Struct Tap

Source
pub struct Tap { /* private fields */ }
Available on non-Windows only.
Expand description

A cross-platform TAP interface, suitable for tunnelling link-layer packets.

Implementations§

Source§

impl Tap

Source

pub fn new() -> Result<Self>

Creates a new, unique TUN device.

Source

pub fn new_named(if_name: Interface) -> Result<Self>

Opens or creates a TUN device of the given name.

Source

pub fn name(&self) -> Result<Interface>

Retrieves the interface name of the TUN device.

Source

pub fn set_state(&mut self, state: DeviceState) -> Result<()>

Sets the adapter state of the TAP device (e.g. “up” or “down”).

Source

pub fn set_up(&mut self) -> Result<()>

Sets the adapter state of the TAP device to “up”.

Source

pub fn set_down(&mut self) -> Result<()>

Sets the adapter state of the TAP device to “down”.

Source

pub fn mtu(&self) -> Result<usize>

Retrieves the Maximum Transmission Unit (MTU) of the TAP device.

Source

pub fn set_nonblocking(&mut self, nonblocking: bool) -> Result<()>

Sets the blocking mode of the TAP device for reads/writes.

Source

pub fn nonblocking(&self) -> Result<bool>

Retrieves the blocking mode of the TAP device.

Source

pub fn addrs(&self) -> Result<Vec<AddressInfo>>

Retrieves the network-layer addresses assigned to the interface.

Most platforms automatically assign a link-local IPv6 address to TAP devices on creation. Developers should take this into account and avoid the incorrect assumption that addrs() will return only the addresses they have assigned via add_addr().

Source

pub fn add_addr<A: Into<AddAddress>>(&self, req: A) -> Result<()>

Assigns a network-layer address to the interface.

Source

pub fn remove_addr(&self, addr: IpAddr) -> Result<()>

Removes the specified network-layer address from the interface.

Source

pub fn send(&self, buf: &[u8]) -> Result<usize>

Sends a packet out over the TAP device.

Source

pub fn recv(&self, buf: &mut [u8]) -> Result<usize>

Receives a packet over the TAP device.

Trait Implementations§

Source§

impl AsFd for Tap

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for Tap

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more

Auto Trait Implementations§

§

impl Freeze for Tap

§

impl RefUnwindSafe for Tap

§

impl Send for Tap

§

impl Sync for Tap

§

impl Unpin for Tap

§

impl UnwindSafe for Tap

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> AsSource for T
where T: AsFd,

Source§

fn source(&self) -> BorrowedFd<'_>

Returns the borrowed file descriptor.
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.