1mod platform;
2mod types;
3
4use std::net::IpAddr;
5
6use mac_address::MacAddress;
7
8use crate::error::Result;
9
10pub use types::{ArpEntry, InterfaceInfo};
11
12pub struct NetworkManager;
13
14impl NetworkManager {
15 pub fn find_mac(ip: &IpAddr) -> Option<ArpEntry> {
16 let table = Self::get_arp_table().ok()?;
17 table.into_iter().find(|e| &e.ip == ip)
18 }
19
20 pub fn get_interfaces() -> Vec<InterfaceInfo> {
21 platform::get_interfaces()
22 }
23
24 pub fn get_arp_table() -> Result<Vec<ArpEntry>> {
25 platform::get_arp_table()
26 }
27
28 pub fn add_entry(ip: IpAddr, mac: MacAddress) -> Result<()> {
29 platform::add_entry(ip, mac)
30 }
31
32 pub fn delete_entry(ip: IpAddr) -> Result<()> {
33 platform::delete_entry(ip)
34 }
35
36 pub fn clear_table() -> Result<()> {
37 platform::clear_table()
38 }
39}