Ticket #5820 (new defect)
standalone trac does not accept -b "::"
| Reported by: | sgala@… | Owned by: | jonas |
|---|---|---|---|
| Priority: | low | Milestone: | 1.0 |
| Component: | web frontend/tracd | Version: | 0.11 |
| Severity: | normal | Keywords: | ipv6 |
| Cc: |
Description
(error is: socket.gaierror: (-9, "Address family for hostname not supported")
The way sockets are initialized is wrong. trac (or the underlying wsgi code for python 2.4) is assuming socket.AF_INET before even knowing the server address.
Standard code for initializing a ipv6 aware socket, that will work in ipv4-only machines (see U. Drepper tutorial) is:
>>> import socket
>>> gais = socket.getaddrinfo("::",8000, socket.AF_UNSPEC, socket.SOCK_STREAM) # host, port, af, tcp, ...
>>> for gai in gais:
... try:
... sock = socket.socket(*gai[:2])
... sock.bind(gai[4])
... break
... except:
... continue
... else:
... sock = None
... raise "Error, couldn't bind"
or something similar. This code should work on any python having getaddrinfo, which means anything modern enough. In fact this code will try to bind in any different possibilities given.
None means localhost in the most general way (127.0.0.1 or ::1); "::" or "0.0.0.0" means any ipv6/ipv4 or any ipv4 address. For concrete addresses, getaddrinfo will parse and take care of the socket parameters.


