• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:46
CET 03:46
KST 11:46
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Weekly Cups (March 16-22): herO doubles, Cure surprises0Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool42Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12
StarCraft 2
General
What mix of new & old maps do you want in the next ladder pool? (SC2) Weekly Cups (March 16-22): herO doubles, Cure surprises Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Potential Updates Coming to the SC2 CN Server Weekly Cups (March 2-8): ByuN overcomes PvT block
Tourneys
World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
ASL21 General Discussion Soulkey's decision to leave C9 BGH Auto Balance -> http://bghmmr.eu/ JaeDong's form before ASL [ASL21] Ro24 Preview Pt1: New Chaos
Tourneys
ASL Season 21 LIVESTREAM with English Commentary [Megathread] Daily Proleagues [ASL21] Ro24 Group A [BSL22] Open Qualifiers & Ladder Tours
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
U4GM Tips Counter Enemy Gadgets Fast in Black Ops rsvsr How to Keep Reward Chains Rolling in Monopol u4gm What to Do First in MLB The Show 26 Spring
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2801 users

Socket programming

Blogs > IMlemon
Post a Reply
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
October 30 2009 18:15 GMT
#1
Hey TL.

So I have to write a chess server/client program for my university. I've already done the chess part, meaning the moves, check(mate)s, castling, etc etc. Now I need to do the rest, so I need to learn about sockets and stuff. Program has to be written in C and must compile on linux systems using gcc. I'm on windows, and I'm following Beej's guide to Network programming guide, because it's recommended by the guys @ uni. Okay, the guide's cool and awesome and stuff. Until I get cygwin and try to compile the first example and everything crashes and burns and I almost jump out of window (it doesn't compile).

+ Show Spoiler +

/*
** showip.c -- show IP addresses for a host given on the command line
*/

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
struct addrinfo hints, *res, *p;
int status;
char ipstr[INET6_ADDRSTRLEN];

if (argc != 2) {
fprintf(stderr,"usage: showip hostname\n");
return 1;
}

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;

if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
return 2;
}

printf("IP addresses for %s:\n\n", argv[1]);

for(p = res;p != NULL; p = p->ai_next) {
void *addr;
char *ipver;

// get the pointer to the address itself,
// different fields in IPv4 and IPv6:
if (p->ai_family == AF_INET) { // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
ipver = "IPv4";
} else { // IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);
ipver = "IPv6";
}

// convert the IP to a string and print it:
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}

freeaddrinfo(res); // free the linked list

return 0;
}


So uhh, I'm fucked unless you guys save me. I have grand two days left until the deadline, and I have NO clue what to do. Am I a dumbass and I just cannot compile properly (please says yes)? I just launch cygwin and "gcc showip.c -o showip" and it vomits a bunch of errors about incompatible pointer types.

What do I dooooo? Should I use a different guide? I've done some googling but all I found were quite techical and way over my knowledge level (pretty much useless). Right now I'm litteraly praying that I overlooked something incredibly obvious and I'm hoping someone can point it out. If not, maybe you guys can point me in the right direction or something, as otherwise I'm reall really screwed.



My future's so bright, I gotta wear shades.
MasterReY
Profile Blog Joined August 2007
Germany2708 Posts
October 30 2009 18:19 GMT
#2
a have no idea about this, but it looks like not so much text, so just try to start from beginning again without checking ur existing code.

Sometimes you dont make the same mistake then and it works.
https://www.twitch.tv/MasterReY/ ~ Biggest Reach fan on TL.net (Don't even dare to mention LR now) ~ R.I.P Violet ~ Developer of SCRChart
TL+ Member
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
October 30 2009 18:20 GMT
#3
This isn't my code. It's the first example program of the guide.
My future's so bright, I gotta wear shades.
butter
Profile Blog Joined July 2009
United States785 Posts
October 30 2009 18:39 GMT
#4
If you can't read C compiler errors you're pretty much screwed anyway.
TL should have a minigame where you have to destroy some rocks before you can make a new post – DentalFloss
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
Last Edited: 2009-10-30 18:52:29
October 30 2009 18:49 GMT
#5
Gee, thanks for such an incredibly useful answer. I know nothing about socket programming. And when the very first example does not compile for me, I won't even pretend I know why and how should I go about fixing it.

Anyways, an "update" of sorts. it does compile just fine on linux. Seems like cygwin is playing tricks on me or something...
My future's so bright, I gotta wear shades.
AcrossFiveJulys
Profile Blog Joined September 2005
United States3612 Posts
October 30 2009 18:53 GMT
#6
When you install cygwin, it asks you what libraries you want. You probably didn't get the correct socket libraries. Either that or you had a weird gcc.

Anyway, good luck writing your program. C sockets are a pain in ass.
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
October 30 2009 18:56 GMT
#7
You have to get socket libraries seperately? Man, that sounds dumb! On the other hand, I'm really hoping that you're right as this seems just like a dumbass overlook on my part.

/pray.
My future's so bright, I gotta wear shades.
haduken
Profile Blog Joined April 2003
Australia8267 Posts
Last Edited: 2009-10-30 19:07:28
October 30 2009 19:02 GMT
#8
are you using POSIX socket libaries? if I remember correctly that is strictly unix stuff aka you can't do the same in Windows (unless you fetch the POSIX equivalent for Windows).


