aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/winipcfg/winipcfg.go
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/winipcfg/winipcfg.go')
-rw-r--r--tunnel/winipcfg/winipcfg.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/tunnel/winipcfg/winipcfg.go b/tunnel/winipcfg/winipcfg.go
index 2fc0c875..e24157b9 100644
--- a/tunnel/winipcfg/winipcfg.go
+++ b/tunnel/winipcfg/winipcfg.go
@@ -1,11 +1,12 @@
/* SPDX-License-Identifier: MIT
*
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
*/
package winipcfg
import (
+ "runtime"
"unsafe"
"golang.org/x/sys/windows"
@@ -29,6 +30,7 @@ import (
//sys getIfTable2Ex(level MibIfEntryLevel, table **mibIfTable2) (ret error) = iphlpapi.GetIfTable2Ex
//sys convertInterfaceLUIDToGUID(interfaceLUID *LUID, interfaceGUID *windows.GUID) (ret error) = iphlpapi.ConvertInterfaceLuidToGuid
//sys convertInterfaceGUIDToLUID(interfaceGUID *windows.GUID, interfaceLUID *LUID) (ret error) = iphlpapi.ConvertInterfaceGuidToLuid
+//sys convertInterfaceIndexToLUID(interfaceIndex uint32, interfaceLUID *LUID) (ret error) = iphlpapi.ConvertInterfaceIndexToLuid
// GetAdaptersAddresses function retrieves the addresses associated with the adapters on the local computer.
// https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses
@@ -166,3 +168,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
+
+//
+// DNS-related functions
+//
+
+//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")
+ }
+}