1use std::fmt;
2use std::net;
3
4use heim_common::prelude::*;
5
6use crate::sys;
7
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
10pub enum Address {
11 Inet(net::SocketAddr),
13
14 Inet6(net::SocketAddr),
16
17 Link(macaddr::MacAddr),
19
20 #[doc(hidden)]
21 __Nonexhaustive,
22}
23
24pub struct Nic(sys::Nic);
31
32wrap!(Nic, sys::Nic);
33
34impl Nic {
35 pub fn name(&self) -> &str {
37 self.as_ref().name()
38 }
39
40 pub fn address(&self) -> Address {
42 self.as_ref().address()
43 }
44
45 pub fn netmask(&self) -> Option<Address> {
47 self.as_ref().netmask()
48 }
49
50 pub fn destination(&self) -> Option<Address> {
52 self.as_ref().destination()
53 }
54
55 pub fn is_up(&self) -> bool {
57 self.as_ref().is_up()
58 }
59
60 pub fn is_loopback(&self) -> bool {
62 self.as_ref().is_loopback()
63 }
64
65 pub fn is_multicast(&self) -> bool {
67 self.as_ref().is_multicast()
68 }
69}
70
71impl fmt::Debug for Nic {
72 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73 f.debug_struct("Nic")
74 .field("name", &self.name())
75 .field("address", &self.address())
76 .field("netmask", &self.netmask())
77 .field("destination", &self.destination())
78 .field("is_up", &self.is_up())
79 .field("is_loopback", &self.is_loopback())
80 .field("is_multicast", &self.is_multicast())
81 .finish()
82 }
83}
84
85pub fn nic() -> impl Stream<Item = Result<Nic>> {
89 sys::nic().map_ok(Into::into)
90}