File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66** /* .rs.bk
77Cargo.lock
88wintun.dll
9- .history
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ nix = { version = "0.29", features = ["ioctl"] }
3030
3131[target .'cfg(target_os = "windows")' .dependencies ]
3232wintun = { version = " 0.4" , features = [" panic_on_unsent_packets" ] }
33- libloading = " 0.8.3 "
33+ libloading = " 0.8"
3434
3535[target .'cfg(any(target_os = "macos", target_os = "freebsd"))' .dependencies ]
3636ipnet = " 2"
Original file line number Diff line number Diff line change @@ -135,5 +135,4 @@ pub extern "C" fn start_tun(fd: std::os::raw::c_int) {
135135Windows
136136-----
137137You need to copy the [ wintun.dll] ( https://wintun.net/ ) file which matches your architecture to
138- the same directory as your executable or can set ` WINTUN_LIBARAY_PATH ` to the dll file and run your program as administrator.
139-
138+ the same directory as your executable and run your program as administrator.
Original file line number Diff line number Diff line change @@ -31,10 +31,12 @@ pub struct Device {
3131impl Device {
3232 /// Create a new `Device` for the given `Configuration`.
3333 pub fn new ( config : & Configuration ) -> Result < Self > {
34+ let wintun_path = match & config. platform_config . wintun_path {
35+ Some ( path) => path. clone ( ) ,
36+ None => "wintun.dll" . to_string ( ) ,
37+ } ;
3438 let wintun = unsafe {
35- let wintun_libray_path =
36- std:: env:: var ( "WINTUN_LIBARAY_PATH" ) . unwrap_or ( "wintun.dll" . to_string ( ) ) ;
37- let wintun = libloading:: Library :: new ( wintun_libray_path) ?;
39+ let wintun = libloading:: Library :: new ( wintun_path) ?;
3840 wintun:: load_from_library ( wintun) ?
3941 } ;
4042 let tun_name = config. tun_name . as_deref ( ) . unwrap_or ( "wintun" ) ;
Original file line number Diff line number Diff line change @@ -22,16 +22,24 @@ use crate::configuration::Configuration;
2222use crate :: error:: Result ;
2323
2424/// Windows-only interface configuration.
25- #[ derive( Copy , Clone , Default , Debug ) ]
25+ #[ derive( Clone , Default , Debug ) ]
2626pub struct PlatformConfig {
2727 pub ( crate ) device_guid : Option < u128 > ,
28+ pub ( crate ) wintun_path : Option < String > ,
2829}
2930
3031impl PlatformConfig {
3132 pub fn device_guid ( & mut self , device_guid : Option < u128 > ) {
3233 log:: trace!( "Windows configuration device GUID" ) ;
3334 self . device_guid = device_guid;
3435 }
36+
37+ /// Use a custom path to the wintun.dll instead of looking in the working directory.
38+ /// Security note: It is up to the caller to ensure that the library can be safely loaded from
39+ /// the indicated path.
40+ pub fn custom_wintun_path ( & mut self , wintun_path : Option < String > ) {
41+ self . wintun_path = wintun_path;
42+ }
3543}
3644
3745/// Create a TUN device with the given name.
You can’t perform that action at this time.
0 commit comments