• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:05
CEST 17:05
KST 00:05
  • 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
Serral wins EWC 202543Tournament Spotlight: FEL Cracow 202510Power Rank - Esports World Cup 202580RSL Season 1 - Final Week9[ASL19] Finals Recap: Standing Tall15
Community News
Weekly Cups (Jul 28-Aug 3): herO doubles up6LiuLi Cup - August 2025 Tournaments3[BSL 2025] H2 - Team Wars, Weeklies & SB Ladder10EWC 2025 - Replay Pack4Google Play ASL (Season 20) Announced58
StarCraft 2
General
Weekly Cups (Jul 28-Aug 3): herO doubles up Clem Interview: "PvT is a bit insane right now" Serral wins EWC 2025 TL Team Map Contest #5: Presented by Monster Energy Would you prefer the game to be balanced around top-tier pro level or average pro level?
Tourneys
Global Tourney for College Students in September Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays $5,000 WardiTV Summer Championship 2025 LiuLi Cup - August 2025 Tournaments
Strategy
Custom Maps
External Content
Mutation # 485 Death from Below Mutation # 484 Magnetic Pull Mutation #239 Bad Weather Mutation # 483 Kill Bot Wars
Brood War
General
BW General Discussion Help, I can't log into staredit.net How do the new Battle.net ranks translate? Which top zerg/toss will fail in qualifiers? Google Play ASL (Season 20) Announced
Tourneys
[CSLPRO] It's CSLAN Season! - Last Chance [Megathread] Daily Proleagues [ASL20] Online Qualifiers Day 2 Cosmonarchy Pro Showmatches
Strategy
Simple Questions, Simple Answers [G] Mineral Boosting Muta micro map competition Does 1 second matter in StarCraft?
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Total Annihilation Server - TAForever Beyond All Reason [MMORPG] Tree of Savior (Successor of Ragnarok)
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
European Politico-economics QA Mega-thread US Politics Mega-thread Things Aren’t Peaceful in Palestine Bitcoin discussion thread 9/11 Anniversary
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment" Computer Build, Upgrade & Buying Resource Thread
TL Community
TeamLiquid Team Shirt On Sale The Automated Ban List
Blogs
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
The Link Between Fitness and…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
Customize Sidebar...

Website Feedback

Closed Threads



Active: 829 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
Stormgate Nexus
14:00
Stormgate Launch Days
BeoMulf221
TKL 194
IndyStarCraft 179
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Reynor 360
SpeCial 81
StarCraft: Brood War
Britney 50665
Bisu 3971
Shuttle 2425
Mini 930
Soulkey 575
ggaemo 463
Snow 365
actioN 350
ZerO 277
Soma 221
[ Show more ]
Hyuk 197
sSak 157
Leta 91
ToSsGirL 76
sorry 74
Nal_rA 57
Sharp 56
Aegong 40
soO 39
[sc1f]eonzerg 33
sas.Sziky 29
zelot 27
scan(afreeca) 20
Rock 17
ajuk12(nOOB) 17
Sacsri 16
Terrorterran 13
Backho 12
IntoTheRainbow 10
SilentControl 9
JulyZerg 8
ivOry 4
Stormgate
BeoMulf221
TKL 194
IndyStarCraft 179
Dota 2
Gorgc5777
Dendi1606
XcaliburYe381
Counter-Strike
pashabiceps504
flusha368
byalli292
kRYSTAL_56
Heroes of the Storm
XaKoH 112
Other Games
gofns1900
hiko891
Beastyqt480
crisheroes383
KnowMe370
Hui .365
RotterdaM261
DeMusliM253
Fuzer 212
ArmadaUGS92
QueenE71
ZerO(Twitch)18
Trikslyr14
Organizations
StarCraft 2
WardiTV1060
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 84
• poizon28 23
• davetesta16
• Kozan
• AfreecaTV YouTube
• intothetv
• sooper7s
• IndyKCrew
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• FirePhoenix10
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV791
League of Legends
• Nemesis2797
• Jankos1054
Upcoming Events
uThermal 2v2 Circuit
55m
DaveTesta Events
8h 55m
The PondCast
18h 55m
WardiTV Summer Champion…
19h 55m
Replay Cast
1d 8h
LiuLi Cup
1d 19h
uThermal 2v2 Circuit
1d 23h
RSL Revival
2 days
RSL Revival
2 days
uThermal 2v2 Circuit
2 days
[ Show More ]
CSO Cup
3 days
Sparkling Tuna Cup
3 days
uThermal 2v2 Circuit
3 days
Wardi Open
4 days
RotterdaM Event
5 days
RSL Revival
6 days
Liquipedia Results

Completed

ASL Season 20: Qualifier #2
FEL Cracow 2025
CC Div. A S7

Ongoing

Copa Latinoamericana 4
Jiahua Invitational
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
HCC Europe
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025

Upcoming

ASL Season 20
CSLPRO Chat StarLAN 3
BSL Season 21
BSL 21 Team A
RSL Revival: Season 2
Maestros of the Game
SEL Season 2 Championship
WardiTV Summer 2025
uThermal 2v2 Main Event
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty 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.