• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:12
CET 16:12
KST 00:12
  • 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
TL.net Map Contest #21: Winners11Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
Weekly Cups (Nov 3-9): Clem Conquers in Canada2SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7[BSL21] RO32 Group Stage4
StarCraft 2
General
Mech is the composition that needs teleportation t SC: Evo Complete - Ranked Ladder OPEN ALPHA Weekly Cups (Nov 3-9): Clem Conquers in Canada Craziest Micro Moments Of All Time? RotterdaM "Serral is the GOAT, and it's not close"
Tourneys
Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions Where's CardinalAllin/Jukado the mapmaker?
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group A - Saturday 21:00 CET [BSL21] RO32 Group B - Sunday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Should offensive tower rushing be viable in RTS games? Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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 SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1703 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
WardiTV Korean Royale
12:00
Group Stage 1 - Group B
WardiTV1042
TKL 405
Rex123
IntoTheiNu 38
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 405
RotterdaM 236
Rex 123
SortOf 114
Vindicta 28
StarCraft: Brood War
Calm 4043
Shuttle 1043
Soma 1042
firebathero 803
Hyuk 691
Stork 459
ZerO 384
hero 280
Rush 213
Sharp 105
[ Show more ]
Killer 104
Barracks 104
sSak 101
Sea.KH 68
Backho 40
Aegong 40
Mong 31
ToSsGirL 29
Free 27
Sexy 22
zelot 16
Movie 14
Terrorterran 14
Shine 13
Dota 2
singsing2181
Dendi1031
BananaSlamJamma147
XcaliburYe120
Counter-Strike
olofmeister1771
markeloff116
FunKaTv 4
Other Games
B2W.Neo1101
hiko632
crisheroes350
DeMusliM318
Hui .302
Lowko297
Sick191
Fuzer 155
Liquid`VortiX145
ArmadaUGS135
oskar115
ZerO(Twitch)13
Reynor8
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Adnapsc2 5
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 22
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2257
• WagamamaTV354
League of Legends
• Nemesis3668
• TFBlade757
Upcoming Events
OSC
48m
Replay Cast
7h 48m
Replay Cast
17h 48m
Kung Fu Cup
20h 48m
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
1d 7h
The PondCast
1d 18h
RSL Revival
1d 18h
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
1d 20h
WardiTV Korean Royale
1d 20h
PiGosaur Monday
2 days
[ Show More ]
RSL Revival
2 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
2 days
CranKy Ducklings
3 days
RSL Revival
3 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
3 days
BSL 21
4 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
4 days
RSL Revival
4 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
BSL 21
5 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
Wardi Open
5 days
Monday Night Weeklies
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
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 © 2025 TLnet. All Rights Reserved.