From dea95d406708522af438edf3bb2eeb992245cff6 Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Sat, 11 Jan 2020 15:00:33 +0100 Subject: [PATCH] Add support for more operating systems. This commit will add support for operating systems that have the lsof tool, initially it will only work on MacOS and FreeBSD, but more operating systems may be added at a later time. Signed-off-by: Valdemar Erk --- src/network/connection.rs | 2 +- src/os/{macos.rs => lsof.rs} | 0 src/os/mod.rs | 6 +++--- src/os/shared.rs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/os/{macos.rs => lsof.rs} (100%) diff --git a/src/network/connection.rs b/src/network/connection.rs index 907e9298f..bdbf4484b 100644 --- a/src/network/connection.rs +++ b/src/network/connection.rs @@ -14,7 +14,7 @@ impl Protocol { // Currently, linux implementation doesn't use this function. // Without this #[cfg] clippy complains about dead code, and CI refuses // to pass. - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "freebsd"))] pub fn from_str(string: &str) -> Option { match string { "TCP" => Some(Protocol::Tcp), diff --git a/src/os/macos.rs b/src/os/lsof.rs similarity index 100% rename from src/os/macos.rs rename to src/os/lsof.rs diff --git a/src/os/mod.rs b/src/os/mod.rs index acc715091..04c1f08b0 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -1,10 +1,10 @@ #[cfg(target_os = "linux")] pub(self) mod linux; -#[cfg(target_os = "macos")] -pub(self) mod macos; +#[cfg(any(target_os = "macos", target_os = "freebsd"))] +pub(self) mod lsof; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "freebsd"))] mod lsof_utils; mod shared; diff --git a/src/os/shared.rs b/src/os/shared.rs index 55a8553c7..852d4f74e 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -13,8 +13,8 @@ use signal_hook::iterator::Signals; #[cfg(target_os = "linux")] use crate::os::linux::get_open_sockets; -#[cfg(target_os = "macos")] -use crate::os::macos::get_open_sockets; +#[cfg(any(target_os = "macos", target_os = "freebsd"))] +use crate::os::lsof::get_open_sockets; use crate::{network::dns, OsInputOutput}; pub type OnSigWinch = dyn Fn(Box) + Send; @@ -143,7 +143,7 @@ pub fn get_input( } #[inline] -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "freebsd"))] fn eperm_message() -> &'static str { "Insufficient permissions to listen on network interface(s). Try running with sudo." }