pub struct Adapter { /* private fields */ }
Expand description
Wrapper around a https://git.zx2c4.com/wintun/about/#wintun_adapter_handle
Implementations§
source§impl Adapter
impl Adapter
sourcepub fn get_name(&self) -> Result<String, Error>
pub fn get_name(&self) -> Result<String, Error>
Returns the Friendly Name
of this adapter,
which is the human readable name shown in Windows
sourcepub fn set_name(&self, name: &str) -> Result<(), Error>
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.
pub fn get_guid(&self) -> u128
sourcepub fn create(
wintun: &Wintun,
name: &str,
tunnel_type: &str,
guid: Option<u128>
) -> Result<Arc<Adapter>, Error>
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
sourcepub fn open(wintun: &Wintun, name: &str) -> Result<Arc<Adapter>, Error>
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!
sourcepub fn start_session(self: &Arc<Self>, capacity: u32) -> Result<Session, Error>
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
.
sourcepub fn get_luid(&self) -> NET_LUID_LH
pub fn get_luid(&self) -> NET_LUID_LH
Returns the Win32 LUID for this adapter
sourcepub fn get_adapter_index(&self) -> Result<u32, Error>
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
sourcepub fn set_address(&self, address: Ipv4Addr) -> Result<(), Error>
pub fn set_address(&self, address: Ipv4Addr) -> Result<(), Error>
Sets the IP address for this adapter, using command netsh
.
sourcepub fn set_gateway(&self, gateway: Option<Ipv4Addr>) -> Result<(), Error>
pub fn set_gateway(&self, gateway: Option<Ipv4Addr>) -> Result<(), Error>
Sets the gateway for this adapter, using command netsh
.
sourcepub fn set_netmask(&self, mask: Ipv4Addr) -> Result<(), Error>
pub fn set_netmask(&self, mask: Ipv4Addr) -> Result<(), Error>
Sets the subnet mask for this adapter, using command netsh
.
sourcepub fn set_dns_servers(&self, dns_servers: &[IpAddr]) -> Result<(), Error>
pub fn set_dns_servers(&self, dns_servers: &[IpAddr]) -> Result<(), Error>
Sets the DNS servers for this adapter
sourcepub fn set_network_addresses_tuple(
&self,
address: IpAddr,
mask: IpAddr,
gateway: Option<IpAddr>
) -> Result<(), Error>
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
sourcepub fn get_addresses(&self) -> Result<Vec<IpAddr>, Error>
pub fn get_addresses(&self) -> Result<Vec<IpAddr>, Error>
Returns the IP addresses of this adapter, including IPv4 and IPv6 addresses