use std::fmt;
use std::net;
use heim_common::prelude::*;
use crate::sys;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Address {
Inet(net::SocketAddr),
Inet6(net::SocketAddr),
Link(macaddr::MacAddr),
#[doc(hidden)]
__Nonexhaustive,
}
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_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 fn nic() -> impl Stream<Item = Result<Nic>> {
sys::nic().map_ok(Into::into)
}