pub struct NetworkInterface {
pub name: String,
pub flags: InterfaceFlags,
pub gateways: Vec<IpAddr>,
pub addrs: Vec<InterfaceAddress>,
}Expand description
A single network interface on this host, with its flags, gateways, and addresses.
Fields§
§name: StringOS interface name (e.g. en0, eth0).
flags: InterfaceFlagsInterface-level flags.
gateways: Vec<IpAddr>Default-route gateways reachable through this interface, sorted and deduplicated.
addrs: Vec<InterfaceAddress>Addresses bound to this interface, sorted by preference and deduplicated.
Implementations§
Source§impl NetworkInterface
impl NetworkInterface
Sourcepub fn new(name: String, flags: InterfaceFlags) -> Self
pub fn new(name: String, flags: InterfaceFlags) -> Self
Make an empty NetworkInterface with the given name and flags.
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Loopback interface (lo/lo0)
Sourcepub fn is_point_to_point(&self) -> bool
pub fn is_point_to_point(&self) -> bool
Point-to-point link (PPP, tun, etc.)
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Interface is up and operational
Sourcepub fn is_clat(&self) -> bool
pub fn is_clat(&self) -> bool
CLAT (RFC 6877) virtual interface (e.g. Android clat4* / v4-*); local-only
Sourcepub fn add_address(&mut self, addr: InterfaceAddress)
pub fn add_address(&mut self, addr: InterfaceAddress)
Append an address to this interface; addresses are kept sorted and deduplicated
Sourcepub fn addresses(&self) -> &[InterfaceAddress]
pub fn addresses(&self) -> &[InterfaceAddress]
All addresses bound to this interface.
Sourcepub fn add_gateway(&mut self, gateway: IpAddr)
pub fn add_gateway(&mut self, gateway: IpAddr)
Append a gateway to this interface; gateways are kept sorted and deduplicated.
Sourcepub fn primary_ipv4(&self) -> Option<InterfaceAddress>
pub fn primary_ipv4(&self) -> Option<InterfaceAddress>
Most-preferred IPv4 address on this interface (per InterfaceAddress::cmp).
Sourcepub fn primary_ipv6(&self) -> Option<InterfaceAddress>
pub fn primary_ipv6(&self) -> Option<InterfaceAddress>
Most-preferred IPv6 address on this interface (per InterfaceAddress::cmp).
Trait Implementations§
Source§impl Clone for NetworkInterface
impl Clone for NetworkInterface
Source§fn clone(&self) -> NetworkInterface
fn clone(&self) -> NetworkInterface
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NetworkInterface
impl Debug for NetworkInterface
Source§impl<'de> Deserialize<'de> for NetworkInterface
impl<'de> Deserialize<'de> for NetworkInterface
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for NetworkInterface
Source§impl PartialEq for NetworkInterface
impl PartialEq for NetworkInterface
Source§impl Serialize for NetworkInterface
impl Serialize for NetworkInterface
impl StructuralPartialEq for NetworkInterface
Auto Trait Implementations§
impl Freeze for NetworkInterface
impl RefUnwindSafe for NetworkInterface
impl Send for NetworkInterface
impl Sync for NetworkInterface
impl Unpin for NetworkInterface
impl UnsafeUnpin for NetworkInterface
impl UnwindSafe for NetworkInterface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more