• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • 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.
0
philsmicronet
Asked:
philsmicronet
  • 2
1 Solution
 
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
 
cookreCommented:
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
 
philsmicronetAuthor Commented:
Thanks very much. MSDN is not very specific about this stuff
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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