]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
add bind(0,''); better way of guessing our fully qualified hostname
authorGuido van Rossum <guido@python.org>
Tue, 20 Jun 1995 17:21:42 +0000 (17:21 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 20 Jun 1995 17:21:42 +0000 (17:21 +0000)
Lib/ftplib.py

index a78f06b05df34e3911a9a6487b6303d81d8e6890..f27ab06ac5dd2998990f93134b19bf826de470e6 100644 (file)
@@ -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']