Skip to main content

Link

Struct Link 

Source
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

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.

Source

pub fn with_mac(self, mac: MacAddr) -> Self

The hardware address this link answers at.

Source

pub fn with_addresses(self, addresses: Vec<LinkAddress>) -> Self

The addresses it holds.

Source

pub fn with_kind(self, kind: LinkKind) -> Self

What kind of link it is.

Whether the operating system reports it as up.

Source

pub fn with_addressing(self, addressing: Addressing) -> Self

How addresses on this link reach anything.

Source

pub fn with_physical(self, physical: bool) -> Self

Whether there is real hardware behind it.

Source

pub fn with_default_route(self, carries: bool) -> Self

Whether this machine’s default route leaves by it.

Source

pub fn with_gateway(self, has: bool) -> Self

Whether a router is configured on the link.

Source

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.

Source

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.

Source

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.

Source

pub fn addresses(&self) -> &[LinkAddress]

Every address this link holds.

Source

pub fn ipv4(&self) -> impl Iterator<Item = (Ipv4Addr, u8)> + '_

The IPv4 addresses among them.

Source

pub fn ipv6(&self) -> impl Iterator<Item = (Ipv6Addr, u8)> + '_

The IPv6 addresses among them.

Source

pub fn zone(&self) -> Zone

This link as a zone, for scoping a link-local address to it.

Source

pub fn kind(&self) -> LinkKind

What kind of link it is.

Source

pub fn is_up(&self) -> bool

Whether the operating system reports it as up.

Source

pub fn is_loopback(&self) -> bool

Whether this is the machine talking to itself.

Source

pub fn is_wireless(&self) -> bool

Whether it is 802.11.

Source

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.

Source

pub fn is_broadcast(&self) -> bool

Whether it can carry a broadcast.

Source

pub fn is_point_to_point(&self) -> bool

Whether it is a point-to-point link, which has one peer and no segment.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

Formats the value using the given formatter. Read more
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§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more