summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-06-20 17:21:42 (GMT)
committerGuido van Rossum <guido@python.org>1995-06-20 17:21:42 (GMT)
commit303c179b922dffe16c8d50c820e9f210dc36eb47 (patch)
tree09c0b2f00e3fa5d4869d2d0a1917bc12338dfde6
parent8d2033f08b99fc4c46c0eb0b5de5cf8d2a8c7965 (diff)
downloadcpython-303c179b922dffe16c8d50c820e9f210dc36eb47.zip
cpython-303c179b922dffe16c8d50c820e9f210dc36eb47.tar.gz
cpython-303c179b922dffe16c8d50c820e9f210dc36eb47.tar.bz2
add bind(0,''); better way of guessing our fully qualified hostname
-rw-r--r--Lib/ftplib.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index a78f06b..f27ab06 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -211,6 +211,7 @@ class FTP:
def makeport(self):
global nextport
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.bind(('', 0))
sock.listen(1)
host, port = sock.getsockname()
resp = self.sendport(port)
@@ -234,7 +235,13 @@ class FTP:
# Make sure it is fully qualified
if not '.' in thishost:
thisaddr = socket.gethostbyname(thishost)
- thishost = socket.gethostbyaddr(thisaddr)[0]
+ firstname, names, unused = \
+ socket.gethostbyaddr(thisaddr)
+ names.insert(0, firstname)
+ for name in names:
+ if '.' in name:
+ thishost = name
+ break
try:
if os.environ.has_key('LOGNAME'):
realuser = os.environ['LOGNAME']