-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.go
54 lines (43 loc) · 905 Bytes
/
question.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
package main
type QueryType int
const (
UNKNOWN QueryType = 0
A QueryType = 1
NS QueryType = 2
CNAME QueryType = 5
MX QueryType = 15
AAAA QueryType = 28
)
type DnsQuestion struct {
name string
qtype QueryType
}
// NewDnsQuestion creates a new DnsQuestion
func NewDnsQuestion() *DnsQuestion {
return &DnsQuestion{}
}
// read reads a question from the buffer
func (d *DnsQuestion) read(buf *BytePacketBuffer) error {
name, err := buf.readQName()
if err != nil {
return err
}
d.name = name
qtype, err := buf.read2Byte()
if err != nil {
return err
}
d.qtype = QueryType(qtype)
buf.read2Byte() // class
return nil
}
func (d *DnsQuestion) write(buf *BytePacketBuffer) error {
if err := buf.writeQName(d.name); err != nil {
return err
}
if err := buf.write2Byte(uint16(d.qtype)); err != nil {
return err
}
buf.write2Byte(1) // class
return nil
}