From 1e988cafb145f2b9b848f9d226fab784f5d652f9 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Thu, 8 Jul 2021 22:04:18 +0900 Subject: [PATCH] Support for ICMP problems in pnet --- Cargo.toml | 7 ++----- src/gateway.rs | 24 ------------------------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0b69a5..dd1cf6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "default-net" -version = "0.2.0" +version = "0.2.1" authors = ["shellrow <81893184+shellrow@users.noreply.github.com>"] edition = "2018" description = "Get default network information" @@ -10,8 +10,5 @@ keywords = ["network"] categories = ["network-programming"] license = "MIT" -[target.'cfg(not(windows))'.dependencies] -pnet = "0.27" - -[target.'cfg(target_os = "windows")'.dependencies] +[dependencies] pnet = "0.26" diff --git a/src/gateway.rs b/src/gateway.rs index f3342b4..452164a 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -65,30 +65,6 @@ fn send_udp_packet(){ socket.send_to(&buf, dest).unwrap(); } -#[cfg(not(windows))] -fn receive_icmp_packets(icmp_type: pnet::packet::icmp::IcmpType, timeout: &Duration) -> Result{ - let default_idx = interface::get_default_interface_index().unwrap(); - let interfaces = pnet::datalink::interfaces(); - let interface = interfaces.into_iter().filter(|interface: &pnet::datalink::NetworkInterface| interface.index == default_idx).next().expect("Failed to get Interface"); - let config = pnet::datalink::Config { - write_buffer_size: 4096, - read_buffer_size: 4096, - read_timeout: None, - write_timeout: None, - channel_type: pnet::datalink::ChannelType::Layer2, - bpf_fd_attempts: 1000, - linux_fanout: None, - promiscuous: false, - }; - let (mut _tx, mut rx) = match pnet::datalink::channel(&interface, config) { - Ok(pnet::datalink::Channel::Ethernet(tx, rx)) => (tx, rx), - Ok(_) => panic!("Unknown channel type"), - Err(e) => panic!("Error happened {}", e), - }; - receive_packets(&mut rx, icmp_type, timeout) -} - -#[cfg(target_os = "windows")] fn receive_icmp_packets(icmp_type: pnet::packet::icmp::IcmpType, timeout: &Duration) -> Result{ let default_idx = interface::get_default_interface_index().unwrap(); let interfaces = pnet::datalink::interfaces();