aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMatthias Urlichs <matthias@urlichs.de>2013-12-12 07:00:58 +0100
committerMatthias Urlichs <matthias@urlichs.de>2013-12-12 07:00:58 +0100
commita7ac97eb823f599ca04f588f6cbe4da28e00a194 (patch)
tree92a2aae06d5552fa3023bfe874f35105eb3a7d72 /netlib
parentd66fd5ba1b11ad57b7825b7feb67392f45e88c24 (diff)
downloadmitmproxy-a7ac97eb823f599ca04f588f6cbe4da28e00a194.tar.gz
mitmproxy-a7ac97eb823f599ca04f588f6cbe4da28e00a194.tar.bz2
mitmproxy-a7ac97eb823f599ca04f588f6cbe4da28e00a194.zip
support ipv6
Diffstat (limited to 'netlib')
-rw-r--r--netlib/tcp.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 5a07c013..ee5fe618 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: