mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Fix check for IPv6 enabled on host
This commit is contained in:
2 files changed
+29
-8
No files matched your search
@@ -21,6 +21,8 @@ import re
|
||||
import shlex
|
||||
import textwrap
|
||||
import posixpath
|
||||
import socket
|
||||
import errno
|
||||
|
||||
|
||||
def force_unix_path(path):
|
||||
@@ -100,3 +102,21 @@ def shlex_quote(s):
|
||||
return s if re.match(r'^[-_\w./]+$', s) else '"%s"' % s.replace('"', '\\"')
|
||||
else:
|
||||
return shlex.quote(s)
|
||||
|
||||
|
||||
def is_ipv6_enabled() -> bool:
|
||||
|
||||
if not socket.has_ipv6:
|
||||
return False # the socket library has no support for IPv6
|
||||
try:
|
||||
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
|
||||
sock.bind(("::1", 0))
|
||||
return True
|
||||
except OSError as e:
|
||||
if e.errno in (errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT):
|
||||
# EADDRNOTAVAIL is the errno if IPv6 modules/drivers are loaded but disabled.
|
||||
# EAFNOSUPPORT is the errno if IPv6 modules/drivers are not loaded at all.
|
||||
return False
|
||||
if e.errno == errno.EADDRINUSE:
|
||||
return True
|
||||
raise
|
||||
Reference in new issue
Block a user