socket.getaddrinfo: flags |= AI_ADDRCONFIG

Discussion in 'Python' started by Karl Chen, Nov 5, 2008.

  1. Karl Chen

    Karl Chen Guest

    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
     
    Karl Chen, Nov 5, 2008
    #1
    1. Advertising

  2. > 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
     
    Martin v. Löwis, Nov 5, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernhard Schmidt

    result sorting in socket.getaddrinfo?

    Bernhard Schmidt, Oct 9, 2004, in forum: Python
    Replies:
    0
    Views:
    396
    Bernhard Schmidt
    Oct 9, 2004
  2. Replies:
    1
    Views:
    386
    Gabriel Genellina
    Dec 23, 2006
  3. Thomas Dybdahl Ahle

    Kill thread or at least socket.getaddrinfo

    Thomas Dybdahl Ahle, Mar 26, 2007, in forum: Python
    Replies:
    3
    Views:
    1,545
    Chris Mellon
    Apr 10, 2007
  4. John Nagle
    Replies:
    2
    Views:
    461
    John Nagle
    Apr 21, 2007
  5. Steve Holden
    Replies:
    0
    Views:
    826
    Steve Holden
    Feb 8, 2009
Loading...

Share This Page