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 has_elevated_access() -> bool {
48 #[cfg(target_os = "macos")]
49 {
50 macos::has_elevated_access()
51 }
52 #[cfg(target_os = "linux")]
53 {
54 linux::has_elevated_access()
55 }
56 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
57 {
58 false
59 }
60}
61
62pub fn scan_ports_with_sudo(password: &str) -> Result<Vec<PortEntry>> {
64 #[cfg(target_os = "macos")]
65 {
66 macos::scan_with_sudo(password)
67 }
68 #[cfg(target_os = "linux")]
69 {
70 linux::scan_with_sudo(password)
71 }
72 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
73 {
74 let _ = password;
75 anyhow::bail!("unsupported platform")
76 }
77}