From 8107217a0cd2dabc95bb77e8e63abb5c972533f8 Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Tue, 2 Apr 2024 13:15:39 +1000 Subject: [PATCH] Move to maintained `if-addrs` crate --- Cargo.toml | 2 +- src/unix.rs | 36 +----------------------------------- src/win.rs | 2 +- 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60b3ff5..ea6e68b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = 'MIT OR Apache-2.0' keywords = ['multicast'] [dependencies] -get_if_addrs = '0.5.3' +if-addrs = '0.11.1' [dependencies.socket2] version = '0.3.19' diff --git a/src/unix.rs b/src/unix.rs index a0dbcbe..e9f40bd 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -61,42 +61,8 @@ pub struct Message { pub interface: Interface, } -/// The crate `get_if_addrs` is reading the bytes of sockets on the wrong endianess on MIPS -/// So the adresses are reversed... -/// The crate `get_if_addrs` is archived and I don't have bandwidth to fork it -/// So this is a hotfix -#[cfg(target_arch = "mips")] -fn reverse_interface(interface: get_if_addrs::Interface) -> get_if_addrs::Interface { - get_if_addrs::Interface { - name: interface.name, - addr: match interface.addr { - get_if_addrs::IfAddr::V4(v4) => { - let reversed = get_if_addrs::Ifv4Addr { - ip: reverse_address(v4.ip), - netmask: reverse_address(v4.netmask), - broadcast: v4.broadcast.map(reverse_address), - }; - get_if_addrs::IfAddr::V4(reversed) - } - addr => addr, - }, - } -} - -#[cfg(target_arch = "mips")] -fn reverse_address(v4: Ipv4Addr) -> Ipv4Addr { - let mut octets = v4.octets(); - octets.reverse(); - octets.into() -} - pub fn all_ipv4_interfaces() -> io::Result> { - #[cfg(not(target_arch = "mips"))] - let interfaces = get_if_addrs::get_if_addrs()?.into_iter(); - #[cfg(target_arch = "mips")] - let interfaces = get_if_addrs::get_if_addrs()? - .into_iter() - .map(reverse_interface); + let interfaces = if_addrs::get_if_addrs()?.into_iter(); // We have to filter the same interface if it has multiple ips // https://stackoverflow.com/questions/49819010/ip-add-membership-fails-when-set-both-on-interface-and-its-subinterface-is-that diff --git a/src/win.rs b/src/win.rs index 2a0dd41..0ccc1a6 100644 --- a/src/win.rs +++ b/src/win.rs @@ -248,7 +248,7 @@ const PKTINFO_DATA_SIZE: usize = mem::size_of::(); const CONTROL_PKTINFO_BUFFER_SIZE: usize = CMSG_HEADER_SIZE + PKTINFO_DATA_SIZE; pub fn all_ipv4_interfaces() -> io::Result> { - let interfaces = get_if_addrs::get_if_addrs()? + let interfaces = if_addrs::get_if_addrs()? .into_iter() .filter_map(|i| match i.ip() { std::net::IpAddr::V4(v4) => Some(v4),