Skip to content

Commit

Permalink
fix ipv6 support in SSHClient
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhar committed Apr 18, 2009
1 parent 5e32b33 commit 20e3306
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions paramiko/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,21 @@ def connect(self, hostname, port=22, username=None, password=None, pkey=None,
establishing an SSH session
@raise socket.error: if a socket error occurred while connecting
"""
if len(hostname.split(':')) > 1:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
for (family, socktype, proto, canonname, sockaddr) in \
socket.getaddrinfo(hostname, port):
if socktype==socket.SOCK_STREAM:
af = family
ADDR = sockaddr
break
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
raise SSHException('No suitable address family for %s' % hostname)
sock = socket.socket(af, socket.SOCK_STREAM)
if timeout is not None:
try:
sock.settimeout(timeout)
except:
pass

sock.connect((hostname, port))
sock.connect(addr)
t = self._transport = Transport(sock)

if self._log_channel is not None:
Expand Down Expand Up @@ -316,6 +320,8 @@ def connect(self, hostname, port=22, username=None, password=None, pkey=None,
else:
key_filenames = key_filename
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
if agent_forwarding:
self._forward_agent()

def close(self):
"""
Expand Down Expand Up @@ -474,4 +480,4 @@ def _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_k

def _log(self, level, msg):
self._transport._log(level, msg)

0 comments on commit 20e3306

Please sign in to comment.