Skip to content

Commit

Permalink
Merge pull request #19 from mon/new-if-addrs
Browse files Browse the repository at this point in the history
Move to maintained `if-addrs` crate
  • Loading branch information
bltavares authored Apr 27, 2024
2 parents 0504098 + 8107217 commit 580beaa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
36 changes: 1 addition & 35 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Ipv4Addr>> {
#[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
Expand Down
2 changes: 1 addition & 1 deletion src/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const PKTINFO_DATA_SIZE: usize = mem::size_of::<IN_PKTINFO>();
const CONTROL_PKTINFO_BUFFER_SIZE: usize = CMSG_HEADER_SIZE + PKTINFO_DATA_SIZE;

pub fn all_ipv4_interfaces() -> io::Result<Vec<Ipv4Addr>> {
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),
Expand Down

0 comments on commit 580beaa

Please # to comment.