From f2956c257b7f0066f43946e30f246e642e75fd6b Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Wed, 7 Mar 2007 18:21:42 -0700
Subject: [PATCH] util.iputil: try to survive not having a global network
 connection at all

---
 src/allmydata/util/iputil.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/util/iputil.py b/src/allmydata/util/iputil.py
index 9b87b1c0..bfa5b5f9 100644
--- a/src/allmydata/util/iputil.py
+++ b/src/allmydata/util/iputil.py
@@ -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)
-- 
2.45.2