Merge pull request #7 from jelmer/master

Fix for issue 6: paramiko does not try all available address families
This commit is contained in:
Robey Pointer 2011-05-21 19:02:23 -07:00
commit 4efd0e6d3c
1 changed files with 10 additions and 4 deletions

View File

@ -285,15 +285,21 @@ class Transport (threading.Thread):
if type(sock) is tuple: if type(sock) is tuple:
# connect to the given (host, port) # connect to the given (host, port)
hostname, port = sock 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): for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
if socktype == socket.SOCK_STREAM: if socktype == socket.SOCK_STREAM:
af = family af = family
addr = sockaddr addr = sockaddr
sock = socket.socket(af, socket.SOCK_STREAM)
try:
sock.connect((hostname, port))
except socket.error, e:
reason = str(e)
else:
break break
else: else:
raise SSHException('No suitable address family for %s' % hostname) raise SSHException(
sock = socket.socket(af, socket.SOCK_STREAM) 'Unable to connect to %s: %s' % (hostname, reason))
sock.connect((hostname, port))
# okay, normal socket-ish flow here... # okay, normal socket-ish flow here...
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.setDaemon(True) self.setDaemon(True)