pub struct Link { /* private fields */ }Expand description
A network interface on this machine.
Built from the host’s interface table by from_netdev, or by hand in a test.
Implementations§
Source§impl Link
impl Link
Sourcepub fn new(name: impl Into<String>, index: u32) -> Self
pub fn new(name: impl Into<String>, index: u32) -> Self
A link with nothing on it but a name and a number.
The starting point for a test, or for a caller describing a link this machine cannot be asked about. Everything else is added through the builders below.
Sourcepub fn with_addresses(self, addresses: Vec<LinkAddress>) -> Self
pub fn with_addresses(self, addresses: Vec<LinkAddress>) -> Self
The addresses it holds.
Sourcepub fn with_link_up(self, up: bool) -> Self
pub fn with_link_up(self, up: bool) -> Self
Whether the operating system reports it as up.
Sourcepub fn with_addressing(self, addressing: Addressing) -> Self
pub fn with_addressing(self, addressing: Addressing) -> Self
How addresses on this link reach anything.
Sourcepub fn with_physical(self, physical: bool) -> Self
pub fn with_physical(self, physical: bool) -> Self
Whether there is real hardware behind it.
Sourcepub fn with_default_route(self, carries: bool) -> Self
pub fn with_default_route(self, carries: bool) -> Self
Whether this machine’s default route leaves by it.
Sourcepub fn with_gateway(self, has: bool) -> Self
pub fn with_gateway(self, has: bool) -> Self
Whether a router is configured on the link.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
What the interface is called here.
The platform’s name, which every other call in this crate is keyed by. On Windows it is the adapter’s GUID.
Sourcepub fn index(&self) -> u32
pub fn index(&self) -> u32
Its number in this kernel’s interface table.
Valid for this boot only, so nothing durable is keyed by it. See Zone.
Sourcepub fn mac(&self) -> Option<MacAddr>
pub fn mac(&self) -> Option<MacAddr>
The hardware address, where it has one.
None for a link with no link layer to have one on: a tunnel, and
loopback on most platforms.
Sourcepub fn addresses(&self) -> &[LinkAddress]
pub fn addresses(&self) -> &[LinkAddress]
Every address this link holds.
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Whether this is the machine talking to itself.
Sourcepub fn is_wireless(&self) -> bool
pub fn is_wireless(&self) -> bool
Whether it is 802.11.
Sourcepub fn is_physical(&self) -> bool
pub fn is_physical(&self) -> bool
Whether there is a physical port behind it.
False for a tunnel, a hypervisor’s virtual switch, and a VPN, none of which has a neighbour to ARP for.
Sourcepub fn is_broadcast(&self) -> bool
pub fn is_broadcast(&self) -> bool
Whether it can carry a broadcast.
Sourcepub fn is_point_to_point(&self) -> bool
pub fn is_point_to_point(&self) -> bool
Whether it is a point-to-point link, which has one peer and no segment.
Sourcepub fn carries_default_route(&self) -> bool
pub fn carries_default_route(&self) -> bool
Whether this machine’s default route leaves by this link.
The closest thing there is to “which network am I on”, answerable the
same way on every platform. Hardware fields cannot tell: macOS presents
awdl0 (AirDrop) and llw0 as ordinary wired Ethernet.
Sourcepub fn has_gateway(&self) -> bool
pub fn has_gateway(&self) -> bool
Whether a router is configured on this link. True of a real LAN, false of a host-only virtualisation bridge, which is what tells them apart when a VPN owns the global default route.
Sourcepub fn is_wired(&self) -> bool
pub fn is_wired(&self) -> bool
Whether it is a physical link that is not wireless.
The one to prefer when there is a choice: a wired segment answers faster and more consistently than 802.11.
Sourcepub fn carries_frames(&self) -> bool
pub fn carries_frames(&self) -> bool
Whether a link-layer probe can be put on it.
ARP and neighbour discovery need a segment with somebody else on it and a hardware address to send from. A point-to-point link has a peer and no segment, loopback has neither, and a link with no hardware address has nothing to put in the frame.
Trait Implementations§
impl Eq for Link
impl StructuralPartialEq for Link
Auto Trait Implementations§
impl Freeze for Link
impl RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnsafeUnpin for Link
impl UnwindSafe for Link
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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