-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathutil.go
88 lines (83 loc) · 2.15 KB
/
util.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
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"strconv"
)
/*
The gopacket DNS layer doesn't have a lot of good String()
conversion methods, so we have to do a lot of that ourselves
here. Much of this should move back into gopacket. Also a
little worried about the perf impact of doing string conversions
in this thread...
*/
func TypeString(dnsType layers.DNSType) string {
switch dnsType {
default:
//take a blind stab...at least this shouldn't *lose* data
return strconv.Itoa(int(dnsType))
case layers.DNSTypeA:
return "A"
case layers.DNSTypeAAAA:
return "AAAA"
case layers.DNSTypeCNAME:
return "CNAME"
case layers.DNSTypeMX:
return "MX"
case layers.DNSTypeNS:
return "NS"
case layers.DNSTypePTR:
return "PTR"
case layers.DNSTypeTXT:
return "TXT"
case layers.DNSTypeSOA:
return "SOA"
case layers.DNSTypeSRV:
return "SRV"
case 255: //ANY query per http://tools.ietf.org/html/rfc1035#page-12
return "ANY"
}
}
/*
The gopacket DNS layer doesn't have a lot of good String()
conversion methods, so we have to do a lot of that ourselves
here. Much of this should move back into gopacket. Also a
little worried about the perf impact of doing string conversions
in this thread...
*/
func RrString(rr layers.DNSResourceRecord) string {
switch rr.Type {
default:
//take a blind stab...at least this shouldn't *lose* data
return string(rr.Data)
case layers.DNSTypeA:
return rr.IP.String()
case layers.DNSTypeAAAA:
return rr.IP.String()
case layers.DNSTypeCNAME:
return string(rr.CNAME)
case layers.DNSTypeMX:
//TODO: add the priority
return string(rr.MX.Name)
case layers.DNSTypeNS:
return string(rr.NS)
case layers.DNSTypePTR:
return string(rr.PTR)
case layers.DNSTypeTXT:
return string(rr.TXT)
case layers.DNSTypeSOA:
//TODO: rebuild the full SOA string
return string(rr.SOA.RName)
case layers.DNSTypeSRV:
//TODO: rebuild the full SRV string
return string(rr.SRV.Name)
}
}
func foundLayerType(layer gopacket.LayerType, found []gopacket.LayerType) bool {
for _, value := range found {
if value == layer {
return true
}
}
return false
}