• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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.
  • 2
1 Solution
Use the WINSOCK gethostbyaddr() or the asynchronous version WSAAsyncGetHostByAddr().
philsmicronetAuthor Commented:
If I have a dotted ip address (say how to I use the gethostbyaddr function. MSDN is not very specific on how to do this.
The first parm to gethostbyaddr() is the IP in four bytes, one binary octet per byte:

HOSTENT       *h;
unsigned char  NBO[4];

h=gethostbyaddr((const char *)NBO,14,AF_INET);
philsmicronetAuthor Commented:
Thanks very much. MSDN is not very specific about this stuff
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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now