Skip to main content

Interface

Struct Interface 

Source
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: u32

OS-assigned index of network interface. This is an integer which uniquely identifies the interface on this machine.

§name: String

System 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: InterfaceType

Interface 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: u32

Raw interface flags.

Bit meanings are platform-specific.

§oper_state: OperState

Operational 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: bool

Whether this interface was identified as the default route.

This field is available only with the gateway feature.

Implementations§

Source§

impl Interface

Source

pub fn default() -> Result<Interface, String>

Returns the interface currently selected as the system default route.

Source

pub fn dummy() -> Interface

Returns an empty placeholder interface.

This constructor is mainly useful for tests and internal assembly of interface data.

Source

pub fn is_up(&self) -> bool

Returns true when the interface has the OS UP flag set.

Source

pub fn is_loopback(&self) -> bool

Returns true when the interface is marked as loopback.

Source

pub fn is_point_to_point(&self) -> bool

Returns true when the interface is marked as point-to-point.

Source

pub fn is_multicast(&self) -> bool

Returns true when the interface supports multicast according to its flags.

Source

pub fn is_broadcast(&self) -> bool

Returns true when the interface supports broadcast according to its flags.

Source

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.

Source

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.

Source

pub fn is_physical(&self) -> bool

Returns true when the interface appears to be backed by physical hardware.

Source

pub fn oper_state(&self) -> OperState

Returns the cached operational state.

Source

pub fn is_oper_up(&self) -> bool

Returns true when Interface::oper_state is OperState::Up.

Source

pub fn update_oper_state(&mut self)

Refreshes Interface::oper_state from the operating system.

Source

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.

Source

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.

Source

pub fn ip_addrs(&self) -> Vec<IpAddr>

Returns all IPv4 and IPv6 host addresses assigned to this interface.

Source

pub fn has_ipv4(&self) -> bool

Returns true when at least one IPv4 address is present.

Source

pub fn has_ipv6(&self) -> bool

Returns true when at least one IPv6 address is present.

Source

pub fn has_global_ipv4(&self) -> bool

Returns true when at least one assigned IPv4 address appears globally routable.

Source

pub fn has_global_ipv6(&self) -> bool

Returns true when at least one assigned IPv6 address appears globally routable.

Source

pub fn has_global_ip(&self) -> bool

Returns true when at least one assigned IPv4 or IPv6 address appears globally routable.

Source

pub fn global_ipv4_addrs(&self) -> Vec<Ipv4Addr>

Returns IPv4 addresses that appear globally routable.

Source

pub fn global_ipv6_addrs(&self) -> Vec<Ipv6Addr>

Returns IPv6 addresses that appear globally routable.

Source

pub fn global_ip_addrs(&self) -> Vec<IpAddr>

Returns IPv4 and IPv6 addresses that appear globally routable.

Source

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.

Trait Implementations§

Source§

impl Clone for Interface

Source§

fn clone(&self) -> Interface

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Interface

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Interface

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Interface

Source§

fn eq(&self, other: &Interface) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Interface

Source§

impl StructuralPartialEq for Interface

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.