This fixes Transport.__init__ to try to connect to each available address
family, rather than assuming that a connection refused from the first one means
no other address families will succeed.

This is similar to the way socket.create_connection in Python 2.6 works.

You can find a bzr branch of this at lp:~spiv/paramiko/address-families-579530.

---
 transport.py |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/paramiko/transport.py b/paramiko/transport.py
index 758ba37..1b5b72d 100644
--- a/paramiko/transport.py 
+++ b/paramiko/transport.py 
@@ -285,15 +285,21 @@
         if type(sock) is tuple:
             # connect to the given (host, port)
             hostname, port = sock
+            reason = 'No suitable address family'
             for (family, socktype, proto, canonname, sockaddr) in 
socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
                 if socktype == socket.SOCK_STREAM:
                     af = family
                     addr = sockaddr
-                    break
+                    sock = socket.socket(af, socket.SOCK_STREAM)
+                    try:
+                        sock.connect((hostname, port))
+                    except socket.error, e:
+                        reason = str(e)
+                    else:
+                        break
             else:
-                raise SSHException('No suitable address family for %s' % 
hostname)
-            sock = socket.socket(af, socket.SOCK_STREAM)
-            sock.connect((hostname, port))
+                raise SSHException(
+                    'Unable to connect to %s: %s' % (hostname, reason))
         # okay, normal socket-ish flow here...
         threading.Thread.__init__(self)
         self.setDaemon(True)
-- 
bzr 2.1.1, bzr-git 0.4.3, dulwich 0.4.1

_______________________________________________
paramiko mailing list
paramiko@lag.net
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko

Reply via email to