Struct tun_rs::platform::linux::Device

source ·
pub struct Device { /* private fields */ }
Expand description

A TUN device using the TUN/TAP Linux driver.

Implementations§

source§

impl Device

source

pub fn from_fd(fd: RawFd) -> Result<Self>

source

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

Set non-blocking mode

source

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

Recv a packet from tun device

source

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

Send a packet to tun device

source

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

Available on crate feature experimental only.

Do not use nonblocking fd when you want to use shutdown

source§

impl Device

source

pub fn new(config: &Configuration) -> Result<Self>

Create a new Device for the given Configuration.

source

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

Make the device persistent.

source

pub fn user(&self, value: i32) -> Result<()>

Set the owner of the device.

source

pub fn group(&self, value: i32) -> Result<()>

Set the group of the device.

Trait Implementations§

source§

impl AbstractDevice for Device

source§

fn name(&self) -> Result<String>

Get the device tun name.
source§

fn set_name(&self, value: &str) -> Result<()>

Set the device tun name.
source§

fn enabled(&self, value: bool) -> Result<()>

Turn on or off the interface.
source§

fn address(&self) -> Result<IpAddr>

Get the address.
source§

fn destination(&self) -> Result<IpAddr>

Get the destination address.
source§

fn broadcast(&self) -> Result<IpAddr>

Get the broadcast address.
source§

fn set_broadcast<A: IntoAddress>(&self, value: A) -> Result<()>

Set the broadcast address.
source§

fn netmask(&self) -> Result<IpAddr>

Get the netmask.
source§

fn set_network_address<A: IntoAddress>( &self, address: A, netmask: A, destination: Option<A>, ) -> Result<()>

Sets the network addresses of this adapter, including network address, subnet mask, and gateway
source§

fn mtu(&self) -> Result<u16>

Get the MTU.
source§

fn set_mtu(&self, value: u16) -> Result<()>

Set the MTU.
source§

fn set_mac_address(&self, eth_addr: [u8; 6]) -> Result<()>

Set mac address
source§

fn get_mac_address(&self) -> Result<[u8; 6]>

Get mac address
source§

impl AsRawFd for Device

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl FromRawFd for Device

source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
source§

impl IntoRawFd for Device

source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations§

§

impl !Freeze for Device

§

impl RefUnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl UnwindSafe for Device

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.