@@ -7,6 +7,8 @@ package net
7
7
import (
8
8
"math/rand"
9
9
"sort"
10
+
11
+ "golang_org/x/net/dns/dnsmessage"
10
12
)
11
13
12
14
// reverseaddr returns the in-addr.arpa. or ip6.arpa. hostname of the IP
@@ -35,71 +37,13 @@ func reverseaddr(addr string) (arpa string, err error) {
35
37
return string (buf ), nil
36
38
}
37
39
38
- // Find answer for name in dns message.
39
- // On return, if err == nil, addrs != nil.
40
- func answer (name , server string , dns * dnsMsg , qtype uint16 ) (cname string , addrs []dnsRR , err error ) {
41
- addrs = make ([]dnsRR , 0 , len (dns .answer ))
42
-
43
- if dns .rcode == dnsRcodeNameError {
44
- return "" , nil , & DNSError {Err : errNoSuchHost .Error (), Name : name , Server : server }
45
- }
46
- if dns .rcode != dnsRcodeSuccess {
47
- // None of the error codes make sense
48
- // for the query we sent. If we didn't get
49
- // a name error and we didn't get success,
50
- // the server is behaving incorrectly or
51
- // having temporary trouble.
52
- err := & DNSError {Err : "server misbehaving" , Name : name , Server : server }
53
- if dns .rcode == dnsRcodeServerFailure {
54
- err .IsTemporary = true
55
- }
56
- return "" , nil , err
57
- }
58
-
59
- // Look for the name.
60
- // Presotto says it's okay to assume that servers listed in
61
- // /etc/resolv.conf are recursive resolvers.
62
- // We asked for recursion, so it should have included
63
- // all the answers we need in this one packet.
64
- Cname:
65
- for cnameloop := 0 ; cnameloop < 10 ; cnameloop ++ {
66
- addrs = addrs [0 :0 ]
67
- for _ , rr := range dns .answer {
68
- if _ , justHeader := rr .(* dnsRR_Header ); justHeader {
69
- // Corrupt record: we only have a
70
- // header. That header might say it's
71
- // of type qtype, but we don't
72
- // actually have it. Skip.
73
- continue
74
- }
75
- h := rr .Header ()
76
- if h .Class == dnsClassINET && equalASCIILabel (h .Name , name ) {
77
- switch h .Rrtype {
78
- case qtype :
79
- addrs = append (addrs , rr )
80
- case dnsTypeCNAME :
81
- // redirect to cname
82
- name = rr .(* dnsRR_CNAME ).Cname
83
- continue Cname
84
- }
85
- }
86
- }
87
- if len (addrs ) == 0 {
88
- return "" , nil , & DNSError {Err : errNoSuchHost .Error (), Name : name , Server : server }
89
- }
90
- return name , addrs , nil
91
- }
92
-
93
- return "" , nil , & DNSError {Err : "too many redirects" , Name : name , Server : server }
94
- }
95
-
96
- func equalASCIILabel (x , y string ) bool {
97
- if len (x ) != len (y ) {
40
+ func equalASCIIName (x , y dnsmessage.Name ) bool {
41
+ if x .Length != y .Length {
98
42
return false
99
43
}
100
- for i := 0 ; i < len ( x ); i ++ {
101
- a := x [i ]
102
- b := y [i ]
44
+ for i := 0 ; i < int ( x . Length ); i ++ {
45
+ a := x . Data [i ]
46
+ b := y . Data [i ]
103
47
if 'A' <= a && a <= 'Z' {
104
48
a += 0x20
105
49
}
0 commit comments