Skip to content

Commit

Permalink
Merge pull request #1366 from stormshield-gwendald/master
Browse files Browse the repository at this point in the history
Add support for sub-interfaces in network_helper::get_interface_ip_networks
  • Loading branch information
GuillaumeGomez authored Oct 28, 2024
2 parents 46a8288 + 2ab59dc commit 876c52a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/unix/network_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,18 @@ pub(crate) unsafe fn get_interface_ip_networks() -> HashMap<String, HashSet<IpNe
let bytes = CStr::from_ptr(c_str).to_bytes();

// Safety: Interfaces on unix must be valid UTF-8
let name = from_utf8_unchecked(bytes).to_owned();
let mut name = from_utf8_unchecked(bytes).to_owned();
// Interfaces names may be formatted as <interface name>:<sub-interface index>
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
Expand Down

0 comments on commit 876c52a

Please sign in to comment.