Opened 17 years ago
Last modified 7 months ago
#5820 new defect
standalone trac does not accept -b "::" — at Initial Version
Reported by: | Owned by: | Jonas Borgström | |
---|---|---|---|
Priority: | low | Milestone: | next-stable-1.6.x |
Component: | web frontend/tracd | Version: | 0.11 |
Severity: | normal | Keywords: | ipv6, patch |
Cc: | Thijs Triemstra | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
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.