summaryrefslogtreecommitdiffstats
path: root/network.py
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2008-10-14 16:37:16 -1000
committerDavid Cantrell <dcantrell@redhat.com>2008-10-14 16:37:16 -1000
commitb011def228d7af9a72f556637dd803051d9d7c7b (patch)
treeebf68c09a90242f9d1668b85bf42f5bfbb9e2b5a /network.py
parent49d36b72b4e3985bc0f1a9e91812859624899267 (diff)
downloadanaconda-b011def228d7af9a72f556637dd803051d9d7c7b.tar.gz
anaconda-b011def228d7af9a72f556637dd803051d9d7c7b.tar.xz
anaconda-b011def228d7af9a72f556637dd803051d9d7c7b.zip
Handle unknown hosts in getDefaultHostname (#466775)
If a host is unknown, socket.gethostbyaddr() gives us a 2-tuple.
Diffstat (limited to 'network.py')
-rw-r--r--network.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/network.py b/network.py
index d546b747d..adefad896 100644
--- a/network.py
+++ b/network.py
@@ -100,11 +100,16 @@ def getDefaultHostname(anaconda):
try:
tmp = struct.pack('I', addrs[0])
ipaddr = socket.inet_ntop(socket.AF_INET, tmp)
- (hn, aliases, addresses) = socket.gethostbyaddr(ipaddr)
+ hinfo = socket.gethostbyaddr(ipaddr)
+
+ if len(hinfo) == 3:
+ hn = hinfo[0]
+ else:
+ continue
except:
continue
- if not hn and hn != 'localhost' or hn != 'localhost.localdomain':
+ if hn and hn != 'localhost' and hn != 'localhost.localdomain':
return hn
hn = anaconda.id.network.hostname
@@ -112,7 +117,7 @@ def getDefaultHostname(anaconda):
if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain':
hn = socket.gethostname()
- if hn == '(none)' or hn == 'localhost':
+ if not hn or hn == '(none)' or hn == 'localhost':
hn = 'localhost.localdomain'
return hn