Retreiving the Hostname from an IP Address

I am writing a log file analyser and I want to resolve the IP address into a Hostname. How do I do this?

I will be using Visual C.
LVL 1
philsmicronetAsked:
Who is Participating?
 
cookreConnect With a Mentor Commented:
The first parm to gethostbyaddr() is the IP in four bytes, one binary octet per byte:

HOSTENT       *h;
unsigned char  NBO[4];

sscanf(IPStr,"%d.%d.%d.%d",&NBO[0],&NBO[1],&NBO[2],&NBO[3]);
h=gethostbyaddr((const char *)NBO,14,AF_INET);
0
 
jhanceCommented:
Use the WINSOCK gethostbyaddr() or the asynchronous version WSAAsyncGetHostByAddr().
0
 
philsmicronetAuthor Commented:
If I have a dotted ip address (say 192.168.40.10) how to I use the gethostbyaddr function. MSDN is not very specific on how to do this.
0
 
philsmicronetAuthor Commented:
Thanks very much. MSDN is not very specific about this stuff
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.