Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sub-interfaces in network_helper::get_interface_ip_networks #1366

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading