as BobS0327 wrotes on the 1st sample line: you should link with the winsock library. but on devcpp you should link from 'project -> options -> params -> linker', just browse till devcpp dir, go to 'lib' dir and select 'libws2_32' for winsock2. note that devcpp uses *.a libraries instead *.lib. hope that helps.

bob's code works well for me in devcpp, and your code works well with the right synthax: take a look on the bob's code and see the diferences. see that first of all you should init the winsock through 'WSAStartup'. another thing, have you tryed to printf the 'hostname' char? it's really a host name in it before run the 'gethostbyname'? and finally to get the ip adress take another look to the bob's sample: he doesn't printf directly the 'hostent*' structure. take also a look at the tonto first post: 'hostent' is not a char, so you can't printf as a '%s' value.

I have no luck with using gethostbyname() either. gethostbyname() won't do DNS resolves. For example if I give it "www.google.com" I get returned with NULL, if I were to feed it my own IP or "127.0.0.1" it works (but "localhost" doesn't). To make sure it's not just taking any shortcuts for IP-numbers I tried entering an erroneous IP, "123.123.123.123" and that returned NULL. Compilers used were Borland 5.6.1 and MinGW32 3.4.2 using both the winsock and winsock2 libraries.

So gethostbyname() can't do hostnames? Is there some sort of conspiracy going on here, where only a select few get a working winsock lib?