-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_request.go
66 lines (60 loc) · 1.78 KB
/
dns_request.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
package main
// 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ID |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QDCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ANCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | NSCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ARCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
type DnsRequest struct {
Id [2]byte
QR bool // 0 = false = request, 1 = true = response
Opcode uint8
AA bool
TC bool
RD bool
RA bool
Z uint8
RCODE uint8
QDCount uint16
ANCount uint16
ARCount uint16
}
func NewDnsRequest(data []byte) *DnsRequest {
if data == nil {
panic("Error: data cannot be nil")
}
if len(data) < 12 {
panic("Error: Length of data must be at least 12 bytes long")
}
if len(data) > maxBufferSize {
panic("This server does not support datagrams longer than " + string(maxBufferSize) + " bytes")
}
req := &DnsRequest{}
req.Id = [2]byte{data[0], data[1]}
req.QR = false
req.Opcode = data[2] & OpCodeFlag >> 3
req.AA = false
req.TC = false
req.RD = (byte(0b00000001) & data[2]) == 1
req.RA = false
req.RCODE = 0
return req
}
func (req DnsRequest) ToByteArray() []byte {
return nil
}
func (req DnsRequest) IsFoulted() bool {
if req.RCODE != 0 {
return true
}
return false
}