Struct Interface

Source
pub struct Interface(/* private fields */);
Expand description

Wrapped interface index.

Index is chosen, because basically all operating systems use index as an identifier. This struct can be used to manipulate interface parameters, such as IP address and MTU.

Implementations§

Source§

impl Interface

Source

pub fn add_address(&self, network: IpNet) -> Result<(), Error>

Add address to the interface

Source

pub fn remove_address(&self, network: IpNet) -> Result<(), Error>

Remove the specified address from the interface

Source

pub fn addresses(&self) -> Result<Vec<IpNet>, Error>

Returns list of IP addresses, assigned to this Interface

Source

pub fn mtu(&self) -> Result<u32, Error>

Source

pub fn set_mtu(&self, mtu: u32) -> Result<(), Error>

Source

pub fn name(&self) -> Result<String, Error>

Source

pub fn index(&self) -> Result<u32, Error>

Source

pub fn hwaddress(&self) -> Result<[u8; 6], Error>

Returns MAC address, assigned to this Interface

Source

pub unsafe fn from_index_unchecked(index: u32) -> Self

§Safety

The passed interface index must be valid

Source

pub fn try_from_index(index: u32) -> Result<Self, Error>

Returns InterfaceHandle from given interface index or Error if not found.

This method checks given index for validity and interface for presence. If you want to get InterfaceHandle without checking interface for presence, use from_index_unchecked.

Source

pub fn try_from_name(name: &str) -> Result<Self, Error>

Returns InterfaceHandle from given name or Error if not found.

On Windows it uses interface name, that is similar to ethernet_32774. If you want to search interface by human-readable name (like Ethernet 1), use try_from_alias

Trait Implementations§

Source§

impl Debug for Interface

Source§

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

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

impl InterfaceExt for Interface

Source§

fn set_up(&self, v: bool) -> Result<(), Error>

Source§

fn set_running(&self, v: bool) -> Result<(), Error>

Source§

fn set_hwaddress(&self, hwaddress: [u8; 6]) -> Result<(), Error>

Source§

fn set_packet_info(&self, v: bool) -> Result<(), Error>

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