diff --git a/Cargo.toml b/Cargo.toml index 45c9f0a..d21b639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" [dependencies] chrono = "0.4" thiserror = "1.0" -pnet = "0.33" +pnet_datalink = { version = "0.35", default-features = false } [dev-dependencies] bencher = "0.1" diff --git a/src/builder.rs b/src/builder.rs index a5c6623..3094e76 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,5 +1,4 @@ use chrono::prelude::*; -use pnet::datalink; use std::{ net::{IpAddr, Ipv4Addr}, sync::{Arc, Mutex}, @@ -100,28 +99,18 @@ impl<'a> Builder<'a> { } fn private_ipv4() -> Option { - datalink::interfaces() + pnet_datalink::interfaces() .iter() .filter(|interface| interface.is_up() && !interface.is_loopback()) - .map(|interface| { - interface - .ips - .iter() - .map(|ip_addr| ip_addr.ip()) // convert to std - .find(|ip_addr| match ip_addr { - IpAddr::V4(ipv4) => is_private_ipv4(*ipv4), - IpAddr::V6(_) => false, - }) - .and_then(|ip_addr| match ip_addr { - IpAddr::V4(ipv4) => Some(ipv4), // make sure the return type is Ipv4Addr - _ => None, - }) + .flat_map(|interface| interface.ips.iter()) + .filter_map(|network| match network.ip() { + IpAddr::V4(ipv4) => Some(ipv4), + IpAddr::V6(_) => None, }) - .find(|ip| ip.is_some()) - .flatten() + .find(is_private_ipv4) } -fn is_private_ipv4(ip: Ipv4Addr) -> bool { +fn is_private_ipv4(ip: &Ipv4Addr) -> bool { let octets = ip.octets(); octets[0] == 10 || octets[0] == 172 && (octets[1] >= 16 && octets[1] < 32)