diff --git a/Cargo.lock b/Cargo.lock index e3d7b6b..4204b56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -661,12 +661,11 @@ dependencies = [ [[package]] name = "nix" -version = "0.23.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", - "cc", "cfg-if", "libc", "memoffset", diff --git a/shared/Cargo.toml b/shared/Cargo.toml index ad521ab..47a6024 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -31,4 +31,4 @@ netlink-packet-route = "0.13" netlink-request = { path = "../netlink-request" } [target.'cfg(target_os = "macos")'.dependencies] -nix = "0.23" +nix = "0.24" diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 6f87b2e..f8c4d1a 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -76,7 +76,9 @@ pub fn chmod(file: &File, new_mode: u32) -> Result { #[cfg(target_os = "macos")] pub fn _get_local_addrs() -> Result, io::Error> { - use nix::{net::if_::InterfaceFlags, sys::socket::SockAddr}; + use std::net::Ipv4Addr; + + use nix::net::if_::InterfaceFlags; let addrs = nix::ifaddrs::getifaddrs()? .filter(|addr| { @@ -87,9 +89,16 @@ pub fn _get_local_addrs() -> Result, io:: | InterfaceFlags::IFF_PROMISC, ) }) - .filter_map(|addr| match addr.address { - Some(SockAddr::Inet(addr)) => Some(addr.to_std().ip()), - _ => None, + .filter_map(|interface_addr| { + interface_addr.address.and_then(|addr| { + if let Some(sockaddr_in) = addr.as_sockaddr_in() { + Some(IpAddr::V4(Ipv4Addr::from(sockaddr_in.ip()))) + } else if let Some(sockaddr_in6) = addr.as_sockaddr_in6() { + Some(IpAddr::V6(sockaddr_in6.ip())) + } else { + None + } + }) }); Ok(addrs)