1.2. Platform and Compiler

The code contained within this document was compiled on a Linux PC using Gnu's gcc compiler. It should, however, build on just about any platform that uses gcc. Naturally, this doesn't apply if you're programming for Windows—see the section on Windows programming, below.


I doubt the author Beej actually tried to use cgywin as cgywin is only a subset of all POSIX libraries.

OP, you need to check all type errors then see if you can ssh into a unix machine (Most universities provide this) and compile your stuff from there.

Socket programming is very system specific, system calls vary greatly between different operating systems.
Rillanon.au
CTStalker
Profile Blog Joined November 2004
Canada9720 Posts
October 30 2009 19:06 GMT
#9
don't use cygwin as a dev environment man. either use an actual linux machine, or install a linux vm
By the way, my name is Funk. I am not of your world
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
October 30 2009 19:10 GMT
#10
Haduken: I did that and the program compiled just fine, as stated in my post above (or wherever).

CTStalker: I don't have the time for such stuff right now, I really don't. Instead of learning about sockets I'd have to learn about linux virtual machines? Maybe another time .
My future's so bright, I gotta wear shades.
araav
Profile Blog Joined September 2004
Armenia1590 Posts
October 30 2009 19:13 GMT
#11
and the error is...???
The flower that blooms in adversity is the most rare and beautiful of all.
CTStalker
Profile Blog Joined November 2004
Canada9720 Posts
October 30 2009 19:13 GMT
#12
do you have access to a linux machine? maybe one at school?
then you can use putty or something else to ssh to it
By the way, my name is Funk. I am not of your world
Too_MuchZerg
Profile Blog Joined February 2008
Finland2818 Posts
October 30 2009 19:18 GMT
#13
can you compile this example @ school computer? I have done this thing via virtual machine, especially compiling is much easier when using Unix based system.




IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
Last Edited: 2009-10-30 19:19:23
October 30 2009 19:18 GMT
#14
CTStalker: I'm doing that right now - so I'm not screwed after all. It's somewhat annoying, but whatever. I'll try to solve those cygwin library/whatever problems later on if I feel like.

So yer, just to make clear - there was nothing wrong with the program, but instead it was a problem on my end with cygwin. Right now I'm compiling my stuff on uni's computers via putty, and it works just fine.

TL is awesome.

My future's so bright, I gotta wear shades.
haduken
Profile Blog Joined April 2003
Australia8267 Posts
October 30 2009 19:19 GMT
#15
On October 31 2009 04:10 IMlemon wrote:
Haduken: I did that and the program compiled just fine, as stated in my post above (or wherever).

CTStalker: I don't have the time for such stuff right now, I really don't. Instead of learning about sockets I'd have to learn about linux virtual machines? Maybe another time .


Oops, Sorry I didn't read your posts.

OP don't blame yourself too hard, C/C++ compiler is a pain in the ass because every vendor/compiler implement their own version. It is one of the great weakness of this language.

I recommend you to stick with a particular framework such as Qt, avoid using low level system calls unless this is exactly what you want to do. Use wrappers when ever you can.
Rillanon.au
IMlemon
Profile Blog Joined May 2008
Lithuania296 Posts
October 30 2009 19:53 GMT
#16
Just if anyone has the same problem with cygwin, here's what you need to do. Go to http://win6.jp/Cygwin/, download the newest package and extract to your cygwin folder.

Again, thanks for the help TL.
My future's so bright, I gotta wear shades.
Please log in or register to reply.
Live Events Refresh
Next event in 7h 14m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft460
PiGStarcraft298
RuFF_SC2 203
Nina 145
StarCraft: Brood War
GuemChi 6419
Stork 91
ggaemo 84
Noble 28
NaDa 28
Dota 2
monkeys_forever899
febbydoto19
LuMiX1
League of Legends
JimRising 636
Counter-Strike
taco 662
minikerr16
Super Smash Bros
hungrybox604
C9.Mang0342
Other Games
summit1g9792
Day[9].tv393
Maynarde134
Trikslyr63
UpATreeSC31
JuggernautJason8
deth6
Organizations
Other Games
gamesdonequick1034
Dota 2
PGL Dota 2 - Main Stream65
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 183
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 112
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo222
Other Games
• Scarra1117
• Day9tv393
Upcoming Events
Sparkling Tuna Cup
7h 14m
Afreeca Starleague
7h 14m
Soulkey vs Ample
JyJ vs sSak
Replay Cast
1d 6h
Afreeca Starleague
1d 7h
hero vs YSC
Larva vs Shine
Kung Fu Cup
1d 8h
Replay Cast
1d 21h
KCM Race Survival
2 days
The PondCast
2 days
WardiTV Team League
2 days
Replay Cast
2 days
[ Show More ]
WardiTV Team League
3 days
RSL Revival
4 days
Cure vs Zoun
herO vs Rogue
WardiTV Team League
4 days
Platinum Heroes Events
4 days
BSL
4 days
RSL Revival
5 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
5 days
BSL
5 days
Replay Cast
6 days
Afreeca Starleague
6 days
Light vs Calm
Royal vs Mind
Wardi Open
6 days
Monday Night Weeklies
6 days
Liquipedia Results

Completed

Proleague 2026-03-23
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.