1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::fmt;
use std::net;
use heim_common::prelude::*;
use crate::sys;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum Address {
Inet(net::SocketAddrV4),
Inet6(net::SocketAddrV6),
Link(macaddr::MacAddr),
}
pub struct Nic(sys::Nic);
wrap!(Nic, sys::Nic);
impl Nic {
pub fn name(&self) -> &str {
self.as_ref().name()
}
pub fn address(&self) -> Address {
self.as_ref().address()
}
pub fn netmask(&self) -> Option<Address> {
self.as_ref().netmask()
}
pub fn destination(&self) -> Option<Address> {
self.as_ref().destination()
}
pub fn is_up(&self) -> bool {
self.as_ref().is_up()
}
pub fn is_running(&self) -> bool {
self.as_ref().is_running()
}
pub fn is_loopback(&self) -> bool {
self.as_ref().is_loopback()
}
pub fn is_multicast(&self) -> bool {
self.as_ref().is_multicast()
}
}
impl fmt::Debug for Nic {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Nic")
.field("name", &self.name())
.field("address", &self.address())
.field("netmask", &self.netmask())
.field("destination", &self.destination())
.field("is_up", &self.is_up())
.field("is_loopback", &self.is_loopback())
.field("is_multicast", &self.is_multicast())
.finish()
}
}
pub async fn nic() -> Result<impl Stream<Item = Result<Nic>>> {
let inner = sys::nic().await?;
Ok(inner.map_ok(Into::into))
}