Martin Panter added the comment:

I also have reservations about using getaddrinfo() like this. Some potential 
problems:

1. IPv4-only compatibility: On my Linux computer, getaddrinfo("localhost", 0) 
returns AF_INET6 before AF_INET. Some programs, like Firefox and BSD netcat, 
will try both v4 and v6 and probably succeed (netcat first warned about 
“connection refused” for IPv4). However, other programs only support IPv4 at 
all or by default. Socat supports v6 but requires an explicit TCP6 or pf=ip6 
argument. Gnu netcat only seems to support IPv4. This could also have been a 
problem with smtpd, or maybe SMTP clients are supposed to be smarter and it is 
okay (I am not familiar with the protocol).

2. Similarly, maybe getaddrinfo() could return AF_INET first even though the 
user made a subclass with address_family = AF_INET6.

3. It seems a waste to do a DNS lookup just to choose the address_family and 
throw away the resolved addresses, only to then call bind() which will do the 
lookup all over again. If DNS times out, the delay until error reporting will 
be twice as long.

4. getaddrinfo(("", None)) has a short delay (DNS timeout?) for me. The Python 
documentation says the empty string "" is special-cased to mean INADDR_ANY 
(IPv4). It also says there is no special case for the IPv6 equivalent 
(in6addr_any), although it does seem to work in some cases, including bind(). 
But getaddrinfo() would parse the string in the underlying platform, not in 
Python.

Some ideas:

1. Don’t look up hostnames, and only determine IPv6 if a numerical IP address 
is specified. I think this closer to the original proposal. Maybe use 
AI_NUMERICHOST? Or the simplistic test proposed in Issue 24209?

2. For the empty string address "", if the platform supports dual stack, use 
AF_INET6, bind to “::” and clear the IPV6_V6ONLY option. See Issue 3213.

3. Bind sockets to all addresses returned by getaddrinfo(), not just the first. 
But this would be a much bigger and more radical change. Maybe just something 
to dream about. :)

4. Add an address_family parameter to the constructor, so the user can change 
to AF_INET6 without subclassing.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20215>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to