aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorsmill <smill@cuckoo.sh>2016-09-04 01:30:27 +0000
committersmill <smill@cuckoo.sh>2016-09-04 01:30:27 +0000
commitfbfedbdc8f02bc36191d3fbf0f5cb7756331c89d (patch)
treeb064696ab20a9f831c02e342b8ed02a2d8c93b15 /netlib
parent377921fa99e5c602ff04ed412be76072abc1d1c0 (diff)
downloadmitmproxy-fbfedbdc8f02bc36191d3fbf0f5cb7756331c89d.tar.gz
mitmproxy-fbfedbdc8f02bc36191d3fbf0f5cb7756331c89d.tar.bz2
mitmproxy-fbfedbdc8f02bc36191d3fbf0f5cb7756331c89d.zip
Improved error-handling / supplemented documention.
Diffstat (limited to 'netlib')
-rw-r--r--netlib/exceptions.py3
-rw-r--r--netlib/tcp.py8
2 files changed, 8 insertions, 3 deletions
diff --git a/netlib/exceptions.py b/netlib/exceptions.py
index dec79c22..795926f1 100644
--- a/netlib/exceptions.py
+++ b/netlib/exceptions.py
@@ -58,3 +58,6 @@ class InvalidCertificateException(TlsException):
class Timeout(TcpException):
pass
+
+class ProtocolException(NetlibException):
+ pass
diff --git a/netlib/tcp.py b/netlib/tcp.py
index aaea9459..37460743 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -731,10 +731,11 @@ class TCPClient(_Connection):
try:
connection = socket.socket(self.address.family, socket.SOCK_STREAM)
if self.spoof_source_address:
- if os.geteuid() != 0:
- raise RuntimeError("Insufficient privileges to set socket option")
- else:
+ try:
connection.setsockopt(socket.SOL_IP, 19, 1)
+ except socket.error as e:
+ raise exceptions.ProtocolException(
+ "Failed to spoof the source address: " + e.strerror)
if self.source_address:
connection.bind(self.source_address())
connection.connect(self.address())
@@ -874,6 +875,7 @@ class BaseHandler(_Connection):
class Counter:
+
def __init__(self):
self._count = 0
self._lock = threading.Lock()