From 234951041f5e02586445221abf7d5ce2902fe60b Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Mon, 16 Apr 2007 15:12:01 -0700
Subject: [PATCH] oops -- the previous commit of iputil wasn't the right
 version Too bad synchronizing pyutil and allmydata.util includes a manual
 step.

---
 src/allmydata/util/iputil.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/allmydata/util/iputil.py b/src/allmydata/util/iputil.py
index a0bb274c..0f2cb8c1 100644
--- a/src/allmydata/util/iputil.py
+++ b/src/allmydata/util/iputil.py
@@ -24,12 +24,12 @@ def get_local_addresses_async(target='A.ROOT-SERVERS.NET'):
         pass the address of a host that you are actually trying to be
         reachable to.
     """
-    addresses = []
-    addresses.append(get_local_ip_for(target))
+    addresses = set()
+    addresses.add(get_local_ip_for(target))
 
     d = _find_addresses_via_config()
     def _collect(res):
-        addresses.extend(res)
+        addresses.update(res)
         return addresses
     d.addCallback(_collect)
 
@@ -79,11 +79,11 @@ class UnsupportedPlatformError(Exception):
 # ... thus wrote Greg Smith in time immemorial...
 _win32_path = 'route.exe'
 _win32_args = ('print',)
-_win32_re = re.compile('^\s*0\.0\.0\.0\s.+\s(?P<address>\d+\.\d+\.\d+\.\d+)\s+(?P<metric>\d+)\s*$', flags=re.M|re.I|re.S)
+_win32_re = re.compile('^\s*\d+\.\d+\.\d+\.\d+\s.+\s(?P<address>\d+\.\d+\.\d+\.\d+)\s+(?P<metric>\d+)\s*$', flags=re.M|re.I|re.S)
 
 # These work in Redhat 6.x and Debian 2.2 potato
 _linux_path = '/sbin/ifconfig'
-_linux_re = re.compile('^(?P<name>\w+)\s.+\sinet addr:(?P<address>\d+\.\d+\.\d+\.\d+)\s.+$', flags=re.M|re.I|re.S)
+_linux_re = re.compile('^\s*inet addr:(?P<address>\d+\.\d+\.\d+\.\d+)\s.+$', flags=re.M|re.I|re.S)
 
 # NetBSD 1.4 (submitted by Rhialto), Darwin, Mac OS X
 _netbsd_path = '/sbin/ifconfig -a'
@@ -108,10 +108,10 @@ def _find_addresses_via_config():
             l.append(_query(executable, _win32_re, _win32_args))
         dl = defer.DeferredList(l)
         def _gather_results(res):
-            addresses = []
+            addresses = set()
             for r in res:
                 if r[0]:
-                    addresses.extend(r[1])
+                    addresses.update(r[1])
             return addresses
         dl.addCallback(_gather_results)
         return dl
@@ -127,13 +127,13 @@ def _find_addresses_via_config():
 def _query(path, regex, args=()):
     d = getProcessOutput(path, args)
     def _parse(output):
-        addresses = []
+        addresses = set()
         outputsplit = output.split('\n')
-        for output in outputsplit:
-            m = regex.match(output)
+        for outline in outputsplit:
+            m = regex.match(outline)
             if m:
                 d = m.groupdict()
-                addresses.append(d['address'])
+                addresses.add(d['address'])
     
         return addresses
     d.addCallback(_parse)
-- 
2.45.2