diff options
author | remgodow <remgodow@users.noreply.github.com> | 2020-09-10 18:52:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-10 18:52:30 +0200 |
commit | 075693975376be05d228bc45b321b1f6d08021cd (patch) | |
tree | 13a4180f8fc43b690aca4cb038405905761eab81 /src/os/shared.rs | |
parent | 16d9758abfd3a8e48b1666496c9fc4ef2db00c3f (diff) |
feat(platform): windows build and run support (#180)
* Remove connections vector from OpenSockets, use common OpenSockets implementation based on sysinfo and netstat2.
* Replace termion backend with crossterm, which works on Windows as well.
* More fixes for windows build.
* Remove tui default-features (termion), update unit tests for crossterm.
* Windows compilation fixes.
* Remove unused get_open_sockets implementations for linux and mac. Fix formatting.
* Add build.rs for windows to download and extract Packet.lib from npcap SDK.
* Resolve Cargo.lock after merging main.
* fix(tests): adjust snapshots new location of the dns resolution
* style(clippy): clippy
* style(clippy): remove dead code
* style(clippy): use write_all in build.rs
* style(clippy): remove unused import added by Intellij
* style(review): use String instead of str
* fix(build): run build.rs only once
* fix(regression): skip iface_is_up() filter only for Windows
* fix(review): restore per os implementation of get_open_sockets()
* fix(cargo): add missing os specific packages
* fix: conditional compilation of windows module
* fix: compilation errors
* fix: missing Protocol::from_str() implementation
* style(clippy): remove unused methods
Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'src/os/shared.rs')
-rw-r--r-- | src/os/shared.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/os/shared.rs b/src/os/shared.rs index 7c252bf..4cc0c24 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -9,12 +9,16 @@ use ::tokio::runtime::Runtime; use ::std::time; use crate::os::errors::GetInterfaceErrorKind; +#[cfg(not(target_os = "windows"))] use signal_hook::iterator::Signals; #[cfg(target_os = "linux")] use crate::os::linux::get_open_sockets; #[cfg(any(target_os = "macos", target_os = "freebsd"))] use crate::os::lsof::get_open_sockets; +#[cfg(target_os = "windows")] +use crate::os::windows::get_open_sockets; + use crate::{network::dns, OsInputOutput}; pub type OnSigWinch = dyn Fn(Box<dyn Fn()>) + Send; @@ -63,6 +67,7 @@ fn get_interface(interface_name: &str) -> Option<NetworkInterface> { .find(|iface| iface.name == interface_name) } +#[cfg(not(target_os = "windows"))] fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) { let signals = Signals::new(&[signal_hook::SIGWINCH]).unwrap(); let on_winch = { @@ -82,6 +87,15 @@ fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) { (Box::new(on_winch), Box::new(cleanup)) } +#[cfg(any(target_os = "windows"))] +fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) { + let on_winch = { move |_cb: Box<dyn Fn()>| {} }; + let cleanup = move || { + println!("Fake signal cleanup"); + }; + (Box::new(on_winch), Box::new(cleanup)) +} + fn create_write_to_stdout() -> Box<dyn FnMut(String) + Send> { Box::new({ let mut stdout = io::stdout(); @@ -180,6 +194,12 @@ pub fn get_input( datalink::interfaces() }; + #[cfg(any(target_os = "windows"))] + let network_frames = network_interfaces + .iter() + .filter(|iface| !iface.ips.is_empty()) + .map(|iface| (iface, get_datalink_channel(iface))); + #[cfg(not(target_os = "windows"))] let network_frames = network_interfaces .iter() .filter(|iface| iface.is_up() && !iface.ips.is_empty()) @@ -257,3 +277,9 @@ fn eperm_message() -> &'static str { `cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep` "# } + +#[inline] +#[cfg(any(target_os = "windows"))] +fn eperm_message() -> &'static str { + "Insufficient permissions to listen on network interface(s). Try running with administrator rights." +} |