mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
fix(faketcp): avoid pnet interface lookup on windows (#2029)
This commit is contained in:
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||||||
use std::{net::SocketAddr, pin::Pin};
|
use std::{net::SocketAddr, pin::Pin};
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use pnet::datalink;
|
use network_interface::NetworkInterfaceConfig;
|
||||||
use pnet::util::MacAddr;
|
use pnet::util::MacAddr;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
@@ -34,11 +34,18 @@ impl IpToIfNameCache {
|
|||||||
|
|
||||||
fn reload_ip_to_ifname(&self) {
|
fn reload_ip_to_ifname(&self) {
|
||||||
self.ip_to_ifname.clear();
|
self.ip_to_ifname.clear();
|
||||||
let interfaces = datalink::interfaces();
|
let Ok(interfaces) = network_interface::NetworkInterface::show() else {
|
||||||
|
tracing::warn!("failed to enumerate interfaces when reloading faketcp ip cache");
|
||||||
|
return;
|
||||||
|
};
|
||||||
for iface in interfaces {
|
for iface in interfaces {
|
||||||
for ip in iface.ips.iter() {
|
let mac = iface.mac_addr.as_deref().and_then(|mac| {
|
||||||
self.ip_to_ifname
|
mac.parse::<MacAddr>().map_err(|e| {
|
||||||
.insert(ip.ip(), (iface.name.clone(), iface.mac));
|
tracing::debug!(iface = %iface.name, mac, ?e, "failed to parse interface mac")
|
||||||
|
}).ok()
|
||||||
|
});
|
||||||
|
for ip in iface.addr.iter() {
|
||||||
|
self.ip_to_ifname.insert(ip.ip(), (iface.name.clone(), mac));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user