Source file
src/net/dnsconfig_windows.go
1
2
3
4
5 package net
6
7 import (
8 "internal/syscall/windows"
9 "syscall"
10 "time"
11 )
12
13 func dnsReadConfig(ignoredFilename string) (conf *dnsConfig) {
14 conf = &dnsConfig{
15 ndots: 1,
16 timeout: 5 * time.Second,
17 attempts: 2,
18 }
19 defer func() {
20 if len(conf.servers) == 0 {
21 conf.servers = defaultNS
22 }
23 }()
24 aas, err := adapterAddresses()
25 if err != nil {
26 return
27 }
28
29 for _, aa := range aas {
30
31 if aa.OperStatus != windows.IfOperStatusUp {
32 continue
33 }
34
35
36 if aa.FirstGatewayAddress == nil {
37 continue
38 }
39
40 for dns := aa.FirstDnsServerAddress; dns != nil; dns = dns.Next {
41 sa, err := dns.Address.Sockaddr.Sockaddr()
42 if err != nil {
43 continue
44 }
45 var ip IP
46 switch sa := sa.(type) {
47 case *syscall.SockaddrInet4:
48 ip = IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
49 case *syscall.SockaddrInet6:
50 ip = make(IP, IPv6len)
51 copy(ip, sa.Addr[:])
52 if ip[0] == 0xfe && ip[1] == 0xc0 {
53
54
55
56
57
58 continue
59 }
60 default:
61
62 continue
63 }
64 conf.servers = append(conf.servers, JoinHostPort(ip.String(), "53"))
65 }
66 }
67 return conf
68 }
69
View as plain text