Skip to content

Commit

Permalink
#3930 Python 3.8+ provides this function
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Sep 5, 2023
1 parent 11a74ac commit c77bf9e
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions xpra/net/socket_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,10 @@ def cleanup_socket() -> None:
pass
return listener, cleanup_socket

def has_dual_stack() -> bool:
"""
Return True if kernel allows creating a socket which is able to
listen for both IPv4 and IPv6 connections.
If *sock* is provided the check is made against it.
"""
try:
assert socket.AF_INET6 and socket.IPPROTO_IPV6 and socket.IPV6_V6ONLY
except AttributeError:
return False
try:
import contextlib
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
with contextlib.closing(sock):
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
return True
except OSError:
return False

def hosts(host_str:str) -> list[str]:
if host_str=="*":
if has_dual_stack():
if socket.has_dualstack_ipv6():
#IPv6 will also listen for IPv4:
return ["::"]
#no dual stack, so we have to listen on both IPv4 and IPv6 explicitly:
Expand Down

0 comments on commit c77bf9e

Please sign in to comment.