Struct AsyncTun

Source
pub struct AsyncTun(/* private fields */);
Available on crate feature tokio only.
Expand description

Represents a non-blocking TUN device.

Implementations§

Source§

impl AsyncTun

Source

pub fn new(name: impl AsRef<str>, packet_info: bool) -> Result<Self>

Methods from Deref<Target = AsyncDevice>§

Source

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

Tries to read data from the device and fill the buffer buf.

§Arguments
  • buf: Buffer to be filled with the data read from the device.
§Returns
  • Ok: Containing the number of bytes read from the device.
  • Err: If the device was not ready to be read(a WOULDBLOCK err), or some other error occurred.
Source

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

Tries to write data from the buf to the device.

§Arguments
  • buf: Data to be written to the device.
§Returns
  • Ok: Containing the number of bytes written to the device.
  • Err: If the device was not ready to be written to(a WOULDBLOCK err), or some other error occurred.
Source

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

Asyncronously reads data from the device and writes to the buf.

§Arguments
  • buf: Buffer to be filled with the data read from the device.
§Returns
  • Ok: Containing the number of bytes read from the device.
  • Err: If reading data was unsuccessful.
Source

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

Asyncronously writes data from buf to the device.

§Arguments
  • buf: Buffer to be written to the device.
§Returns
  • Ok: Containing the number of bytes written from the device.
  • Err: If writting data was unsuccessful.

Methods from Deref<Target = Device>§

Source

pub fn name(&self) -> String

Returns The name of the device chosen by the kernel.

Source

pub fn flags(&self) -> Result<Flags>

Returns the active flags of the interface.

Source

pub fn bring_up(&self) -> Result<()>

Brings the device up which makes it ready to send and receive packets.

Source

pub fn bring_down(&self) -> Result<()>

Brings the device down which makes it unable to send and receive packets.

Source

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

Sets the MTU of the device.

Source

pub fn get_mtu(&self) -> Result<i32>

Returns the MTU of the device.

Source

pub fn set_netmask(&self, netmask: Ipv4Addr) -> Result<()>

Sets the netmask of the device.

Source

pub fn get_netmask(&self) -> Result<Ipv4Addr>

Sets the netmask of the device.

Source

pub fn get_index(&self) -> Result<i32>

Returns the index of the interface.

Source

pub fn set_ipv6_addr(&self, addr: Ipv6Addr) -> Result<()>

Adds the specified addr to the list of IPv6 addresses of the interface.

Source

pub fn get_ipv6_addrs(&self) -> Result<Vec<Ipv6Addr>>

Returns the list of IPv6 addresses of the interface.

Source

pub fn del_ipv6_addr(&self, addr: Ipv6Addr) -> Result<()>

Deletes the specified IPv6 address from the interface.

Source

pub fn set_addr(&self, addr: Ipv4Addr) -> Result<()>

Sets the IPv4 address of the device.

Source

pub fn get_addr(&self) -> Result<Ipv4Addr>

Returns the IPv4 address of the device.

Source

pub fn del_addr(&self) -> Result<()>

Deletes the IPv4 address of the interface.

Source

pub fn set_brd_addr(&self, addr: Ipv4Addr) -> Result<()>

Sets the broadcast IPv4 address of the device.

Source

pub fn get_brd_addr(&self) -> Result<Ipv4Addr>

Returns the broadcast IPv4 address of the device.

Source

pub fn set_dst_addr(&self, addr: Ipv4Addr) -> Result<()>

Sets the destination IPv4 address of the device.

Source

pub fn get_dst_addr(&self) -> Result<Ipv4Addr>

Returns the destination IPv4 address of the device.

Source

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

Writes the data in buf into the device.

Source

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

Reads the data from device into buf.

Trait Implementations§

Source§

impl Debug for AsyncTun

Source§

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

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

impl Deref for AsyncTun

Source§

type Target = AsyncDevice

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for AsyncTun

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.