Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dea95d4

Browse files
committed
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 <[email protected]>
1 parent 21938b6 commit dea95d4

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/network/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Protocol {
1414
// Currently, linux implementation doesn't use this function.
1515
// Without this #[cfg] clippy complains about dead code, and CI refuses
1616
// to pass.
17-
#[cfg(target_os = "macos")]
17+
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
1818
pub fn from_str(string: &str) -> Option<Self> {
1919
match string {
2020
"TCP" => Some(Protocol::Tcp),
File renamed without changes.

src/os/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#[cfg(target_os = "linux")]
22
pub(self) mod linux;
33

4-
#[cfg(target_os = "macos")]
5-
pub(self) mod macos;
4+
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
5+
pub(self) mod lsof;
66

7-
#[cfg(target_os = "macos")]
7+
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
88
mod lsof_utils;
99

1010
mod shared;

src/os/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use signal_hook::iterator::Signals;
1313

1414
#[cfg(target_os = "linux")]
1515
use crate::os::linux::get_open_sockets;
16-
#[cfg(target_os = "macos")]
17-
use crate::os::macos::get_open_sockets;
16+
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
17+
use crate::os::lsof::get_open_sockets;
1818
use crate::{network::dns, OsInputOutput};
1919

2020
pub type OnSigWinch = dyn Fn(Box<dyn Fn()>) + Send;
@@ -143,7 +143,7 @@ pub fn get_input(
143143
}
144144

145145
#[inline]
146-
#[cfg(target_os = "macos")]
146+
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
147147
fn eperm_message() -> &'static str {
148148
"Insufficient permissions to listen on network interface(s). Try running with sudo."
149149
}

0 commit comments

Comments
 (0)