diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dns/dns_test.go | 14 | ||||
| -rw-r--r-- | lib/dns/hosts.go | 2 | ||||
| -rw-r--r-- | lib/dns/message.go | 10 | ||||
| -rw-r--r-- | lib/dns/message_test.go | 9 | ||||
| -rw-r--r-- | lib/dns/response.go | 2 | ||||
| -rw-r--r-- | lib/dns/tcpclient.go | 6 | ||||
| -rw-r--r-- | lib/dns/tcpclient_test.go | 2 | ||||
| -rw-r--r-- | lib/dns/udpclient.go | 6 | ||||
| -rw-r--r-- | lib/dns/udpclient_test.go | 2 |
9 files changed, 26 insertions, 27 deletions
diff --git a/lib/dns/dns_test.go b/lib/dns/dns_test.go index 80972af2..9bfd57e8 100644 --- a/lib/dns/dns_test.go +++ b/lib/dns/dns_test.go @@ -53,9 +53,9 @@ func (h *serverHandler) generateResponses() { }, } - _, err := res.Message.MarshalBinary() + _, err := res.Message.Pack() if err != nil { - log.Fatal("MarshalBinary: ", err) + log.Fatal("Pack: ", err) } h.responses = append(h.responses, res) @@ -93,9 +93,9 @@ func (h *serverHandler) generateResponses() { }, } - _, err = res.Message.MarshalBinary() + _, err = res.Message.Pack() if err != nil { - log.Fatal("MarshalBinary: ", err) + log.Fatal("Pack: ", err) } h.responses = append(h.responses, res) @@ -127,9 +127,9 @@ func (h *serverHandler) generateResponses() { }, } - _, err = res.Message.MarshalBinary() + _, err = res.Message.Pack() if err != nil { - log.Fatal("MarshalBinary: ", err) + log.Fatal("Pack: ", err) } h.responses = append(h.responses, res) @@ -165,7 +165,7 @@ func (h *serverHandler) ServeDNS(req *Request) { res.Message.Header.ID = req.Message.Header.ID - _, err := res.Message.MarshalBinary() + _, err := res.Message.Pack() if err != nil { _testServer.FreeRequest(req) return diff --git a/lib/dns/hosts.go b/lib/dns/hosts.go index 2cec0000..d55c5f88 100644 --- a/lib/dns/hosts.go +++ b/lib/dns/hosts.go @@ -87,7 +87,7 @@ func newMessage(addr, hname []byte) *Message { }}, } - _, err := msg.MarshalBinary() + _, err := msg.Pack() if err != nil { return nil } diff --git a/lib/dns/message.go b/lib/dns/message.go index c406b6fc..ee84182b 100644 --- a/lib/dns/message.go +++ b/lib/dns/message.go @@ -508,10 +508,10 @@ func (msg *Message) IsExpired(elapsed uint32) bool { } // -// MarshalBinary convert message into datagram packet. The result of packing +// Pack convert message into datagram packet. The result of packing // a message will be saved in Packet field and returned. // -func (msg *Message) MarshalBinary() ([]byte, error) { +func (msg *Message) Pack() ([]byte, error) { msg.dnameOff = make(map[string]uint16) msg.Packet = msg.Packet[:0] @@ -599,11 +599,9 @@ func (msg *Message) String() string { } // -// UnmarshalBinary unpack the packet to fill the message fields. +// Unpack the packet to fill the message fields. // -func (msg *Message) UnmarshalBinary(packet []byte) (err error) { - msg.Packet = packet - +func (msg *Message) Unpack() (err error) { msg.UnpackHeaderQuestion() startIdx := uint(sectionHeaderSize + msg.Question.Size()) diff --git a/lib/dns/message_test.go b/lib/dns/message_test.go index 47d37fe4..24afa104 100644 --- a/lib/dns/message_test.go +++ b/lib/dns/message_test.go @@ -154,7 +154,7 @@ func TestMessagePackQuestion(t *testing.T) { } } -func TestMessageMarshalBinary(t *testing.T) { +func TestMessagePack(t *testing.T) { cases := []struct { desc string msg *Message @@ -851,13 +851,13 @@ func TestMessageMarshalBinary(t *testing.T) { for _, c := range cases { t.Log(c.desc) - got, _ := c.msg.MarshalBinary() + got, _ := c.msg.Pack() test.Assert(t, c.desc, c.exp, got, true) } } -func TestMessageUnmarshalBinary(t *testing.T) { +func TestMessageUnpack(t *testing.T) { cases := []struct { desc string packet []byte @@ -1706,8 +1706,9 @@ func TestMessageUnmarshalBinary(t *testing.T) { t.Log(c.desc) msg.Reset() + msg.Packet = c.packet - err := msg.UnmarshalBinary(c.packet) + err := msg.Unpack() if err != nil { t.Fatal(err) } diff --git a/lib/dns/response.go b/lib/dns/response.go index 70a58211..40108c2c 100644 --- a/lib/dns/response.go +++ b/lib/dns/response.go @@ -43,7 +43,7 @@ func (res *Response) IsExpired() bool { // Unpack message and set received time value to current time. // func (res *Response) Unpack() (err error) { - err = res.Message.UnmarshalBinary(res.Message.Packet) + err = res.Message.Unpack() if err != nil { return } diff --git a/lib/dns/tcpclient.go b/lib/dns/tcpclient.go index ac55d19b..4b469a4c 100644 --- a/lib/dns/tcpclient.go +++ b/lib/dns/tcpclient.go @@ -94,7 +94,7 @@ func (cl *TCPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( msg.Question.Class = qclass msg.Question.Name = append(msg.Question.Name, qname...) - _, _ = msg.MarshalBinary() + _, _ = msg.Pack() _, err := cl.Send(msg, nil) if err != nil { @@ -111,7 +111,7 @@ func (cl *TCPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( return nil, err } - err = resMsg.UnmarshalBinary(resMsg.Packet) + err = resMsg.Unpack() if err != nil { FreeMessage(msg) FreeMessage(resMsg) @@ -126,7 +126,7 @@ func (cl *TCPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( // // Send DNS message to name server using active connection in client. // -// The message packet must already been filled, using MarshalBinary(). +// The message packet must already been filled, using Pack(). // The addr parameter is unused. // func (cl *TCPClient) Send(msg *Message, addr net.Addr) (n int, err error) { diff --git a/lib/dns/tcpclient_test.go b/lib/dns/tcpclient_test.go index deef7ef3..9ff8c94f 100644 --- a/lib/dns/tcpclient_test.go +++ b/lib/dns/tcpclient_test.go @@ -125,7 +125,7 @@ func TestTCPClientLookup(t *testing.T) { c.exp.Header.ID = getID() - _, err = c.exp.MarshalBinary() + _, err = c.exp.Pack() if err != nil { t.Fatal(err) } diff --git a/lib/dns/udpclient.go b/lib/dns/udpclient.go index 464e35c9..9ba51fca 100644 --- a/lib/dns/udpclient.go +++ b/lib/dns/udpclient.go @@ -88,7 +88,7 @@ func (cl *UDPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( msg.Question.Class = qclass msg.Question.Name = append(msg.Question.Name, qname...) - _, _ = msg.MarshalBinary() + _, _ = msg.Pack() _, err := cl.Send(msg, cl.Addr) if err != nil { @@ -106,7 +106,7 @@ func (cl *UDPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( return nil, err } - err = resMsg.UnmarshalBinary(resMsg.Packet) + err = resMsg.Unpack() if err != nil { msgPool.Put(msg) msgPool.Put(resMsg) @@ -121,7 +121,7 @@ func (cl *UDPClient) Lookup(qtype uint16, qclass uint16, qname []byte) ( // // Send DNS message to name server using active connection in client. // -// The message packet must already been filled, using MarshalBinary(). +// The message packet must already been filled, using Pack(). // The addr parameter must not be nil. // func (cl *UDPClient) Send(msg *Message, ns net.Addr) (n int, err error) { diff --git a/lib/dns/udpclient_test.go b/lib/dns/udpclient_test.go index 3fcb928c..8e4ff609 100644 --- a/lib/dns/udpclient_test.go +++ b/lib/dns/udpclient_test.go @@ -125,7 +125,7 @@ func TestUDPClientLookup(t *testing.T) { c.exp.Header.ID = getID() - _, err = c.exp.MarshalBinary() + _, err = c.exp.Pack() if err != nil { t.Fatal(err) } |
