aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/winipcfg/winipcfg.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-01-29 22:29:22 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-02 21:44:58 +0100
commite11de8481c4c349456125e5ad6782d82d423a5b9 (patch)
treed68075b842708eaef491eaed5cd240245923af7d /tunnel/winipcfg/winipcfg.go
parentmod: bump to fix 32-bit alignment (diff)
downloadwireguard-windows-e11de8481c4c349456125e5ad6782d82d423a5b9.tar.xz
wireguard-windows-e11de8481c4c349456125e5ad6782d82d423a5b9.zip
winipcfg: move to undocumented DNS function
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/winipcfg/winipcfg.go')
-rw-r--r--tunnel/winipcfg/winipcfg.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/tunnel/winipcfg/winipcfg.go b/tunnel/winipcfg/winipcfg.go
index 8d119f0e..54040a1c 100644
--- a/tunnel/winipcfg/winipcfg.go
+++ b/tunnel/winipcfg/winipcfg.go
@@ -6,6 +6,7 @@
package winipcfg
import (
+ "runtime"
"unsafe"
"golang.org/x/sys/windows"
@@ -166,3 +167,29 @@ func GetIPForwardTable2(family AddressFamily) ([]MibIPforwardRow2, error) {
// https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-cancelmibchangenotify2
//sys cancelMibChangeNotify2(notificationHandle windows.Handle) (ret error) = iphlpapi.CancelMibChangeNotify2
+
+//
+// Undocumented DNS API
+//
+
+//sys setInterfaceDnsSettingsByPtr(guid *windows.GUID, settings *dnsInterfaceSettings) (ret error) = iphlpapi.SetInterfaceDnsSettings?
+//sys setInterfaceDnsSettingsByQwords(guid1 uintptr, guid2 uintptr, settings *dnsInterfaceSettings) (ret error) = iphlpapi.SetInterfaceDnsSettings?
+//sys setInterfaceDnsSettingsByDwords(guid1 uintptr, guid2 uintptr, guid3 uintptr, guid4 uintptr, settings *dnsInterfaceSettings) (ret error) = iphlpapi.SetInterfaceDnsSettings?
+
+// The GUID is passed by value, not by reference, which means different
+// things on different calling conventions. On amd64, this means it's
+// passed by reference anyway, while on arm, arm64, and 386, it's split
+// into words.
+func setInterfaceDnsSettings(guid windows.GUID, settings *dnsInterfaceSettings) error {
+ words := (*[4]uintptr)(unsafe.Pointer(&guid))
+ switch runtime.GOARCH {
+ case "amd64":
+ return setInterfaceDnsSettingsByPtr(&guid, settings)
+ case "arm64":
+ return setInterfaceDnsSettingsByQwords(words[0], words[1], settings)
+ case "arm", "386":
+ return setInterfaceDnsSettingsByDwords(words[0], words[1], words[2], words[3], settings)
+ default:
+ panic("unknown calling convention")
+ }
+}