• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:38
CET 02:38
KST 10:38
  • 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
HomeStory Cup 28 - Info & Preview12Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational14SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8
Community News
Weekly Cups (Jan 26-Feb 1): herO, Clem, ByuN, Classic win2RSL Season 4 announced for March-April7Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win3Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8
StarCraft 2
General
Stellar Fest "01" Jersey Charity Auction StarCraft 2 Not at the Esports World Cup 2026 Weekly Cups (Jan 26-Feb 1): herO, Clem, ByuN, Classic win HomeStory Cup 28 - Info & Preview Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win
Tourneys
HomeStory Cup 28 RSL Season 4 announced for March-April PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) StarCraft Evolution League (SC Evo Biweekly) $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)
Strategy
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 511 Temple of Rebirth The PondCast: SC2 News & Results Mutation # 510 Safety Violation Mutation # 509 Doomsday Report
Brood War
General
[ASL21] Potential Map Candidates Can someone share very abbreviated BW cliffnotes? BW General Discussion Liquipedia.net NEEDS editors for Brood War BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues Azhi's Colosseum - Season 2 Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Path of Exile Mobile Legends: Bang Bang Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Join illminati in Luanda Angola+27 60 696 7068
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
Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread The Games Industry And ATVI Canadian Politics Mega-thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Play, Watch, Drink: Esports …
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2056 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
Replay Cast
00:00
Rongyi Cup S3 - Playoffs Day 2
CranKy Ducklings142
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 142
Nathanias 123
UpATreeSC 91
StarCraft: Brood War
Artosis 784
Shuttle 74
Hyuk 39
Dota 2
monkeys_forever156
NeuroSwarm104
LuMiX1
League of Legends
C9.Mang0366
JimRising 270
Counter-Strike
fl0m1092
taco 580
shahzam456
Foxcn262
Super Smash Bros
hungrybox1267
AZ_Axe124
Heroes of the Storm
Khaldor130
Other Games
summit1g8258
tarik_tv3298
Day[9].tv842
ViBE159
Maynarde107
Organizations
Other Games
gamesdonequick1129
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• davetesta17
• intothetv
• sooper7s
• Migwel
• LaughNgamezSOOP
• AfreecaTV YouTube
• IndyKCrew
• Kozan
StarCraft: Brood War
• RayReign 28
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21659
League of Legends
• Doublelift4502
• Scarra1192
Other Games
• imaqtpie1572
• Day9tv842
• WagamamaTV269
• Shiphtur242
Upcoming Events
The PondCast
8h 22m
WardiTV Invitational
10h 22m
Replay Cast
22h 22m
RongYI Cup
2 days
herO vs Maru
uThermal 2v2 Circuit
3 days
Replay Cast
4 days
Wardi Open
4 days
Monday Night Weeklies
4 days
Sparkling Tuna Cup
5 days
Liquipedia Results

Completed

Proleague 2026-02-04
HSC XXVIII
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
Nations Cup 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W7
Escore Tournament S1: W8
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
LiuLi Cup: 2025 Grand Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
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.