macos_routing_table/
lib.rs

1mod route_entry;
2mod routing_flag;
3mod routing_table;
4
5use std::fmt::Write;
6
7pub use routing_table::execute_netstat;
8
9// Exports
10pub use route_entry::RouteEntry;
11pub use routing_flag::RoutingFlag;
12pub use routing_table::RoutingTable;
13
14use cidr::AnyIpCidr;
15use mac_address::MacAddress;
16
17/// A generic network entity
18#[derive(Debug, Clone)]
19pub enum Entity {
20    Default,
21    Cidr(AnyIpCidr),
22    Link(String),
23    Mac(MacAddress),
24}
25
26impl std::fmt::Display for Entity {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Entity::Default => f.write_str("default"),
30            Entity::Cidr(cidr) => write!(f, "{cidr}"),
31            Entity::Link(link) => f.write_str(link),
32            Entity::Mac(mac) => {
33                for (i, byte) in mac.bytes().iter().enumerate() {
34                    if i > 0 {
35                        f.write_char(':')?;
36                    }
37                    write!(f, "{byte:02x}")?;
38                }
39                Ok(())
40            }
41        }
42    }
43}
44
45/// A destination entity with an optional zone
46#[derive(Clone, Debug)]
47pub struct Destination {
48    pub entity: crate::Entity,
49    pub zone: Option<String>,
50}
51
52impl std::fmt::Display for Destination {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        let Destination { entity, zone } = self;
55        write!(f, "{entity}")?;
56        if let Some(zone) = &zone {
57            write!(f, "%{zone}")?;
58        }
59
60        Ok(())
61    }
62}
63
64/// Internet Protocols associated with routing table entries
65#[derive(Debug, Clone, Copy)]
66pub enum Protocol {
67    V4,
68    V6,
69}