From da966efaa7b94f58e2a428b32731045b12797105 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 6 Apr 2008 21:33:40 +0000 Subject: [PATCH] use getaddrinfo to know if we should use ipv4 or v6 for zeroconf --- src/common/zeroconf/client_zeroconf.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/zeroconf/client_zeroconf.py b/src/common/zeroconf/client_zeroconf.py index 0e67bd14d..c60834525 100644 --- a/src/common/zeroconf/client_zeroconf.py +++ b/src/common/zeroconf/client_zeroconf.py @@ -59,16 +59,15 @@ class ZeroconfListener(IdleObject): self.conn_holder = conn_holder def bind(self): - try: - self._serv = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) - except socket.error: - self._serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + ai = socket.getaddrinfo(None, self.port, socket.AF_UNSPEC, + socket.SOCK_STREAM, 0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG)[0] + self._serv = socket.socket(ai[0], ai[1]) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self._serv.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # will fail when port is busy, or we don't have rights to bind try: - self._serv.bind(('', self.port)) + self._serv.bind((ai[4][0], self.port)) except Exception, e: # unable to bind, show error dialog return None