Sourceware Bugzilla – Bug 14415
AI_V4MAPPED is useless with AI_UNSPEC but they're used together as defaults when hints=NULL
Last modified: 2013-10-20 20:54:40 UTC
From 'man getaddrinfo':
Specifying hints as NULL is equivalent to setting ai_socktype and
ai_protocol to 0; ai_family to AF_UNSPEC; and ai_flags to
(AI_V4MAPPED | AI_ADDRCONFIG).
If hint.ai_flags specifies the AI_V4MAPPED flag, and hints.ai_family
was specified as AF_INET6, and no matching IPv6 addresses could be
found, then return IPv4-mapped IPv6 addresses in the list pointed to
by res. If both AI_V4MAPPED and AI_ALL are specified in hints.ai_flags,
then return both IPv6 and IPv4-mapped IPv6 addresses in the list pointed
to by res. AI_ALL is ignored if AI_V4MAPPED is not also specified.
As I read it, AI_V4MAPPED is useless without AF_INET6. So either it is wrong,
or I miss something about AI_V4MAPPED that should be documented in the manpage.
My understanding is that because the default uses AF_UNSPEC that the caller accepts *any* address family thus AI_V4MAPPED is not useless because AF_UNSPEC can be treated as anything including AF_INET6.
Does that clarify why we would set AI_V4MAPPED in the default?
Please note that the man pages are maintained by man-pages project here:
Would a clarification on the man page about the uses of AF_UNSPEC help?
> My understanding is that because the default uses AF_UNSPEC that the caller
> accepts *any* address family thus AI_V4MAPPED is not useless because AF_UNSPEC
> can be treated as anything including AF_INET6.
This is not the case. My tests say that AF_UNSPEC with AI_V4MAPPED returns
regular IPv4 addresses, regular IPv6 addresses but *no* IPv4-mapped IPv6
addresses. So it actually behaves exactly like AF_UNSPEC without AI_V4MAPPED.
> Does that clarify why we would set AI_V4MAPPED in the default?
Created attachment 6649 [details]
patch to remove useless AI_V4MAPPED from default with AF_UNSPEC
Created attachment 6794 [details]
getaddrinfo: use zero ai_flags by default
According to POSIX1-2008, AI_V4MAPPED flag shall be ignored unless ai_family
equals AF_INET6. In the default hints, ai_family is AF_UNSPEC. Therefore
AI_V4MAPPED is redundant.
AI_ADDRCONFIG can potentially be beneficial to applications that use
getaddrinfo() results to immediately call connect(), sendto() and
similar functions to avoid querying redundant DNS records according
to the current address configuration.
Those applications will also need to specify ai_socktype and/or
ai_protocol and therefore will not use hints=NULL. As AI_DEFAULT is not
a part of the public API, such applications will not be able to use the
default flags at all.
Please note that POSIX1-2008 doesn't define any default flags at all.
Resolves: #14415, #14965
Could you send these patches to libc-alpha? In second one wouldn't be defining AI_DEFAULT as 0 more reasonable?