# HG changeset patch # User Alexander Solovyov # Date 1240857219 -10800 # Node ID 63ea850b331267aa9a5e33c734d58a5446ea79fd # Parent 41031699550a05405e8447a25966741002fac6ca zeroconf: guess ip for Zeroconf Zeroconf() is actually pretty dumb in guessing IPs and in case of socket.gaierror will not guess right IP. diff -r 41031699550a -r 63ea850b3312 hgext/zeroconf/__init__.py --- a/hgext/zeroconf/__init__.py Wed Apr 29 20:47:30 2009 -0500 +++ b/hgext/zeroconf/__init__.py Mon Apr 27 21:33:39 2009 +0300 @@ -51,9 +51,12 @@ pass # Generic method, sometimes gives useless results - dumbip = socket.gethostbyaddr(socket.gethostname())[2][0] - if not dumbip.startswith('127.') and ':' not in dumbip: - return dumbip + try: + dumbip = socket.gethostbyaddr(socket.gethostname())[2][0] + if not dumbip.startswith('127.') and ':' not in dumbip: + return dumbip + except socket.gaierror: + dumbip = '127.0.0.1' # works elsewhere, but actually sends a packet try: @@ -69,13 +72,12 @@ def publish(name, desc, path, port): global server, localip if not server: - try: - server = Zeroconf.Zeroconf() - except socket.gaierror: + ip = getip() + if ip.startswith('127.'): # if we have no internet connection, this can happen. return - ip = getip() localip = socket.inet_aton(ip) + server = Zeroconf.Zeroconf(ip) hostname = socket.gethostname().split('.')[0] host = hostname + ".local" @@ -129,7 +131,10 @@ self.found[repr(name)] = server.getServiceInfo(type, name) def getzcpaths(): - server = Zeroconf.Zeroconf() + ip = getip() + if ip.startswith('127.'): + return + server = Zeroconf.Zeroconf(ip) l = listener() Zeroconf.ServiceBrowser(server, "_hg._tcp.local.", l) time.sleep(1)