Support for ICMP problems in pnet

main
shellrow 3 years ago
parent 9e804ec020
commit 1e988cafb1
  1. 7
      Cargo.toml
  2. 24
      src/gateway.rs

@ -1,6 +1,6 @@
[package] [package]
name = "default-net" name = "default-net"
version = "0.2.0" version = "0.2.1"
authors = ["shellrow <81893184+shellrow@users.noreply.github.com>"] authors = ["shellrow <81893184+shellrow@users.noreply.github.com>"]
edition = "2018" edition = "2018"
description = "Get default network information" description = "Get default network information"
@ -10,8 +10,5 @@ keywords = ["network"]
categories = ["network-programming"] categories = ["network-programming"]
license = "MIT" license = "MIT"
[target.'cfg(not(windows))'.dependencies] [dependencies]
pnet = "0.27"
[target.'cfg(target_os = "windows")'.dependencies]
pnet = "0.26" pnet = "0.26"

@ -65,30 +65,6 @@ fn send_udp_packet(){
socket.send_to(&buf, dest).unwrap(); socket.send_to(&buf, dest).unwrap();
} }
#[cfg(not(windows))]
fn receive_icmp_packets(icmp_type: pnet::packet::icmp::IcmpType, timeout: &Duration) -> Result<String, String>{
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<String, String>{ fn receive_icmp_packets(icmp_type: pnet::packet::icmp::IcmpType, timeout: &Duration) -> Result<String, String>{
let default_idx = interface::get_default_interface_index().unwrap(); let default_idx = interface::get_default_interface_index().unwrap();
let interfaces = pnet::datalink::interfaces(); let interfaces = pnet::datalink::interfaces();

Loading…
Cancel
Save