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?
LVL 1
ol muserTechnology GeneralistAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
>> The headerfiles in the code samples, do they have windows equivalent?

The same guide has some notes specifically for Windows development :

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

The guide is a good resource for socket programming btw - so it's a recommended read :)
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
here is the command you can use:
c:\ipconfig
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
nslookup IMHO
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
evilrixSenior Software Engineer (Avast)Commented:
http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyaddr.html

gethostbyaddr, gethostbyname - network host database functions

These functions shall retrieve information about hosts.
0
 
sarabandeCommented:
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
0
 
Infinity08Commented:
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)
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
@evilrix - I'm sorry, missed that.

@olmuser - please ignore my remark.
0
 
ol muserTechnology GeneralistAuthor Commented:
@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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.