xarxa

Crates

git

Versions

default

Flavors

Skip to main content

TunTapDriver

Struct TunTapDriver 

Source
pub struct TunTapDriver { /* private fields */ }
Expand description

A driver for a virtual TUN (IP) or TAP (Ethernet) interface.

Implementations§

Source§

impl TunTapDriver

Source

pub fn new(name: &str, hardware_addr: HardwareAddress) -> Result<TunTapDriver>

Attaches to a TUN/TAP interface called name, or creates it if it does not exist.

hardware_addr is the address the interface reports to the stack, and picks the medium: HardwareAddress::Ip opens a TUN interface, an Ethernet address opens a TAP one.

If name is a persistent interface configured with UID of the current user, no special privileges are needed. Otherwise, this requires superuser privileges or a corresponding capability set on the executable.

Source

pub fn from_fd( fd: RawFd, hardware_addr: HardwareAddress, mtu: usize, ) -> Result<TunTapDriver>

Attaches to a TUN/TAP interface specified by file descriptor fd.

On platforms like Android, a file descriptor to a tun interface is exposed. On these platforms, a TunTapDriver cannot be instantiated with a name.

hardware_addr is the address the interface reports to the stack, and picks the medium, as in new.

Trait Implementations§

Source§

impl AsRawFd for TunTapDriver

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for TunTapDriver

Source§

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

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

impl Driver for TunTapDriver

Source§

fn capabilities(&self) -> Capabilities

Get a description of the device’s capabilities.
Source§

fn hardware_address(&self) -> HardwareAddress

Get the device’s hardware address. Read more
Source§

fn receive(&mut self) -> Option<PacketBuf>

Poll for a received frame. Read more
Source§

fn transmit(&mut self, buf: PacketBuf) -> Result<(), PacketBuf>

Queue a frame for transmission, transferring ownership of the buffer to the driver. Read more
Source§

fn can_transmit(&mut self) -> bool

Whether the device can transmit one frame right now. Read more
Get the link state. Read more
Source§

fn poll_tx_timestamp(&mut self) -> Option<TxTimestamp>

Poll for the timestamp of an already-transmitted packet. Read more
Source§

impl Drop for TunTapDriver

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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 = !

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.