Jump to content
  • Advertisement
Sign in to follow this  
badmoon

Winsock: gethostbyname

This topic is 5394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I've recently decided to train me up in networking programming. Prior to this, I've never had any experience on it. I've been trying out some example tutorials from the net. One of them goes like the following:
WSAStartup(MAKEWORD(1,1), &wsaData);
LPHOSTENT lpHostEntry = gethostbyname("www.idgbooks.com");

Unfortunately lpHostEntry comes out NULL after the second line. Does anyone know why? What I ultimately would like to do is open up a socket to a web server and request pages from it via the http protocol.

Share this post


Link to post
Share on other sites
Advertisement
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.

Check out MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/ntwrkprot.asp

Check out my website for software development links.

http://www.dslextreme.com/users/kuphryn/links.html

Kuphryn

Share this post


Link to post
Share on other sites
Try using "getaddrinfo" function, while gethostbyname was deprecated. It takes also IP address as parameter, so it helps a bit when confused, returns meaningful values and quite nice addrinfo struct.

Description of this function can be found on MSDN of course.

m.

Share this post


Link to post
Share on other sites
I dont know moutch about network programming, but I belive you have to type the full address. http://www.idgbooks.com to find the hoste.

I can't connect to www.idgbooks.com, AFAIK if you use a site that don't exists the call whill return NULL

Share this post


Link to post
Share on other sites
www.idgbooks.com without protocol (http://) SHOULD be resolved, while you don't need to know it to resolve domain name to IP address. The other thing, of course, is, if the address has DNS record somewhere or not... i did not checked it, but as you say, if that is the issue, i hope gethostbyname() will always return NULL and WSAGetLastError() will return something meaningful...

m.

Share this post


Link to post
Share on other sites
I get redirected to another web site, which is a tell-tale sign.

gethostbyname() does a DNS lookup and will return both an MX and an A-type record if the host is found AND is reacheable. The function call will return a NULL and error code WSANO_DATA indicating the IP exist but cannot be reached directly.

-cb

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!