1#[cfg(target_os = "linux")]
7mod linux;
8#[cfg(target_os = "macos")]
9mod macos;
10
11use crate::model::PortEntry;
12use anyhow::Result;
13
14pub fn scan_ports() -> Result<Vec<PortEntry>> {
16 #[cfg(target_os = "linux")]
17 {
18 linux::scan()
19 }
20 #[cfg(target_os = "macos")]
21 {
22 macos::scan()
23 }
24 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
25 {
26 anyhow::bail!("unsupported platform")
27 }
28}
29
30pub fn scan_ports_elevated() -> Result<Vec<PortEntry>> {
32 #[cfg(target_os = "macos")]
33 {
34 macos::scan_elevated()
35 }
36 #[cfg(target_os = "linux")]
37 {
38 linux::scan()
39 }
40 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
41 {
42 anyhow::bail!("unsupported platform")
43 }
44}
45
46pub fn scan_ports_with_sudo(password: &str) -> Result<Vec<PortEntry>> {
48 #[cfg(target_os = "macos")]
49 {
50 macos::scan_with_sudo(password)
51 }
52 #[cfg(target_os = "linux")]
53 {
54 let _ = password;
55 linux::scan()
56 }
57 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
58 {
59 let _ = password;
60 anyhow::bail!("unsupported platform")
61 }
62}