Skip to content

Commit

Permalink
add ablility to set device GUID for wintun
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Dec 6, 2023
1 parent 9d6c749 commit 9935102
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/ping-tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

#[cfg(target_os = "windows")]
config.platform(|config| {
config.initialize();
config.initialize(Some(9099482345783245345345_u128));
});

let dev = tun::create_as_async(&config)?;
Expand Down
3 changes: 1 addition & 2 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ pub struct Device {

impl Device {
/// Create a new `Device` for the given `Configuration`.
pub fn new(config: &Configuration) -> Result<Self> {
pub fn new(config: &Configuration, guid: Option<u128>) -> Result<Self> {
let wintun = unsafe { wintun::load()? };
let tun_name = config.name.as_deref().unwrap_or("wintun");
let guid = Some(9099482345783245345345_u128);
let adapter = match wintun::Adapter::open(&wintun, tun_name) {
Ok(a) => a,
Err(_) => wintun::Adapter::create(&wintun, tun_name, tun_name, guid)?,
Expand Down
10 changes: 7 additions & 3 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ use crate::error::*;

/// Windows-only interface configuration.
#[derive(Copy, Clone, Default, Debug)]
pub struct Configuration {}
pub struct Configuration {
pub(crate) device_guid: Option<u128>,
}

impl Configuration {
pub fn initialize(&mut self) {
pub fn initialize(&mut self, device_guid: Option<u128>) {
log::trace!("Windows configuration initialize");
self.device_guid = device_guid;
}
}

/// Create a TUN device with the given name.
pub fn create(configuration: &C) -> Result<Device> {
Device::new(configuration)
let guid = configuration.platform.device_guid;
Device::new(configuration, guid)
}

0 comments on commit 9935102

Please sign in to comment.