Solved

Retreiving the Hostname from an IP Address

Posted on 2002-03-15
4
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

724 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