pub struct Interface {Show 19 fields
pub index: u32,
pub name: String,
pub friendly_name: Option<String>,
pub description: Option<String>,
pub if_type: InterfaceType,
pub mac_addr: Option<MacAddr>,
pub ipv4: Vec<Ipv4Net>,
pub ipv6: Vec<Ipv6Net>,
pub ipv6_scope_ids: Vec<u32>,
pub ipv6_addr_flags: Vec<Ipv6AddrFlags>,
pub flags: u32,
pub oper_state: OperState,
pub transmit_speed: Option<u64>,
pub receive_speed: Option<u64>,
pub stats: Option<InterfaceStats>,
pub gateway: Option<NetworkDevice>,
pub dns_servers: Vec<IpAddr>,
pub mtu: Option<u32>,
pub default: bool,
}Expand description
A network interface.
Values are collected from platform-specific system APIs. Some metadata is optional.
Fields§
§index: u32OS-assigned index of network interface. This is an integer which uniquely identifies the interface on this machine.
name: StringSystem name of the interface.
On Unix-like systems this is usually a BSD or kernel name such as eth0, en0, or
wlan0. On Windows this is the adapter name GUID string.
friendly_name: Option<String>Human-readable interface name, when the platform provides one.
Examples include Wi-Fi or Ethernet on Windows and display names on macOS.
This field is commonly None on Linux, Android, iOS, and BSD systems.
description: Option<String>Adapter description, when the platform provides one.
On Windows this is usually the adapter model or driver description.
This field is generally None on non-Windows platforms.
if_type: InterfaceTypeInterface classification.
The value is derived from platform-specific type identifiers and may be
InterfaceType::Unknown when the OS does not expose a recognizable type.
mac_addr: Option<MacAddr>Link-layer address of the interface, when available.
This field may be None for interfaces without a MAC address, for virtual interfaces,
or on platforms that do not expose the address through the available APIs.
ipv4: Vec<Ipv4Net>IPv4 addresses assigned to the interface, including prefix length.
The vector is empty when the interface has no IPv4 addresses or when they could not be read.
ipv6: Vec<Ipv6Net>IPv6 addresses assigned to the interface, including prefix length.
The vector is empty when the interface has no IPv6 addresses or when they could not be read.
ipv6_scope_ids: Vec<u32>IPv6 scope IDs aligned with entries in Interface::ipv6.
Scope IDs are primarily relevant for link-local IPv6 addresses and may also be called
zone indexes. A value can be 0 when no scope is needed or when the platform did not
provide one.
ipv6_addr_flags: Vec<Ipv6AddrFlags>Per-address IPv6 flags, aligned with entries in Interface::ipv6.
flags: u32Raw interface flags.
Bit meanings are platform-specific.
oper_state: OperStateOperational state at the time the interface snapshot was collected.
transmit_speed: Option<u64>Transmit link speed in bits per second.
This field is usually available on Linux, Android, and Windows.
It may be None for virtual adapters, unsupported drivers, or platforms that do not
expose link speed.
receive_speed: Option<u64>Reported receive link speed in bits per second.
This field follows the same availability rules as Interface::transmit_speed.
stats: Option<InterfaceStats>Traffic counters captured when the interface snapshot was collected.
The counters are cumulative totals reported by the OS, typically since boot.
This field may be None when the current platform or adapter does not expose statistics.
Use Interface::update_stats to refresh the snapshot in place.
gateway: Option<NetworkDevice>Default gateway associated with this interface, when known.
This field is available only with the gateway feature. It may be None when the
interface is not the default route, when the gateway has no link-layer address available,
or when the platform cannot resolve gateway information.
dns_servers: Vec<IpAddr>DNS resolver addresses associated with this interface.
This field is available only with the gateway feature.
mtu: Option<u32>Maximum transmission unit in bytes, when available.
This field may be None when the platform API does not provide the MTU or the lookup fails.
default: boolWhether this interface was identified as the default route.
This field is available only with the gateway feature.
Implementations§
Source§impl Interface
impl Interface
Sourcepub fn default() -> Result<Interface, String>
pub fn default() -> Result<Interface, String>
Returns the interface currently selected as the system default route.
Sourcepub fn dummy() -> Interface
pub fn dummy() -> Interface
Returns an empty placeholder interface.
This constructor is mainly useful for tests and internal assembly of interface data.
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Returns true when the interface is marked as loopback.
Sourcepub fn is_point_to_point(&self) -> bool
pub fn is_point_to_point(&self) -> bool
Returns true when the interface is marked as point-to-point.
Sourcepub fn is_multicast(&self) -> bool
pub fn is_multicast(&self) -> bool
Returns true when the interface supports multicast according to its flags.
Sourcepub fn is_broadcast(&self) -> bool
pub fn is_broadcast(&self) -> bool
Returns true when the interface supports broadcast according to its flags.
Sourcepub fn is_tun(&self) -> bool
pub fn is_tun(&self) -> bool
Returns true for interfaces that look like TUN-style point-to-point devices.
This is a heuristic based on interface flags and is not guaranteed to identify every virtual tunnel interface on every platform.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true when the platform reports the interface as able to pass traffic.
The exact definition depends on the operating system.
Sourcepub fn is_physical(&self) -> bool
pub fn is_physical(&self) -> bool
Returns true when the interface appears to be backed by physical hardware.
Sourcepub fn oper_state(&self) -> OperState
pub fn oper_state(&self) -> OperState
Returns the cached operational state.
Sourcepub fn is_oper_up(&self) -> bool
pub fn is_oper_up(&self) -> bool
Returns true when Interface::oper_state is OperState::Up.
Sourcepub fn update_oper_state(&mut self)
pub fn update_oper_state(&mut self)
Refreshes Interface::oper_state from the operating system.
Sourcepub fn ipv4_addrs(&self) -> Vec<Ipv4Addr>
pub fn ipv4_addrs(&self) -> Vec<Ipv4Addr>
Returns the IPv4 addresses assigned to this interface.
Prefix lengths are discarded. Use Interface::ipv4 when the network prefix is needed.
Sourcepub fn ipv6_addrs(&self) -> Vec<Ipv6Addr>
pub fn ipv6_addrs(&self) -> Vec<Ipv6Addr>
Returns the IPv6 host addresses assigned to this interface.
Prefix lengths are discarded. Use Interface::ipv6 when the network prefix is needed.
Sourcepub fn ip_addrs(&self) -> Vec<IpAddr>
pub fn ip_addrs(&self) -> Vec<IpAddr>
Returns all IPv4 and IPv6 host addresses assigned to this interface.
Sourcepub fn has_global_ipv4(&self) -> bool
pub fn has_global_ipv4(&self) -> bool
Returns true when at least one assigned IPv4 address appears globally routable.
Sourcepub fn has_global_ipv6(&self) -> bool
pub fn has_global_ipv6(&self) -> bool
Returns true when at least one assigned IPv6 address appears globally routable.
Sourcepub fn has_global_ip(&self) -> bool
pub fn has_global_ip(&self) -> bool
Returns true when at least one assigned IPv4 or IPv6 address appears globally routable.
Sourcepub fn global_ipv4_addrs(&self) -> Vec<Ipv4Addr>
pub fn global_ipv4_addrs(&self) -> Vec<Ipv4Addr>
Returns IPv4 addresses that appear globally routable.
Sourcepub fn global_ipv6_addrs(&self) -> Vec<Ipv6Addr>
pub fn global_ipv6_addrs(&self) -> Vec<Ipv6Addr>
Returns IPv6 addresses that appear globally routable.
Sourcepub fn global_ip_addrs(&self) -> Vec<IpAddr>
pub fn global_ip_addrs(&self) -> Vec<IpAddr>
Returns IPv4 and IPv6 addresses that appear globally routable.
Sourcepub fn update_stats(&mut self) -> Result<()>
pub fn update_stats(&mut self) -> Result<()>
Refreshes Interface::stats for this interface.
On supported platforms this updates the byte counters and timestamp with a new snapshot.