Skip to content

Move to maintained if-addrs crate #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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