-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
77 lines (64 loc) · 1.29 KB
/
tools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package resolver
import (
"fmt"
"net"
"strings"
"darvaza.org/core"
"github.com/miekg/dns"
"golang.org/x/net/idna"
"darvaza.org/resolver/pkg/errors"
)
const (
netIP4or6 = "ip"
netIP4only = "ip4"
netIP6only = "ip6"
)
func sanitiseNetwork(network string) (string, error) {
s := strings.ToLower(network)
switch s {
case "":
return netIP4or6, nil
case netIP4or6, netIP4only, netIP6only:
return s, nil
default:
return "", fmt.Errorf("%q: invalid network", network)
}
}
func sanitiseHost(host string, p *idna.Profile) (string, error) {
if host != "" {
s, err := p.ToASCII(host)
if err != nil {
return "", core.Wrapf(err, "%q: invalid host", host)
}
return s, nil
}
return "", errors.New("empty host")
}
func sanitiseHost2(host string, p *idna.Profile) (string, *net.DNSError) {
s, err := sanitiseHost(host, p)
if err == nil {
return s, nil
}
return "", &net.DNSError{
Name: host,
Err: err.Error(),
}
}
func eqIP(ip1, ip2 net.IP) bool {
return ip1.Equal(ip2)
}
func msgQuestion(m *dns.Msg) *dns.Question {
if m != nil && len(m.Question) > 0 {
return &m.Question[0]
}
return nil
}
func msgQType(m *dns.Msg) uint16 {
if q := msgQuestion(m); q != nil {
return q.Qtype
}
return 0
}
func rrIsAAAA(rr dns.RR) bool {
return rr.Header().Rrtype == dns.TypeAAAA
}