From 133e83cd8a89ce145169fcd72978a94de1dced0d Mon Sep 17 00:00:00 2001 From: xhdix Date: Mon, 8 Aug 2022 14:35:35 +0300 Subject: [PATCH] fix: show understandable error in socket binding (#74) --- utils/ephemeral_port.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/ephemeral_port.py b/utils/ephemeral_port.py index 5f2487a..a7004f3 100644 --- a/utils/ephemeral_port.py +++ b/utils/ephemeral_port.py @@ -13,7 +13,13 @@ def ephemeral_port_reserve(user_source_ip_address: str, proto: str = "tcp"): socketkind = socket.SOCK_DGRAM ipproto = socket.IPPROTO_UDP with contextlib.closing(socket.socket(socket.AF_INET, socketkind, ipproto)) as s: - s.bind((user_source_ip_address, 0)) + try: + s.bind((user_source_ip_address, 0)) + except: + print("An error occurred when trying to bind to:" + str(user_source_ip_address)) + print("It seems that the specified network interface is not connected to the network.") + print("Please make sure you are connected to the network or choose a correct iface.") + raise # the connect below deadlocks on kernel >= 4.4.0 unless this arg is greater than zero if proto == "tcp": s.listen(1)