shared: update nix to 0.24

pull/239/head
Jake McGinty 2022-08-10 16:30:45 -06:00
parent 55671ec80a
commit c9dbeefaaa
3 changed files with 16 additions and 8 deletions

5
Cargo.lock generated
View File

@ -661,12 +661,11 @@ dependencies = [
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.23.1" version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc",
"cfg-if", "cfg-if",
"libc", "libc",
"memoffset", "memoffset",

View File

@ -31,4 +31,4 @@ netlink-packet-route = "0.13"
netlink-request = { path = "../netlink-request" } netlink-request = { path = "../netlink-request" }
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
nix = "0.23" nix = "0.24"

View File

@ -76,7 +76,9 @@ pub fn chmod(file: &File, new_mode: u32) -> Result<bool, io::Error> {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub fn _get_local_addrs() -> Result<impl Iterator<Item = std::net::IpAddr>, io::Error> { pub fn _get_local_addrs() -> Result<impl Iterator<Item = std::net::IpAddr>, io::Error> {
use nix::{net::if_::InterfaceFlags, sys::socket::SockAddr}; use std::net::Ipv4Addr;
use nix::net::if_::InterfaceFlags;
let addrs = nix::ifaddrs::getifaddrs()? let addrs = nix::ifaddrs::getifaddrs()?
.filter(|addr| { .filter(|addr| {
@ -87,9 +89,16 @@ pub fn _get_local_addrs() -> Result<impl Iterator<Item = std::net::IpAddr>, io::
| InterfaceFlags::IFF_PROMISC, | InterfaceFlags::IFF_PROMISC,
) )
}) })
.filter_map(|addr| match addr.address { .filter_map(|interface_addr| {
Some(SockAddr::Inet(addr)) => Some(addr.to_std().ip()), interface_addr.address.and_then(|addr| {
_ => None, 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) Ok(addrs)