summaryrefslogtreecommitdiffhomepage
path: root/paramiko/transport.py
diff options
context:
space:
mode:
Diffstat (limited to 'paramiko/transport.py')
-rw-r--r--paramiko/transport.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/paramiko/transport.py b/paramiko/transport.py
index 758ba37d..e04db26a 100644
--- a/paramiko/transport.py
+++ b/paramiko/transport.py
@@ -285,19 +285,25 @@ class Transport (threading.Thread):
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)
- self.randpool = randpool
+ self.rng = rng
self.sock = sock
# Python < 2.3 doesn't have the settimeout method - RogerB
try:
@@ -585,7 +591,7 @@ class Transport (threading.Thread):
@note: This has no effect when used in client mode.
"""
- Transport._modulus_pack = ModulusPack(randpool)
+ Transport._modulus_pack = ModulusPack(rng)
# places to look for the openssh "moduli" file
file_list = [ '/etc/ssh/moduli', '/usr/local/etc/moduli' ]
if filename is not None:
@@ -837,10 +843,9 @@ class Transport (threading.Thread):
"""
m = Message()
m.add_byte(chr(MSG_IGNORE))
- randpool.stir()
if bytes is None:
- bytes = (ord(randpool.get_bytes(1)) % 32) + 10
- m.add_bytes(randpool.get_bytes(bytes))
+ bytes = (ord(rng.read(1)) % 32) + 10
+ m.add_bytes(rng.read(bytes))
self._send_user_message(m)
def renegotiate_keys(self):
@@ -1674,10 +1679,9 @@ class Transport (threading.Thread):
else:
available_server_keys = self._preferred_keys
- randpool.stir()
m = Message()
m.add_byte(chr(MSG_KEXINIT))
- m.add_bytes(randpool.get_bytes(16))
+ m.add_bytes(rng.read(16))
m.add_list(self._preferred_kex)
m.add_list(available_server_keys)
m.add_list(self._preferred_ciphers)