-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathutils.go
More file actions
45 lines (39 loc) · 671 Bytes
/
utils.go
File metadata and controls
45 lines (39 loc) · 671 Bytes
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
package main
import (
"bytes"
"fmt"
"log"
"net"
"github.com/miekg/dns"
)
type query struct {
t uint16
name string
nameForReply string
}
func mustRR(s string) dns.RR {
rr, err := dns.NewRR(s)
if err != nil {
log.Fatal(err)
}
return rr
}
func tryAdd(reply *dns.Msg, record string) {
if rr, err := dns.NewRR(record); err == nil {
reply.Answer = append(reply.Answer, rr)
}
}
func forcedV6(ip net.IP) string {
ip = ip.To16()
if ip == nil {
return "::1"
}
v := bytes.NewBuffer(nil)
for i, b := range ip {
v.WriteString(fmt.Sprintf("%02x", b))
if i%2 == 1 && i != len(ip)-1 {
v.WriteByte(':')
}
}
return v.String()
}