Skip to content

Commit

Permalink
fix: show understandable error in socket binding (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhdix authored Aug 8, 2022
1 parent fd1b196 commit 133e83c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/ephemeral_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 133e83c

Please sign in to comment.