From 586f5cc2f8e0056dbf28e30aa075d983206e2905 Mon Sep 17 00:00:00 2001 From: PierluigiGreto Date: Tue, 8 May 2018 16:32:19 +0200 Subject: [PATCH] handle OSError errno 97 when ipv6 is disabled --- sshutil/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sshutil/server.py b/sshutil/server.py index bb4935d..95bfa3d 100644 --- a/sshutil/server.py +++ b/sshutil/server.py @@ -360,7 +360,12 @@ def __init__(self, # Bind first to IPv6, if the OS supports binding per AF then the IPv4 # will succeed, otherwise the IPv6 will support both AF. for pname, host, proto in [("IPv6", '::', socket.AF_INET6), ("IPv4", '', socket.AF_INET)]: - protosocket = socket.socket(proto, socket.SOCK_STREAM) + try: + protosocket = socket.socket(proto, socket.SOCK_STREAM) + except OSError as e: + if e.errno == errno.EAFNOSUPPORT: + continue + raise protosocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if self.debug: logger.debug("Server binding to proto %s port %s", str(pname), str(port))