From d7eabfff063e286b5545226668e18857da00442f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 3 Sep 2019 10:54:05 -0600 Subject: winipcfg: [BEGINNINGS] import undocumented iphlpapi function --- tunnel/winipcfg/types.go | 25 +++++++++++++++++++++++++ tunnel/winipcfg/winipcfg.go | 3 +++ tunnel/winipcfg/zwinipcfg_windows.go | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/tunnel/winipcfg/types.go b/tunnel/winipcfg/types.go index 684a6c77..b7c49029 100644 --- a/tunnel/winipcfg/types.go +++ b/tunnel/winipcfg/types.go @@ -950,3 +950,28 @@ func (tab *mibIPforwardTable2) get() []MibIPforwardRow2 { func (tab *mibIPforwardTable2) free() { freeMibTable(unsafe.Pointer(tab)) } + +type DnsInterfaceSettings struct { + Version uint32 + Flags uint64 + Domain *uint16 + NameServer *uint16 + SearchList *uint16 + RegistrationEnabled uint32 + RegisterAdapterName uint32 + EnableLLMNR uint32 + QueryAdapterName uint32 + ProfileNameServer *uint16 +} + +const ( + DisVersion = 1 + + DisFlagsHaveNameServer = 2 << iota + DisFlagsHaveSearchList + DisFlagsHaveRegistrationEnabled + DisFlagsHaveDomain + DisFlagsHaveEnableLLMNR + DisFlagsHaveQueryAdapterName + DisFlagsHaveProfileNameServer +) \ No newline at end of file diff --git a/tunnel/winipcfg/winipcfg.go b/tunnel/winipcfg/winipcfg.go index 2fc0c875..90a96bb5 100644 --- a/tunnel/winipcfg/winipcfg.go +++ b/tunnel/winipcfg/winipcfg.go @@ -166,3 +166,6 @@ 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 +//sys setInterfaceDnsSettings(guid *windows.GUID, settings *DnsInterfaceSettings) (ret error) = iphlpapi.SetInterfaceDnsSettings \ No newline at end of file diff --git a/tunnel/winipcfg/zwinipcfg_windows.go b/tunnel/winipcfg/zwinipcfg_windows.go index 8f37ac26..cc4c3f70 100644 --- a/tunnel/winipcfg/zwinipcfg_windows.go +++ b/tunnel/winipcfg/zwinipcfg_windows.go @@ -68,6 +68,7 @@ var ( procNotifyUnicastIpAddressChange = modiphlpapi.NewProc("NotifyUnicastIpAddressChange") procNotifyRouteChange2 = modiphlpapi.NewProc("NotifyRouteChange2") procCancelMibChangeNotify2 = modiphlpapi.NewProc("CancelMibChangeNotify2") + procSetInterfaceDnsSettings = modiphlpapi.NewProc("SetInterfaceDnsSettings") ) func freeMibTable(memory unsafe.Pointer) { @@ -307,3 +308,11 @@ func cancelMibChangeNotify2(notificationHandle windows.Handle) (ret error) { } return } + +func setInterfaceDnsSettings(guid *windows.GUID, settings *DnsInterfaceSettings) (ret error) { + r0, _, _ := syscall.Syscall(procSetInterfaceDnsSettings.Addr(), 2, uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(settings)), 0) + if r0 != 0 { + ret = syscall.Errno(r0) + } + return +} -- cgit v1.2.3-59-g8ed1b