1#[cfg(target_os = "linux")]
2pub mod linux;
3#[cfg(target_os = "macos")]
4pub mod macos;
5#[cfg(target_os = "windows")]
6pub mod windows;
7
8use anyhow::Result;
9use std::collections::HashMap;
10
11#[derive(Debug, Clone)]
12pub struct InterfaceStats {
13 #[allow(dead_code)]
14 pub name: String,
15 pub rx_bytes: u64,
16 pub tx_bytes: u64,
17 pub rx_packets: u64,
18 pub tx_packets: u64,
19 pub rx_errors: u64,
20 pub tx_errors: u64,
21 pub rx_drops: u64,
22 pub tx_drops: u64,
23}
24
25#[derive(Debug, Clone)]
26pub struct InterfaceInfo {
27 pub name: String,
28 pub ipv4: Option<String>,
29 pub ipv6: Option<String>,
30 pub mac: Option<String>,
31 pub mtu: Option<u32>,
32 pub is_up: bool,
33}
34
35pub fn collect_interface_stats() -> Result<HashMap<String, InterfaceStats>> {
36 #[cfg(target_os = "linux")]
37 return linux::collect_interface_stats();
38
39 #[cfg(target_os = "macos")]
40 return macos::collect_interface_stats();
41
42 #[cfg(target_os = "windows")]
43 return windows::collect_interface_stats();
44
45 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
46 anyhow::bail!("Unsupported platform")
47}
48
49pub fn collect_interface_info() -> Result<Vec<InterfaceInfo>> {
50 #[cfg(target_os = "linux")]
51 return linux::collect_interface_info();
52
53 #[cfg(target_os = "macos")]
54 return macos::collect_interface_info();
55
56 #[cfg(target_os = "windows")]
57 return windows::collect_interface_info();
58
59 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
60 anyhow::bail!("Unsupported platform")
61}