• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:32
CET 18:32
KST 02:32
  • 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
RSL Revival - 2025 Season Finals Preview7RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ [BSL21] RO8 Bracket & Prediction Contest BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Let's talk about Metropolis
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Fighting Spirit mining rates Current Meta
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
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
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1678 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 2h 29m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
IndyStarCraft 88
BRAT_OK 78
MindelVK 52
JuggernautJason51
Railgan 32
StarCraft: Brood War
Britney 24492
Calm 2776
Jaedong 672
Horang2 498
Hyuk 346
EffOrt 205
Mini 200
Last 151
Hyun 95
Zeus 76
[ Show more ]
scan(afreeca) 50
Mong 36
Aegong 34
ggaemo 33
Noble 8
Dota 2
Gorgc6091
singsing3733
qojqva2320
Counter-Strike
fl0m15346
byalli488
chrisJcsgo32
Heroes of the Storm
Khaldor578
Liquid`Hasu416
Other Games
B2W.Neo773
Beastyqt763
ToD159
XaKoH 89
ArmadaUGS74
Mew2King24
OptimusSC21
Organizations
Other Games
WardiTV1512
StarCraft 2
ComeBackTV 994
angryscii 18
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• HeavenSC 23
• Adnapsc2 8
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2615
Other Games
• Shiphtur547
Upcoming Events
IPSL
2h 29m
Sziky vs JDConan
BSL 21
2h 29m
Tech vs Cross
Bonyth vs eOnzErG
Replay Cast
15h 29m
Wardi Open
18h 29m
Monday Night Weeklies
23h 29m
Sparkling Tuna Cup
1d 16h
Replay Cast
3 days
The PondCast
3 days
CranKy Ducklings
5 days
SC Evo League
5 days
[ Show More ]
BSL 21
6 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

CSL 2025 WINTER (S19)
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 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.