Solved

Retreiving the Hostname from an IP Address

Posted on 2002-03-15
4
166 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 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

16 Experts available now in Live!

Get 1:1 Help Now