From 5a221a8e151ba2644d6e09f11c247ab299246f9c Mon Sep 17 00:00:00 2001 From: Tudy GOURMELEN Date: Tue, 26 Jul 2022 12:39:57 +0200 Subject: [PATCH] fix: ignore interface with no link address --- src/linux.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/linux.rs b/src/linux.rs index dc5a4b5..95f67d3 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -146,6 +146,13 @@ pub fn list_afinet_netifas() -> Result, Error> { while !(**ifa).ifa_next.is_null() { let ifa_addr = (**ifa).ifa_addr; + // If a tun device is present, no link address is assigned to it and `ifa_addr` is null. + // See https://github.com/EstebanBorai/local-ip-address/issues/24 + if ifa_addr.is_null() { + *ifa = (**ifa).ifa_next; + continue; + } + match (*ifa_addr).sa_family as i32 { // AF_INET IPv4 protocol implementation AF_INET => {