diff options
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/exceptions.py | 3 | ||||
-rw-r--r-- | netlib/tcp.py | 8 |
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() |