summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2023-08-07 13:49:01 +0200
committerLinus Färnstrand <linus@mullvad.net>2023-08-08 08:40:05 +0200
commitfbc2f65508bd1e05548280e1449296d8724f1349 (patch)
tree1e3bc35fc76e6b817713261a287551bdc37b1c98
parent2c54aa327c770c1a3abbe864d0359033fb035077 (diff)
downloadmullvadvpn-fbc2f65508bd1e05548280e1449296d8724f1349.tar.xz
mullvadvpn-fbc2f65508bd1e05548280e1449296d8724f1349.zip
Fix signature on SetInterfaceDnsSettings
-rw-r--r--talpid-core/src/dns/windows/auto.rs2
-rw-r--r--talpid-core/src/dns/windows/iphlpapi.rs19
2 files changed, 10 insertions, 11 deletions
diff --git a/talpid-core/src/dns/windows/auto.rs b/talpid-core/src/dns/windows/auto.rs
index d4cd5d838e..c0b04742d4 100644
--- a/talpid-core/src/dns/windows/auto.rs
+++ b/talpid-core/src/dns/windows/auto.rs
@@ -82,7 +82,7 @@ impl DnsMonitor {
fn fallback_due_to_dnscache(&mut self, result: &Result<(), super::Error>) -> bool {
let is_dnscache_error = match result {
Err(super::Error::Iphlpapi(iphlpapi::Error::SetInterfaceDnsSettings(error))) => {
- *error == RPC_S_SERVER_UNAVAILABLE
+ error.raw_os_error() == Some(RPC_S_SERVER_UNAVAILABLE)
}
Err(super::Error::Netsh(netsh::Error::Netsh(Some(1)))) => true,
_ => false,
diff --git a/talpid-core/src/dns/windows/iphlpapi.rs b/talpid-core/src/dns/windows/iphlpapi.rs
index 8cd8859224..d76b2db6c7 100644
--- a/talpid-core/src/dns/windows/iphlpapi.rs
+++ b/talpid-core/src/dns/windows/iphlpapi.rs
@@ -7,12 +7,13 @@ use std::{
os::windows::ffi::OsStrExt,
ptr,
};
+use talpid_types::win32_err;
use talpid_windows_net::{guid_from_luid, luid_from_alias};
use windows_sys::{
core::GUID,
s, w,
Win32::{
- Foundation::{ERROR_PROC_NOT_FOUND, NO_ERROR, NTSTATUS},
+ Foundation::{ERROR_PROC_NOT_FOUND, WIN32_ERROR},
NetworkManagement::IpHelper::{
DNS_INTERFACE_SETTINGS, DNS_INTERFACE_SETTINGS_VERSION1, DNS_SETTING_IPV6,
DNS_SETTING_NAMESERVER,
@@ -36,8 +37,8 @@ pub enum Error {
ObtainInterfaceGuid(#[error(source)] io::Error),
/// Failed to set DNS settings on interface.
- #[error(display = "Failed to set DNS settings on interface: {}", _0)]
- SetInterfaceDnsSettings(i32),
+ #[error(display = "Failed to set DNS settings on interface")]
+ SetInterfaceDnsSettings(#[error(source)] io::Error),
/// Failure to flush DNS cache.
#[error(display = "Failed to flush DNS resolver cache")]
@@ -55,7 +56,7 @@ pub enum Error {
type SetInterfaceDnsSettingsFn = unsafe extern "stdcall" fn(
interface: GUID,
settings: *const DNS_INTERFACE_SETTINGS,
-) -> NTSTATUS;
+) -> WIN32_ERROR;
struct IphlpApi {
set_interface_dns_settings: SetInterfaceDnsSettingsFn,
@@ -199,12 +200,10 @@ fn set_interface_dns_servers<T: ToString>(
ProfileNameServer: ptr::null_mut(),
};
- let result =
- unsafe { (iphlpapi.set_interface_dns_settings)(guid.to_owned(), &dns_interface_settings) };
- if result != (NO_ERROR as i32) {
- return Err(Error::SetInterfaceDnsSettings(result));
- }
- Ok(())
+ win32_err!(unsafe {
+ (iphlpapi.set_interface_dns_settings)(guid.to_owned(), &dns_interface_settings)
+ })
+ .map_err(Error::SetInterfaceDnsSettings)
}
fn flush_dns_cache() -> Result<(), Error> {