Struct wintun::Adapter

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

Implementations§

source§

impl Adapter

source

pub fn get_name(&self) -> Result<String, Error>

Returns the Friendly Name of this adapter, which is the human readable name shown in Windows

source

pub fn set_name(&self, name: &str) -> Result<(), Error>

Sets the Friendly Name of this adapter, which is the human readable name shown in Windows

Note: This is different from Adapter Name, which is a GUID.

source

pub fn get_guid(&self) -> u128

source

pub fn create( wintun: &Wintun, name: &str, tunnel_type: &str, guid: Option<u128> ) -> Result<Arc<Adapter>, Error>

Creates a new wintun adapter inside the name name with tunnel type tunnel_type

Optionally a GUID can be specified that will become the GUID of this adapter once created. Adapters obtained via this function will be able to return their adapter index via Adapter::get_adapter_index

source

pub fn open(wintun: &Wintun, name: &str) -> Result<Arc<Adapter>, Error>

Attempts to open an existing wintun interface name name.

Adapters opened via this call will have an unknown GUID meaning Adapter::get_adapter_index will always fail because knowing the adapter’s GUID is required to determine its index. Currently a workaround is to delete and re-create a new adapter every time one is needed so that it gets created with a known GUID, allowing Adapter::get_adapter_index to works as expected. There is likely a way to get the GUID of our adapter using the Windows Registry or via the Win32 API, so PR’s that solve this issue are always welcome!

source

pub fn delete(self) -> Result<(), Error>

Delete an adapter, consuming it in the process

source

pub fn start_session(self: &Arc<Self>, capacity: u32) -> Result<Session, Error>

Initiates a new wintun session on the given adapter.

Capacity is the size in bytes of the ring buffer used internally by the driver. Must be a power of two between crate::MIN_RING_CAPACITY and crate::MIN_RING_CAPACITY.

source

pub fn get_luid(&self) -> NET_LUID_LH

Returns the Win32 LUID for this adapter

source

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

Set MTU of this adapter

source

pub fn get_mtu(&self) -> Result<usize, Error>

Returns MTU of this adapter

source

pub fn get_adapter_index(&self) -> Result<u32, Error>

Returns the Win32 interface index of this adapter. Useful for specifying the interface when executing netsh interface ip commands

source

pub fn set_address(&self, address: Ipv4Addr) -> Result<(), Error>

Sets the IP address for this adapter, using command netsh.

source

pub fn set_gateway(&self, gateway: Option<Ipv4Addr>) -> Result<(), Error>

Sets the gateway for this adapter, using command netsh.

source

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

Sets the subnet mask for this adapter, using command netsh.

source

pub fn set_dns_servers(&self, dns_servers: &[IpAddr]) -> Result<(), Error>

Sets the DNS servers for this adapter

source

pub fn set_network_addresses_tuple( &self, address: IpAddr, mask: IpAddr, gateway: Option<IpAddr> ) -> Result<(), Error>

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

source

pub fn get_addresses(&self) -> Result<Vec<IpAddr>, Error>

Returns the IP addresses of this adapter, including IPv4 and IPv6 addresses

source

pub fn get_gateways(&self) -> Result<Vec<IpAddr>, Error>

Returns the gateway addresses of this adapter, including IPv4 and IPv6 addresses

source

pub fn get_netmask_of_address( &self, target_address: &IpAddr ) -> Result<IpAddr, Error>

Returns the subnet mask of the given address

Trait Implementations§

source§

impl Drop for Adapter

source§

fn drop(&mut self)

Executes the destructor for this type. 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>,

§

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>,

§

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.