Struct net_route::Route

source ·
pub struct Route {
    pub destination: IpAddr,
    pub prefix: u8,
    pub gateway: Option<IpAddr>,
    pub ifindex: Option<u32>,
    pub table: u8,
    pub source: Option<IpAddr>,
    pub source_prefix: u8,
    pub source_hint: Option<IpAddr>,
    pub metric: Option<u32>,
}
Expand description

Contains information that describes a route in the local computer’s Ipv4 or Ipv6 routing table.

Fields§

§destination: IpAddr

Network address of the destination. 0.0.0.0 with a prefix of 0 is considered a default route.

§prefix: u8

Length of network prefix in the destination address.

§gateway: Option<IpAddr>

The address of the next hop of this route.

On macOS, this must be Some if ifindex is None

§ifindex: Option<u32>

The index of the local interface through which the next hop of this route may be reached.

On macOS, this must be Some if gateway is None

§table: u8

The routing table this route belongs to.

§source: Option<IpAddr>

Network address of the source.

§source_prefix: u8

Prefix length of the source address.

§source_hint: Option<IpAddr>

Source address hint. Does not influence routing.

§metric: Option<u32>

The route metric offset value for this route.

Implementations§

source§

impl Route

source

pub fn new(destination: IpAddr, prefix: u8) -> Self

Create a route that matches a given destination network.

Either the gateway or interface should be set before attempting to add to a routing table.

source

pub fn with_gateway(self, gateway: IpAddr) -> Self

Set the next next hop gateway for this route.

source

pub fn with_ifindex(self, ifindex: u32) -> Self

Set the index of the local interface through which the next hop of this route should be reached.

source

pub fn with_table(self, table: u8) -> Self

Set table the route will be installed in.

source

pub fn with_source(self, source: IpAddr, prefix: u8) -> Self

Set source.

source

pub fn with_source_hint(self, hint: IpAddr) -> Self

Set source hint.

source

pub fn with_metric(self, metric: u32) -> Self

Set route metric.

source

pub fn mask(&self) -> IpAddr

Get the netmask covering the network portion of the destination address.

Trait Implementations§

source§

impl Clone for Route

source§

fn clone(&self) -> Route

Returns a copy 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 Route

source§

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

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

impl PartialEq for Route

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Route

source§

impl StructuralPartialEq for Route

Auto Trait Implementations§

§

impl RefUnwindSafe for Route

§

impl Send for Route

§

impl Sync for Route

§

impl Unpin for Route

§

impl UnwindSafe for Route

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> 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,

§

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>,

§

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>,

§

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.