Skip to content

Commit

Permalink
Merge pull request #74 from shellrow/add-macos-if-type
Browse files Browse the repository at this point in the history
Add macOS interface type
  • Loading branch information
shellrow authored Jun 6, 2024
2 parents 5ce40ff + f3a789a commit cbc291d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/interface/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use system_configuration::network_configuration;

fn get_if_type_from_id(type_id: String) -> InterfaceType {
match type_id.as_str() {
"Bridge" => InterfaceType::Bridge,
"Ethernet" => InterfaceType::Ethernet,
"IEEE80211" => InterfaceType::Wireless80211,
"Loopback" => InterfaceType::Loopback,
"Modem" => InterfaceType::GenericModem,
"PPP" => InterfaceType::Ppp,
"Bridge" => InterfaceType::Bridge,
_ => InterfaceType::Unknown,
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/interface/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ fn sockaddr_to_network_addr(sa: *mut libc::sockaddr) -> (Option<MacAddr>, Option
}
}

#[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
fn get_interface_type(addr_ref: &libc::ifaddrs) -> InterfaceType {
if !addr_ref.ifa_data.is_null() {
let if_data = unsafe { &*(addr_ref.ifa_data as *const libc::if_data) };
Expand All @@ -236,12 +242,7 @@ fn get_interface_type(addr_ref: &libc::ifaddrs) -> InterfaceType {
}
}

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "macos",
target_os = "ios"
))]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn get_interface_type(_addr_ref: &libc::ifaddrs) -> InterfaceType {
InterfaceType::Unknown
}
Expand Down

0 comments on commit cbc291d

Please sign in to comment.