ol muser
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?
nslookup IMHO
http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyaddr.html
gethostbyaddr, gethostbyname - network host database functions
These functions shall retrieve information about hosts.
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
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)
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.
@olmuser - please ignore my remark.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
c:\ipconfig