Skip to content

Commit

Permalink
Support set wintun dns servers (meh#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
feifeigood authored Jun 13, 2024
1 parent 8ec27d1 commit f9f59f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ impl Device {
.unwrap_or(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0)));
let gateway = config.destination.map(IpAddr::from);
adapter.set_network_addresses_tuple(address, mask, gateway)?;
if let Some(dns_servers) = &config.platform_config.dns_servers {
adapter.set_dns_servers(dns_servers)?;
}
let mtu = config.mtu.unwrap_or(crate::DEFAULT_MTU);

let session = adapter.start_session(wintun::MAX_RING_CAPACITY)?;
Expand Down
8 changes: 8 additions & 0 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
mod device;

use std::net::IpAddr;

pub use device::{Device, Tun};

use crate::configuration::Configuration;
Expand All @@ -26,13 +28,15 @@ use crate::error::Result;
pub struct PlatformConfig {
pub(crate) device_guid: Option<u128>,
pub(crate) wintun_path: String,
pub(crate) dns_servers: Option<Vec<IpAddr>>,
}

impl Default for PlatformConfig {
fn default() -> Self {
Self {
device_guid: None,
wintun_path: "wintun".to_string(),
dns_servers: None,
}
}
}
Expand All @@ -49,6 +53,10 @@ impl PlatformConfig {
pub fn custom_wintun_path(&mut self, wintun_path: &str) {
self.wintun_path = wintun_path.to_string();
}

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

/// Create a TUN device with the given name.
Expand Down

0 comments on commit f9f59f6

Please sign in to comment.