• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

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?
0
Mydeen Yussouf
Asked:
Mydeen Yussouf
  • 2
  • 2
  • 2
  • +3
2 Solutions
 
Sikhumbuzo NtsadaCommented:
here is the command you can use:
c:\ipconfig
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
nslookup IMHO
0
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Mydeen YussoufTechnology 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
 
sarabandeCommented:
0
 
Infinity08Commented:
>> 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now