Search code examples
windowsrustwindows-rs

GetInterfaceDnsSettings does not accept *mut DNS_INTERFACE_SETTINGS3


I am trying to get the ServerProperties member from a DNS_INTERFACE_SETTINGS3 struct.

The documentation states to use GetInterfaceDnsSettings, and under the Settings parameter, it explicitly states that if the Version member is 3, the underlying struct should be DNS_INTERFACE_SETTINGS3.

Any help is greatly appreciated. Thank you.

GetInterfaceDnsSettings docs

I tried doing a manual type cast, there is no compile error, but the cServerProperties member is 0 for my WiFi network adapter even though I have configured DNS over HTTPS for it (Windows 11 machine).

// My GUID is valid and retrieved from GetAdaptersAddresses (and converting the LUID to GUID).

let mut dns_interface_settings: DNS_INTERFACE_SETTINGS3 = Default::default();
dns_interface_settings.Version = DNS_INTERFACE_SETTINGS_VERSION3;

// This has an error: expected raw pointer `*mut DNS_INTERFACE_SETTINGS` found raw pointer `*mut DNS_INTERFACE_SETTINGS3`

let dns_setting_result = GetInterfaceDnsSettings(guid, &mut dns_interface_settings as *mut DNS_INTERFACE_SETTINGS3);

// Or am I meant to do manual type cast?

let dns_setting_result = GetInterfaceDnsSettings(guid, &mut dns_interface_settings as *mut _ as *mut DNS_INTERFACE_SETTINGS);

Solution

  • Silly me, the manual type cast works, and it was meant to return 0, because I configured DNS over HTTPS on a specific network, instead of my network adapter. After configuring it on my network adapter, it does return the correct setting.

    let dns_setting_result = GetInterfaceDnsSettings(guid, &mut dns_interface_settings as *mut _ as *mut DNS_INTERFACE_SETTINGS);