What Linux's getaddrinfo()
is doing with IPv6 (on some versions)
I've previously noted that Linux's getaddrinfo()
implementation
doesn't return IPv6 addresses by default if it doesn't think that your
system is IPv6 capable, or perhaps if your system has IPv6 disabled
(this is most conveniently visible through the Python interface). This behavior is more or less the same as
what you'd get if you supplied the AI_ADDRCONFIG
flag in the hints
structure.
(To be specific, I have seen this behavior on Ubuntu 8.04. It doesn't seem to be present in Ubuntu 6.06, and unfortunately I don't have any other Linux machines with IPv6 disabled to test on.)
This behavior is half-documented in modern getaddrinfo()
manpages, which
say that if you supply no hints
structure you get flags that include
AI_ADDRCONFIG
. However this is not the full story, since you also
get this behavior if you supply a hints
structure with ai_family
set to 0 (aka AF_UNSPEC
).
I would love to report that I had found the code that does this in
glibc. However, the glibc getaddrinfo()
internals have defeated me;
I cannot see any clear code that has this particular side effect. So
all I can do is report what I have determined experimentally, which is
that supplying a non-zero set of flags in af_flags
doesn't make a
difference, nor does the type of socket you ask for. The only thing
that will get you IPv6 addresses on such a Linux system is putting
AF_INET6
in the ai_family
field, at which point they will
magically appear.
(Note that this behavior is subtly different from turning on the
AI_ADDRCONFIG
flag all the time, as the flag causes IPv6 results to
never get returned, even if you ask for them specifically.)
I assume that this is why 'getents ahostsv6
' (from the comments here) will fail on such a system; I expect it
is making a plain getaddrinfo()
call and filtering the results if you
ask specifically for IPv6 addresses.
(The getents
behavior may be a bug, but the glibc getaddrinfo()
behavior is probably deliberate.)
Comments on this page:
|
|