linux tcp/ip: How to reverse resolve a hostname from an ip address?

T

Tim Veldhuizen

Hi all!

I'm attempting at writing a networked program. It is going to be a threaded
irc server in c++ using almost nothing but oop code.
And it needs to know the full hostname of the users that connect to it. I
already get some info from this code:

workersock = accept(mastersock, &sockaddr, &addrlen);
printf("Received a Client Connection from: %s port: %d fd: %d\n",
inet_ntoa(sockaddr.sin_addr), ntohs(sockaddr.sin_port), workersock);

But it also needs to get the hostname resolved.. Something like 127.0.0.1
would resolve to localhost.localdomain but for every possible ip (if there
is a dns that knows the hostname ofcourse)
I don't mind if the command or routine would take some time, becouse it is
going to work from within a thread either way.. (It would have to be thread
safe too then i guess)
I've searched google for it and looked through some groups, but can't seem
to find it.

Any help is more than welcome. Tnx in advance..

Tim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top