Link to home
Start Free TrialLog in
Avatar of ol muser
ol muserFlag for United States of America

asked on

IP address to host name

I have the IP address of a socket client connected to the TCP server. I need to know the name of the host connected. What is the best way to programatically find it on the server side?
Avatar of Phiwi Moyo
Phiwi Moyo
Flag of Germany image

here is the command you can use:
c:\ipconfig
Avatar of Gerwin Jansen
nslookup IMHO
http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyaddr.html

gethostbyaddr, gethostbyname - network host database functions

These functions shall retrieve information about hosts.
you could try to call gethostbyaddr if supported by your compiler. but the server not necessarily has a a name for a client address.

Sara
Actually, you should probably use the newer getnameinfo (the replacement for gethostbyaddr) :

        http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#getnameinfoman

(at the very least in order to make your code ready for IPv6)
@evilrix - I'm sorry, missed that.

@olmuser - please ignore my remark.
Avatar of ol muser

ASKER

@Infinity08: the code samples and methods by beej network guide sound promising. I am on windows platform. The headerfiles in the code samples, do they have windows equivalent?
SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial