From a7ac97eb823f599ca04f588f6cbe4da28e00a194 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Thu, 12 Dec 2013 07:00:58 +0100 Subject: [PATCH 1/2] support ipv6 --- netlib/tcp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netlib/tcp.py b/netlib/tcp.py index 5a07c013a..ee5fe6185 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -176,12 +176,13 @@ class Reader(_FileLike): class TCPClient: rbufsize = -1 wbufsize = -1 - def __init__(self, host, port, source_address=None): + def __init__(self, host, port, source_address=None, use_ipv6=False): self.host, self.port = host, port self.connection, self.rfile, self.wfile = None, None, None self.cert = None self.ssl_established = False self.source_address = source_address + self.use_ipv6 = use_ipv6 def convert_to_ssl(self, cert=None, sni=None, method=TLSv1_METHOD, options=None): """ @@ -211,11 +212,10 @@ class TCPClient: def connect(self): try: - addr = socket.gethostbyname(self.host) - connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + connection = socket.socket(socket.AF_INET6 if self.use_ipv6 else socket.AF_INET, socket.SOCK_STREAM) if self.source_address: connection.bind(self.source_address) - connection.connect((addr, self.port)) + connection.connect((self.host, self.port)) self.rfile = Reader(connection.makefile('rb', self.rbufsize)) self.wfile = Writer(connection.makefile('wb', self.wbufsize)) except (socket.error, IOError), err: From 6f26cec83e77f8998b50988c54196f9dfae5b7dd Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Thu, 12 Dec 2013 07:11:13 +0100 Subject: [PATCH 2/2] tab fix --- netlib/tcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlib/tcp.py b/netlib/tcp.py index ee5fe6185..aa9ca0278 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -182,7 +182,7 @@ class TCPClient: self.cert = None self.ssl_established = False self.source_address = source_address - self.use_ipv6 = use_ipv6 + self.use_ipv6 = use_ipv6 def convert_to_ssl(self, cert=None, sni=None, method=TLSv1_METHOD, options=None): """