1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 "internal/syscall/windows"
13 func dnsReadConfig(ignoredFilename string) (conf *dnsConfig) {
16 timeout: 5 * time.Second,
20 if len(conf.servers) == 0 {
21 conf.servers = defaultNS
24 aas, err := adapterAddresses()
28 // TODO(bradfitz): this just collects all the DNS servers on all
29 // the interfaces in some random order. It should order it by
30 // default route, or only use the default route(s) instead.
31 // In practice, however, it mostly works.
32 for _, aa := range aas {
33 for dns := aa.FirstDnsServerAddress; dns != nil; dns = dns.Next {
34 // Only take interfaces whose OperStatus is IfOperStatusUp(0x01) into DNS configs.
35 if aa.OperStatus != windows.IfOperStatusUp {
38 sa, err := dns.Address.Sockaddr.Sockaddr()
43 switch sa := sa.(type) {
44 case *syscall.SockaddrInet4:
45 ip = IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
46 case *syscall.SockaddrInet6:
47 ip = make(IP, IPv6len)
49 if ip[0] == 0xfe && ip[1] == 0xc0 {
50 // Ignore these fec0/10 ones. Windows seems to
51 // populate them as defaults on its misc rando
59 conf.servers = append(conf.servers, JoinHostPort(ip.String(), "53"))