[sr-dev] gethostbyname() usage in resolving hostname

marius zbihlei marius.zbihlei at 1and1.ro
Wed Nov 25 13:04:07 CET 2009


I have seen that sip-router (and also kamailio) uses the old 
gethostbyname()/gethostbyname2() (for IPv6) method of resolving hostnames.

These calls have been deprecated according to the POSIX 2001 standard 
these calls are obsolete: Quote from the gethostbyname manpage

"POSIX.1-2001 marks *gethostbyaddr*() and *gethostbyname*() obsolescent. 
See *getaddrinfo <http://linux.die.net/man/3/getaddrinfo>*(3), 
*getnameinfo <http://linux.die.net/man/3/getnameinfo>*(3), *gai_strerror 
<http://linux.die.net/man/3/gai_strerror>*(3). "

How about changing these calls to the new and improved API(getaddrinfo)?

Some benefits of using the getaddrinfo API:

1. Thread safe calls (also async-sig-safe)
2. IPv4/IPv6 compliant
3. Order or returned addresses conforming to RFC 3484 (private network 
address returned first) (http://udrepper.livejournal.com/16116.html)

For a more complete description of the differences , I point to Urlich 
Drepper's excelent article:


Any benefits from using these calls? Any problems from removing the old 


More information about the sr-dev mailing list