Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions tools/network/dnssec/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package dnssec

import (
"fmt"
"runtime/debug"
"time"
"unsafe"

Expand Down Expand Up @@ -94,25 +93,31 @@ type fixedInfoWithOverlay struct {
// See GetNetworkParams for details:
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getnetworkparams
func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error) {
// disable GC to prevent fi collection earlier than lookups in fi completed
pct := debug.SetGCPercent(-1)
defer debug.SetGCPercent(pct)
ulSize := uint32(unsafe.Sizeof(fixedInfoWithOverlay{}))

buf, err := windows.LocalAlloc(windows.LMEM_FIXED | windows.LMEM_ZEROINIT, ulSize)
if err != nil {
err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize)
Comment thread
algorandskiy marked this conversation as resolved.
return
}

defer windows.LocalFree(windows.Handle(buf))

var fi fixedInfoWithOverlay
var ulSize uint32 = uint32(unsafe.Sizeof(fi))
ret, _, _ := networkParamsProc.Call(
uintptr(unsafe.Pointer(&fi)),
buf,
uintptr(unsafe.Pointer(&ulSize)),
)
if ret != 0 {
if windows.Errno(ret) == windows.ERROR_BUFFER_OVERFLOW {
err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fi), ret)
err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fixedInfoWithOverlay{}), ret)
return
}
err = fmt.Errorf("GetNetworkParams failed with code is %x", ret)
return
}

fi := (*fixedInfoWithOverlay)(unsafe.Pointer(buf))

var p *ipAddrString = &fi.DnsServerList
for {
ip := make([]byte, ip_size)
Expand Down