@@ -9,38 +9,6 @@ import (
9
9
"sort"
10
10
)
11
11
12
- // DNSError represents a DNS lookup error.
13
- type DNSError struct {
14
- Err string // description of the error
15
- Name string // name looked for
16
- Server string // server used
17
- IsTimeout bool // if true, timed out; not all timeouts set this
18
- }
19
-
20
- func (e * DNSError ) Error () string {
21
- if e == nil {
22
- return "<nil>"
23
- }
24
- s := "lookup " + e .Name
25
- if e .Server != "" {
26
- s += " on " + e .Server
27
- }
28
- s += ": " + e .Err
29
- return s
30
- }
31
-
32
- // Timeout reports whether the DNS lookup is known to have timed out.
33
- // This is not always known; a DNS lookup may fail due to a timeout
34
- // and return a DNSError for which Timeout returns false.
35
- func (e * DNSError ) Timeout () bool { return e .IsTimeout }
36
-
37
- // Temporary reports whether the DNS error is known to be temporary.
38
- // This is not always known; a DNS lookup may fail due to a temporary
39
- // error and return a DNSError for which Temporary returns false.
40
- func (e * DNSError ) Temporary () bool { return e .IsTimeout }
41
-
42
- const noSuchHost = "no such host"
43
-
44
12
// reverseaddr returns the in-addr.arpa. or ip6.arpa. hostname of the IP
45
13
// address addr suitable for rDNS (PTR) record lookup or an error if it fails
46
14
// to parse the IP address.
@@ -50,8 +18,7 @@ func reverseaddr(addr string) (arpa string, err error) {
50
18
return "" , & DNSError {Err : "unrecognized address" , Name : addr }
51
19
}
52
20
if ip .To4 () != nil {
53
- return uitoa (uint (ip [15 ])) + "." + uitoa (uint (ip [14 ])) + "." + uitoa (uint (ip [13 ])) + "." +
54
- uitoa (uint (ip [12 ])) + ".in-addr.arpa." , nil
21
+ return uitoa (uint (ip [15 ])) + "." + uitoa (uint (ip [14 ])) + "." + uitoa (uint (ip [13 ])) + "." + uitoa (uint (ip [12 ])) + ".in-addr.arpa." , nil
55
22
}
56
23
// Must be IPv6
57
24
buf := make ([]byte , 0 , len (ip )* 4 + len ("ip6.arpa." ))
@@ -74,7 +41,7 @@ func answer(name, server string, dns *dnsMsg, qtype uint16) (cname string, addrs
74
41
addrs = make ([]dnsRR , 0 , len (dns .answer ))
75
42
76
43
if dns .rcode == dnsRcodeNameError && dns .recursion_available {
77
- return "" , nil , & DNSError {Err : noSuchHost , Name : name }
44
+ return "" , nil , & DNSError {Err : errNoSuchHost . Error () , Name : name }
78
45
}
79
46
if dns .rcode != dnsRcodeSuccess {
80
47
// None of the error codes make sense
@@ -113,7 +80,7 @@ Cname:
113
80
}
114
81
}
115
82
if len (addrs ) == 0 {
116
- return "" , nil , & DNSError {Err : noSuchHost , Name : name , Server : server }
83
+ return "" , nil , & DNSError {Err : errNoSuchHost . Error () , Name : name , Server : server }
117
84
}
118
85
return name , addrs , nil
119
86
}
@@ -201,13 +168,10 @@ type SRV struct {
201
168
type byPriorityWeight []* SRV
202
169
203
170
func (s byPriorityWeight ) Len () int { return len (s ) }
204
-
205
- func (s byPriorityWeight ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
206
-
207
171
func (s byPriorityWeight ) Less (i , j int ) bool {
208
- return s [i ].Priority < s [j ].Priority ||
209
- (s [i ].Priority == s [j ].Priority && s [i ].Weight < s [j ].Weight )
172
+ return s [i ].Priority < s [j ].Priority || (s [i ].Priority == s [j ].Priority && s [i ].Weight < s [j ].Weight )
210
173
}
174
+ func (s byPriorityWeight ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
211
175
212
176
// shuffleByWeight shuffles SRV records by weight using the algorithm
213
177
// described in RFC 2782.
@@ -255,11 +219,9 @@ type MX struct {
255
219
// byPref implements sort.Interface to sort MX records by preference
256
220
type byPref []* MX
257
221
258
- func (s byPref ) Len () int { return len (s ) }
259
-
222
+ func (s byPref ) Len () int { return len (s ) }
260
223
func (s byPref ) Less (i , j int ) bool { return s [i ].Pref < s [j ].Pref }
261
-
262
- func (s byPref ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
224
+ func (s byPref ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
263
225
264
226
// sort reorders MX records as specified in RFC 5321.
265
227
func (s byPref ) sort () {
0 commit comments