Skip to content

Commit 580beaa

Browse files
authored
Merge pull request #19 from mon/new-if-addrs
Move to maintained `if-addrs` crate
2 parents 0504098 + 8107217 commit 580beaa

File tree

3 files changed

+3
-37
lines changed

3 files changed

+3
-37
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = 'MIT OR Apache-2.0'
1111
keywords = ['multicast']
1212

1313
[dependencies]
14-
get_if_addrs = '0.5.3'
14+
if-addrs = '0.11.1'
1515

1616
[dependencies.socket2]
1717
version = '0.3.19'

src/unix.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,8 @@ pub struct Message {
6161
pub interface: Interface,
6262
}
6363

64-
/// The crate `get_if_addrs` is reading the bytes of sockets on the wrong endianess on MIPS
65-
/// So the adresses are reversed...
66-
/// The crate `get_if_addrs` is archived and I don't have bandwidth to fork it
67-
/// So this is a hotfix
68-
#[cfg(target_arch = "mips")]
69-
fn reverse_interface(interface: get_if_addrs::Interface) -> get_if_addrs::Interface {
70-
get_if_addrs::Interface {
71-
name: interface.name,
72-
addr: match interface.addr {
73-
get_if_addrs::IfAddr::V4(v4) => {
74-
let reversed = get_if_addrs::Ifv4Addr {
75-
ip: reverse_address(v4.ip),
76-
netmask: reverse_address(v4.netmask),
77-
broadcast: v4.broadcast.map(reverse_address),
78-
};
79-
get_if_addrs::IfAddr::V4(reversed)
80-
}
81-
addr => addr,
82-
},
83-
}
84-
}
85-
86-
#[cfg(target_arch = "mips")]
87-
fn reverse_address(v4: Ipv4Addr) -> Ipv4Addr {
88-
let mut octets = v4.octets();
89-
octets.reverse();
90-
octets.into()
91-
}
92-
9364
pub fn all_ipv4_interfaces() -> io::Result<Vec<Ipv4Addr>> {
94-
#[cfg(not(target_arch = "mips"))]
95-
let interfaces = get_if_addrs::get_if_addrs()?.into_iter();
96-
#[cfg(target_arch = "mips")]
97-
let interfaces = get_if_addrs::get_if_addrs()?
98-
.into_iter()
99-
.map(reverse_interface);
65+
let interfaces = if_addrs::get_if_addrs()?.into_iter();
10066

10167
// We have to filter the same interface if it has multiple ips
10268
// https://stackoverflow.com/questions/49819010/ip-add-membership-fails-when-set-both-on-interface-and-its-subinterface-is-that

src/win.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const PKTINFO_DATA_SIZE: usize = mem::size_of::<IN_PKTINFO>();
248248
const CONTROL_PKTINFO_BUFFER_SIZE: usize = CMSG_HEADER_SIZE + PKTINFO_DATA_SIZE;
249249

250250
pub fn all_ipv4_interfaces() -> io::Result<Vec<Ipv4Addr>> {
251-
let interfaces = get_if_addrs::get_if_addrs()?
251+
let interfaces = if_addrs::get_if_addrs()?
252252
.into_iter()
253253
.filter_map(|i| match i.ip() {
254254
std::net::IpAddr::V4(v4) => Some(v4),

0 commit comments

Comments
 (0)