Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Refine windows platform configuration (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
cavivie authored Jun 14, 2024
1 parent f9f59f6 commit 78985e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub struct Device {
impl Device {
/// Create a new `Device` for the given `Configuration`.
pub fn new(config: &Configuration) -> Result<Self> {
let wintun_path = &config.platform_config.wintun_path;
let wintun_file = &config.platform_config.wintun_file;
let wintun = unsafe {
let wintun = libloading::Library::new(wintun_path)?;
let wintun = libloading::Library::new(wintun_file)?;
wintun::load_from_library(wintun)?
};
let tun_name = config.tun_name.as_deref().unwrap_or("wintun");
Expand Down
21 changes: 11 additions & 10 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@

mod device;

use std::net::IpAddr;

pub use device::{Device, Tun};

use crate::configuration::Configuration;
use crate::error::Result;
pub use device::{Device, Tun};
use std::ffi::OsString;
use std::net::IpAddr;

/// Windows-only interface configuration.
#[derive(Clone, Debug)]
pub struct PlatformConfig {
pub(crate) device_guid: Option<u128>,
pub(crate) wintun_path: String,
pub(crate) wintun_file: OsString,
pub(crate) dns_servers: Option<Vec<IpAddr>>,
}

impl Default for PlatformConfig {
fn default() -> Self {
Self {
device_guid: None,
wintun_path: "wintun".to_string(),
wintun_file: "wintun.dll".into(),
dns_servers: None,
}
}
Expand All @@ -50,12 +49,14 @@ impl PlatformConfig {
/// Use a custom path to the wintun.dll instead of looking in the working directory.
/// Security note: It is up to the caller to ensure that the library can be safely loaded from
/// the indicated path.
pub fn custom_wintun_path(&mut self, wintun_path: &str) {
self.wintun_path = wintun_path.to_string();
///
/// [`wintun_file`](PlatformConfig::wintun_file) likes "path/to/wintun" or "path/to/wintun.dll".
pub fn wintun_file<S: Into<OsString>>(&mut self, wintun_file: S) {
self.wintun_file = wintun_file.into();
}

pub fn dns_servers(&mut self, dns_servers: Option<Vec<IpAddr>>) {
self.dns_servers = dns_servers;
pub fn dns_servers(&mut self, dns_servers: &[IpAddr]) {
self.dns_servers = Some(dns_servers.to_vec());
}
}

Expand Down

0 comments on commit 78985e6

Please sign in to comment.