From 389020e14594e4894e28d1eb9103c210b142509e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 23 May 2024 18:45:13 +0200 Subject: Adding upstream version 18.2.3. Signed-off-by: Daniel Baumann --- src/pybind/mgr/mgr_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pybind/mgr/mgr_util.py') diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index 8684f8013..05ec64966 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -12,6 +12,7 @@ import socket import time import logging import sys +from ipaddress import ip_address from threading import Lock, Condition, Event from typing import no_type_check, NewType import urllib @@ -413,7 +414,9 @@ def test_port_allocation(addr: str, port: int) -> None: If no exception is raised, the port can be assumed available """ try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + ip_version = ip_address(addr).version + addr_family = socket.AF_INET if ip_version == 4 else socket.AF_INET6 + sock = socket.socket(addr_family, socket.SOCK_STREAM) sock.bind((addr, port)) sock.close() except socket.error as e: -- cgit v1.2.3