From 2ab59dcb8979605029cfc920e9e8e18ea850c95b Mon Sep 17 00:00:00 2001 From: Gwendal Didot Date: Mon, 28 Oct 2024 11:07:58 +0100 Subject: [PATCH] fix(unix): add support for sub-interfaces in network_helpers::get_interface_ip_networks --- src/unix/network_helper.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/unix/network_helper.rs b/src/unix/network_helper.rs index 8625eca3b..c41ab205f 100644 --- a/src/unix/network_helper.rs +++ b/src/unix/network_helper.rs @@ -151,7 +151,18 @@ pub(crate) unsafe fn get_interface_ip_networks() -> HashMap: + if name.contains(':') { + if let Some(interface_name) = name.split(':').next() { + name = interface_name.to_string() + } else { + // The sub-interface is malformed, skipping to the next addr + addr = addr_ref.ifa_next; + continue; + } + } + let ip = sockaddr_to_network_addr(addr_ref.ifa_addr as *const libc::sockaddr); let netmask = sockaddr_to_network_addr(addr_ref.ifa_netmask as *const libc::sockaddr); let prefix = netmask