]> granicus.if.org Git - python/commitdiff
Rewrite the `hostname mismatch' test as per GvR suggestion.
authorBarry Warsaw <barry@python.org>
Mon, 13 Jan 1997 19:35:39 +0000 (19:35 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 13 Jan 1997 19:35:39 +0000 (19:35 +0000)
Don't assume gethostbyaddr()'s primary hostname is the same as
gethostname(), or even that gethostname() can be found in the list of
hosts returned by gethostbyaddr().  We do test for at least one FQDN
in gethostbyaddr().

Lib/test/test_socket.py

index 2b3c504984378d78a13458a8a7e5771abc441f7a..f7b62a9bbcd875e20e2a3bfdfc3f25dc4ba0f178 100644 (file)
@@ -12,6 +12,7 @@ from test_support import verbose
 import socket
 import os
 import time
+import string
 
 def missing_ok(str):
     try:
@@ -67,14 +68,19 @@ for optional in ("AF_UNIX",
 hostname = socket.gethostname()
 ip = socket.gethostbyname(hostname)
 hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
+all_host_names = [hname] + aliases
 
 if verbose:
     print hostname
     print ip
     print hname, aliases, ipaddrs
+    print all_host_names
 
-if hostname <> hname:
-    print 'hostname mismatch'
+for name in all_host_names:
+    if string.find(name, '.'):
+       break
+else:
+    print 'FQDN not found'
 
 print socket.getservbyname('telnet', 'tcp')
 try: