util.iputil: try to survive not having a global network connection at all
authorBrian Warner <warner@lothar.com>
Thu, 8 Mar 2007 01:21:42 +0000 (18:21 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 8 Mar 2007 01:21:42 +0000 (18:21 -0700)
src/allmydata/util/iputil.py

index 9b87b1c00012e486cd46145a9de774f5811de0d5..bfa5b5f986f30fd9c28fe6a833449c045fa8ecde 100644 (file)
@@ -11,7 +11,10 @@ def get_local_ip_for(target='A.ROOT-SERVERS.NET'):
     Returns a string that holds the IP address which could be used by
     'target' to connect to us. It might work for them, it might not.
     """
-    target_ipaddr = socket.gethostbyname(target)
+    try:
+        target_ipaddr = socket.gethostbyname(target)
+    except socket.gaierror:
+        return "127.0.0.1"
     udpprot = DatagramProtocol()
     port = reactor.listenUDP(0, udpprot)
     udpprot.transport.connect(target_ipaddr, 7)