Solved

Retreiving the Hostname from an IP Address

Posted on 2002-03-15
4
165 Views
Last Modified: 2013-12-03
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
Comment
Question by:philsmicronet
  • 2
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6867759
Use the WINSOCK gethostbyaddr() or the asynchronous version WSAAsyncGetHostByAddr().
0
 
LVL 1

Author Comment

by:philsmicronet
ID: 6867926
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
 
LVL 22

Accepted Solution

by:
cookre earned 100 total points
ID: 6868221
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
 
LVL 1

Author Comment

by:philsmicronet
ID: 6869420
Thanks very much. MSDN is not very specific about this stuff
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now