summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2021-10-28 01:10:54 +0300
committerMaxim Devaev <[email protected]>2021-10-28 01:10:54 +0300
commit88aad3bf87d401ed166f5de322d475e5dd98507a (patch)
tree8c419ba41f2df26c7ce1c877a52ce2bc99e2dc3e
parentea896f71168cc9bd9dc2795ea608a2843df29177 (diff)
pikvm/pikvm#521: fixed ipv4-only binding for vnc
-rw-r--r--kvmd/apps/vnc/server.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index 4c3d0a55..bfceacf5 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -500,10 +500,12 @@ class VncServer: # pylint: disable=too-many-instance-attributes
logger.info("Listening VNC on TCP [%s]:%d ...", self.__host, self.__port)
- with contextlib.closing(socket.socket(socket.AF_INET6, socket.SOCK_STREAM)) as sock:
- sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
+ (family, _, _, _, addr) = socket.getaddrinfo(self.__host, self.__port, type=socket.SOCK_STREAM)[0]
+ with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as sock:
+ if family == socket.AF_INET6:
+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- sock.bind((self.__host, self.__port))
+ sock.bind(addr)
server = loop.run_until_complete(asyncio.start_server(
client_connected_cb=self.__handle_client,