pub struct Tun { /* private fields */ }
wintun
only.Expand description
A cross-platform TUN interface, suitable for tunnelling network-layer packets.
Implementations§
Source§impl Tun
impl Tun
Sourcepub fn new_named(if_name: Interface) -> Result<Self>
pub fn new_named(if_name: Interface) -> Result<Self>
Opens or creates a TUN device of the given name.
Sourcepub fn set_state(&mut self, state: DeviceState) -> Result<()>
pub fn set_state(&mut self, state: DeviceState) -> Result<()>
Sets the adapter state of the TUN device (e.g. “up” or “down”).
Sourcepub fn mtu(&self) -> Result<usize>
pub fn mtu(&self) -> Result<usize>
Retrieves the Maximum Transmission Unit (MTU) of the TUN device.
Sourcepub fn set_nonblocking(&mut self, nonblocking: bool) -> Result<()>
pub fn set_nonblocking(&mut self, nonblocking: bool) -> Result<()>
Sets the blocking mode of the TUN device for reads/writes.
Sourcepub fn nonblocking(&self) -> Result<bool>
pub fn nonblocking(&self) -> Result<bool>
Retrieves the blocking mode of the TUN device.
Sourcepub fn addrs(&self) -> Result<Vec<AddressInfo>>
Available on non-Windows only.
pub fn addrs(&self) -> Result<Vec<AddressInfo>>
Retrieves the IP addresses assigned to the interface.
§Portability
In nearly all platforms, no addresses are automatically assigned to TUN interfaces. The
exception to this is OpenBSD, which automatically assigns a link-layer IPv6 address (in
addition to the specified IPv6 address) the first time an IPv6 address is assigned to a
TUN device. As such, portable applications should not rely on the assumption that the
only addresses returned from this method are those that were previously assigned via
add_addr()
.
Sourcepub fn add_addr<A: Into<AddAddress>>(&self, req: A) -> Result<()>
Available on non-Windows only.
pub fn add_addr<A: Into<AddAddress>>(&self, req: A) -> Result<()>
Assigns an IP address to the interface.
§Portability
MacOS, FreeBSD and DragonFlyBSD all require a destination address when assigning an IPv4 address to a TUN device. The destination address is optional for other platforms.
Most platforms automatically assign a link-local IPv6 address to a newly created TAP device. No platforms assign link-local IPv6 addresses to TUN devices on creation. However, OpenBSD will assign a link-local IPv6 address (in addition to the specified IPv6 address) the first time an IPv6 address is assigned to a TUN device.
Sourcepub fn remove_addr(&self, addr: IpAddr) -> Result<()>
Available on non-Windows only.
pub fn remove_addr(&self, addr: IpAddr) -> Result<()>
Removes the specified network-layer address from the interface.