getaddrinfo performance problems

Rich Felker dalias at
Mon Apr 16 17:32:28 UTC 2012

On Mon, Apr 16, 2012 at 05:57:47PM +0100, Ed W wrote:
> Rich, disregarding posix for a moment, what does glibc do?  Options
> are: canonname=NULL  or IP as string?

If the AI_CANONNAME flag is not specified, the value of the
ai_canonname field in the returned structure is unspecified; in this
case it should not be filled in at all unless there's no cost to
filling it (IIRC musl always fills it because filling it is free if
done right).

> At present uclibc is returning the reverse dns lookup or textual IP
> format.  It should be trivial for me to supply a patch to make this
> whatever we want - can someone define what we want? (Posix or
> emulate some other wierdness?)


    If nodename is not null, and if requested by the AI_CANONNAME
    flag, the ai_canonname field of the first returned addrinfo
    structure shall point to a null-terminated string containing the
    canonical name corresponding to the input nodename; if the
    canonical name is not available, then ai_canonname shall refer to
    the nodename argument or a string with the same contents. The
    contents of the ai_flags field of the returned structures are

My reading is that in the numeric case, since there is no canonical
name, the text about storing a pointer to the input nodename, or a
duplicate of the same, applies.

> Just to be clear - my understanding is (for posix)
> if ( inet_pton(addr) )
>     canonname = NULL;
> else
>     canonname = reverse_dns;

No, reverse dns is ALWAYS wrong. See:

    Since different implementations use different conceptual models,
    the terms ``canonical name'' and ``alias'' cannot be precisely
    defined for the general case. However, Domain Name System
    implementations are expected to interpret them as they are used in
    RFC 1034.

The use in RFC 1034 is the name to which a CNAME reference points.
That is, if the queried name is a CNAME record, ai_canonname is
supposed to store the name that the CNAME points to. If the queried
name is itself an A or AAAA record (no indirection), the ai_canonname
should simply be (possibly a copy of) nodename.

In summary, getaddrinfo is specified never to perform reverse dns. The
getnameinfo function is what's needed for reverse dns.


More information about the uClibc mailing list