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

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Nov 26 18:22:28 CET 2009

On Nov 25, 2009 at 14:04, marius zbihlei <marius.zbihlei at 1and1.ro> wrote:
> Hello,
> I have seen that sip-router (and also kamailio) uses the old 
> gethostbyname()/gethostbyname2() (for IPv6) method of resolving hostnames.

In general sr uses its own dns cache. gethostbyname() is used only if
compiled without dns cache support and from some modules.

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

They might be deprecated, but they are still the most portable way of doing
dns lookups.
> "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). "
> (http://linux.die.net/man/3/gethostbyname)
> 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)

We don't care about that (we don't have threads and we don't use them
from signal handlers).

> 2. IPv4/IPv6 compliant

same goes for gethostbyname2 or getipnodebyname (solaris).

> 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:
> http://people.redhat.com/drepper/userapi-ipv6.html
> Any benefits from using these calls? Any problems from removing the old 
> calls?

I don't see any benefits in changing, only possible portability


More information about the sr-dev mailing list