Resolving IP Addresses

Started by
4 comments, last by zackriggle 20 years, 12 months ago
How can you resolve an IP address with WinSock? gethostbyname doesn''t seem to work...
Advertisement
inet_addr()
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Can I pass something like "www.yahoo.com" to inet_addr()??
No, inet_addr() will only translate a dotted ip address. If the string you pass it isn't a valid ip address then it will return INADDR_NONE. You should check for this value, and then use gethostbyname or (if you're using asyncronous sockets anyway) WSAAsyncGetHostByName to resolve the name using DNS.

Information about all the functions can be found in the winsock documentation or on msdn (msdn.microsoft.com).

Winsock API documentation is here.
WSAAsyncGetHostByName is here.
inet_addr is here.

EDIT:
For general winsock information, I suggest you look at the winsock FAQ.

Hope that helps,

John B

[edited by - JohnBSmall on April 19, 2003 11:37:36 AM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
I know the gethostbyname SHOULD work, but it does not seem to. The ones I am trying to get it to work for is:

xtac.kicks-ass.net
or
xtac.serveftp.net
or
mqonline.homeftp.net

They all point to the same IP address. Ping them, and it works just fine, but I cannot do much else. I do not want to use WSAAsync* functions right now, because I am just doing stuff with the console.
What''s your point? They do all point to the same IP.

This topic is closed to new replies.

Advertisement