-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathutil.go
More file actions
123 lines (117 loc) · 2.83 KB
/
Copy pathutil.go
File metadata and controls
123 lines (117 loc) · 2.83 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"strconv"
"github.com/gopacket/gopacket"
"github.com/gopacket/gopacket/layers"
)
/*
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 {
case layers.DNSTypeA:
return "A"
case layers.DNSTypeNS:
return "NS"
case layers.DNSTypeMD:
return "MD"
case layers.DNSTypeMF:
return "MF"
case layers.DNSTypeCNAME:
return "CNAME"
case layers.DNSTypeSOA:
return "SOA"
case layers.DNSTypeMB:
return "MB"
case layers.DNSTypeMG:
return "MG"
case layers.DNSTypeMR:
return "MR"
case layers.DNSTypeNULL:
return "NULL"
case layers.DNSTypeWKS:
return "WKS"
case layers.DNSTypePTR:
return "PTR"
case layers.DNSTypeHINFO:
return "HINFO"
case layers.DNSTypeMINFO:
return "MINFO"
case layers.DNSTypeMX:
return "MX"
case layers.DNSTypeTXT:
return "TXT"
case layers.DNSTypeAAAA:
return "AAAA"
case layers.DNSTypeSRV:
return "SRV"
case layers.DNSTypeOPT:
return "OPT"
case layers.DNSTypeRRSIG:
return "RRSIG"
case layers.DNSTypeDNSKEY:
return "DNSKEY"
case layers.DNSTypeSVCB:
return "SVCB"
case layers.DNSTypeHTTPS:
return "HTTPS"
case layers.DNSTypeURI:
return "URI"
case 255:
return "ANY"
default:
return strconv.Itoa(int(dnsType))
}
}
/*
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 {
case layers.DNSTypeA:
return rr.IP.String()
case layers.DNSTypeAAAA:
return rr.IP.String()
case layers.DNSTypeCNAME:
return string(rr.CNAME)
case layers.DNSTypeMX:
return fmt.Sprintf("%d %s", rr.MX.Preference, 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:
return fmt.Sprintf("%s %s %d %d %d %d %d",
string(rr.SOA.MName), string(rr.SOA.RName),
rr.SOA.Serial, rr.SOA.Refresh, rr.SOA.Retry,
rr.SOA.Expire, rr.SOA.Minimum)
case layers.DNSTypeSRV:
return fmt.Sprintf("%d %d %d %s",
rr.SRV.Priority, rr.SRV.Weight, rr.SRV.Port, string(rr.SRV.Name))
case layers.DNSTypeURI:
return string(rr.Data)
case layers.DNSTypeOPT:
return string(rr.Data)
default:
return string(rr.Data)
}
}
func foundLayerType(layer gopacket.LayerType, found []gopacket.LayerType) bool {
for _, value := range found {
if value == layer {
return true
}
}
return false
}