How can I translate IP to hostname in C

Bernd Walter ticso at cicely7.cicely.de
Thu May 22 18:47:50 UTC 2008


On Thu, May 22, 2008 at 04:14:46PM +0000, Bjoern A. Zeeb wrote:
> On Thu, 22 May 2008, John Timony wrote:
> 
> Hi,
> 
> >I am writing a c program in FreeBSD,and I can not
> >translate a ip to hostname
> >,i wonder if there is a function to take this job...
> 
> You mean like gethostbyaddr()?
> 
> See also http://www.unixguide.net/network/socketfaq/2.24.shtml for
> further inspiration on this but slightly different topic.

You can also use the newer getaddrinfo(3)/freeaddrinfo(3).
I think it is bit easier to use and can it transparently handle inet6
addresses as well.
The only downside is that some rare old systems don't support it.
On FreeBSD it is suppoorted since FreeBSD-4, but some commerical
OS implemented it later.

-- 
B.Walter <bernd at bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


More information about the freebsd-hackers mailing list