summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2021-02-16 19:17:59 +0100
committerDavid Lönnhager <david.l@mullvad.net>2021-02-17 12:21:24 +0100
commit6b9290bb852fa49d7c7542882306cb7c5c784371 (patch)
tree62aa0a875e3bdcb7c94d2b3e806598b88286145d
parentcc1abe541be006a7db2d6c1d92adcb0a627721fe (diff)
downloadmullvadvpn-6b9290bb852fa49d7c7542882306cb7c5c784371.tar.xz
mullvadvpn-6b9290bb852fa49d7c7542882306cb7c5c784371.zip
Test Wintun imports
-rw-r--r--talpid-core/src/tunnel/openvpn/windows.rs31
1 files changed, 26 insertions, 5 deletions
diff --git a/talpid-core/src/tunnel/openvpn/windows.rs b/talpid-core/src/tunnel/openvpn/windows.rs
index ba5f2b8821..ae150a1117 100644
--- a/talpid-core/src/tunnel/openvpn/windows.rs
+++ b/talpid-core/src/tunnel/openvpn/windows.rs
@@ -172,34 +172,41 @@ impl WintunDll {
return Err(io::Error::last_os_error());
}
+ Self::new_inner(handle, Self::get_proc_address)
+ }
+
+ fn new_inner(
+ handle: HMODULE,
+ get_proc_fn: unsafe fn(HMODULE, &CStr) -> io::Result<FARPROC>,
+ ) -> io::Result<Self> {
Ok(WintunDll {
handle,
func_open: unsafe {
- std::mem::transmute(Self::get_proc_address(
+ std::mem::transmute(get_proc_fn(
handle,
CStr::from_bytes_with_nul(b"WintunOpenAdapter\0").unwrap(),
)?)
},
func_create: unsafe {
- std::mem::transmute(Self::get_proc_address(
+ std::mem::transmute(get_proc_fn(
handle,
CStr::from_bytes_with_nul(b"WintunCreateAdapter\0").unwrap(),
)?)
},
func_delete: unsafe {
- std::mem::transmute(Self::get_proc_address(
+ std::mem::transmute(get_proc_fn(
handle,
CStr::from_bytes_with_nul(b"WintunDeleteAdapter\0").unwrap(),
)?)
},
func_free: unsafe {
- std::mem::transmute(Self::get_proc_address(
+ std::mem::transmute(get_proc_fn(
handle,
CStr::from_bytes_with_nul(b"WintunFreeAdapter\0").unwrap(),
)?)
},
func_get_adapter_name: unsafe {
- std::mem::transmute(Self::get_proc_address(
+ std::mem::transmute(get_proc_fn(
handle,
CStr::from_bytes_with_nul(b"WintunGetAdapterName\0").unwrap(),
)?)
@@ -322,3 +329,17 @@ pub fn find_adapter_registry_key(find_guid: &str, permissions: REGSAM) -> io::Re
Err(io::Error::new(io::ErrorKind::NotFound, "device not found"))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn get_proc_fn(_handle: HMODULE, _symbol: &CStr) -> io::Result<FARPROC> {
+ Ok(std::ptr::null_mut())
+ }
+
+ #[test]
+ fn test_wintun_imports() {
+ WintunDll::new_inner(ptr::null_mut(), get_proc_fn).unwrap();
+ }
+}