By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

socket.getaddrinfo: flags |= AI_ADDRCONFIG

P: n/a

I've discovered that since glibc 2.3.2, getaddrinfo(3) supports a
useful flag called AI_ADDRCONFIG. It turns off AAAA lookups if
the machine isn't configured for IPv6 (and similarly for IPv4,
theoretically). This is especially important when behind gateways
whose DNS forwarder silently filter AAAA requests. Without
AI_ADDRCONFIG, every DNS request has to wait for 4 AAAA request
timeouts before it even attempts an A request.

Passing hints=NULL to getaddrinfo (the C function) means
hints->flags = AI_V4MAPPED | AI_ADDRCONFIG. I.e., not the same as
hints->hints->flags = 0. (Don't ask me why the default isn't 0, I
don't like this API either. It means if you wish to specify only
some hint parameters you have to carefully get the flags right.)

Python's socketmodule.c, especially socket_getaddrinfo, uses 0 as
the default flags. So AI_ADDRCONFIG is turned off by default.

I propose:
1) mimic glibc default behavior, i.e. if flags is unspecified or
None, treat it as the default value of AI_V4MAPPED |
AI_ADDRCONFIG).

Alternatively:
2) add these flags to callers of socket.getaddrinfo in various
standard libs, e.g. httplib.
(AI_V4MAPPED isn't as important since it only applies if you
explicitly choose AF_INET6, a conscious decision.)

Karl
Nov 5 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
1) mimic glibc default behavior, i.e. if flags is unspecified or
None, treat it as the default value of AI_V4MAPPED |
AI_ADDRCONFIG).
Unfortunately, that contradicts with RFC 3493, which says

# If hints is a null pointer, the behavior
# shall be as if it referred to a structure containing the value zero
# for the ai_flags, ai_socktype and ai_protocol fields, and AF_UNSPEC
# for the ai_family field.

Of course, we might chose to ignore that.
Alternatively:
2) add these flags to callers of socket.getaddrinfo in various
standard libs, e.g. httplib.
There is apparently a problem with this one, also: implementations
might define AI_ADDRCONFIG, but not implement it, but instead return
EAI_BADFLAGS. Not sure whether this is a real problem, though.

Regards,
Martin
Nov 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.