Unverified Commit 69e6afdf authored by mszarma's avatar mszarma Committed by GitHub
Browse files

Fix crashing on SIOCGIFADDR (#1733)

During scanning the list of interfaces,
some of them can be configured invalidly:
lack of ip, link down etc.
This patch handles the error
and inform about problem with concrete interface.
parent c8ec6ee5
...@@ -18,10 +18,21 @@ def local_ip4_addr_list(): ...@@ -18,10 +18,21 @@ def local_ip4_addr_list():
for if_nidx in socket.if_nameindex(): for if_nidx in socket.if_nameindex():
name = if_nidx[1] name = if_nidx[1]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip_addr = socket.inet_ntoa(fcntl.ioctl( try:
sock.fileno(), ip_of_ni = fcntl.ioctl(sock.fileno(),
0x8915, # SIOCGIFADDR 0x8915, # SIOCGIFADDR
struct.pack('256s', name[:15].encode("UTF-8")))[20:24]) struct.pack('256s', name[:15].encode("UTF-8")))
except OSError as e:
if e.errno == 99: # EADDRNOTAVAIL
print("Warning!",
"Interface: {}".format(name),
"IP address not available for interface.",
sep='\n')
continue
else:
raise e
ip_addr = socket.inet_ntoa(ip_of_ni[20:24])
nic.add(ip_addr) nic.add(ip_addr)
return nic return nic
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment