pub struct NetworkInterface { /* private fields */ }Expand description
A local network interface and the addresses assigned to it.
This is a snapshot taken when the value is created. It does not track addresses added or removed afterwards.
§Examples
use maestro_rs::NetworkInterface;
let eth0: NetworkInterface = "eth0".parse()?;
println!("{eth0}: {:?} {:?}", eth0.ipv4(), eth0.ipv6());
// Portable way to get the loopback interface:
let lo = NetworkInterface::loopback()?;Because it implements FromStr, it can be used directly as a
clap argument with value_parser!(NetworkInterface).
Implementations§
Source§impl NetworkInterface
impl NetworkInterface
Sourcepub fn from_name(name: &str) -> Result<Self>
pub fn from_name(name: &str) -> Result<Self>
Looks up an interface by its system name (e.g. "eth0", "lo0").
On Windows the friendly name shown in the control panel (e.g.
"Ethernet", matched case-insensitively) is accepted as well as the
system name (e.g. "ethernet_32768"). See alias.
§Errors
Error::InvalidInterfaceNameifnameis empty or contains a NUL byte.Error::InterfaceNotFoundif no such interface exists.Error::Ioif the system interface list cannot be read.
Sourcepub fn loopback() -> Result<Self>
pub fn loopback() -> Result<Self>
The first loopback interface: lo on Linux, lo0 on macOS and BSD,
loopback_0 on Windows.
§Errors
Error::InterfaceNotFoundif the system has no loopback interface.Error::Ioif the system interface list cannot be read.
Sourcepub fn addrs(&self) -> impl Iterator<Item = IpAddr> + '_
pub fn addrs(&self) -> impl Iterator<Item = IpAddr> + '_
All IPv4 then IPv6 addresses assigned to the interface.
Sourcepub fn mac(&self) -> Option<[u8; 6]>
pub fn mac(&self) -> Option<[u8; 6]>
The hardware (MAC) address, if the interface has one.
Loopback and tunnel interfaces typically have none.
Sourcepub fn alias(&self) -> Option<&str>
pub fn alias(&self) -> Option<&str>
The Windows friendly name (e.g. "Ethernet"). Always None on other platforms.
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Whether this is a loopback interface.