From 1790140abeba04cef8c215afa4477ed56375e8fb Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Sun, 26 Sep 2021 13:46:13 +0900 Subject: [PATCH] Disable promiscuous mode --- Cargo.toml | 4 ++-- src/gateway.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index df98a0c..038979a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "default-net" -version = "0.3.0" +version = "0.4.0" authors = ["shellrow <81893184+shellrow@users.noreply.github.com>"] edition = "2018" description = "Get default network information" @@ -14,4 +14,4 @@ license = "MIT" pnet = "0.28" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = [ "std" ] } +winapi = { version = "0.3.9", features = [ "std" ] } diff --git a/src/gateway.rs b/src/gateway.rs index d9bb9a3..9bb5b49 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -85,7 +85,17 @@ fn receive_icmp_packets(icmp_type: pnet::packet::icmp::IcmpType, timeout: &Durat }; 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 (mut _tx, mut rx) = match pnet::datalink::channel(&interface, Default::default()) { + 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),