summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_domainsearchlist.go
diff options
context:
space:
mode:
authorChristopher Koch <c@chrisko.ch>2019-01-20 04:47:08 +0000
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-26 23:34:26 +0000
commit3478513076477d0f19eaeaf441f29949a9f6bc92 (patch)
tree4d621abff002cef480901a2ef015620472293db3 /dhcpv6/option_domainsearchlist.go
parente62883f5b5683ae2259ad01b7ffbe20671deb6b2 (diff)
dhcpv6: easier option parsing
- move option parsing to uio buffer library. - move option code and length reading into FromBytes rather than implementing it in each OptionParser.
Diffstat (limited to 'dhcpv6/option_domainsearchlist.go')
-rw-r--r--dhcpv6/option_domainsearchlist.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/dhcpv6/option_domainsearchlist.go b/dhcpv6/option_domainsearchlist.go
index b7a356e..404a109 100644
--- a/dhcpv6/option_domainsearchlist.go
+++ b/dhcpv6/option_domainsearchlist.go
@@ -1,16 +1,16 @@
package dhcpv6
-// This module defines the OptDomainSearchList structure.
-// https://www.ietf.org/rfc/rfc3646.txt
-
import (
- "encoding/binary"
"fmt"
"github.com/insomniacslk/dhcp/rfc1035label"
+ "github.com/u-root/u-root/pkg/uio"
)
// OptDomainSearchList list implements a OptionDomainSearchList option
+//
+// This module defines the OptDomainSearchList structure.
+// https://www.ietf.org/rfc/rfc3646.txt
type OptDomainSearchList struct {
DomainSearchList *rfc1035label.Labels
}
@@ -19,12 +19,13 @@ func (op *OptDomainSearchList) Code() OptionCode {
return OptionDomainSearchList
}
+// ToBytes marshals this option to bytes.
func (op *OptDomainSearchList) ToBytes() []byte {
- buf := make([]byte, 4)
- binary.BigEndian.PutUint16(buf[0:2], uint16(OptionDomainSearchList))
- binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length()))
- buf = append(buf, op.DomainSearchList.ToBytes()...)
- return buf
+ buf := uio.NewBigEndianBuffer(nil)
+ buf.Write16(uint16(OptionDomainSearchList))
+ buf.Write16(uint16(op.Length()))
+ buf.WriteBytes(op.DomainSearchList.ToBytes())
+ return buf.Data()
}
func (op *OptDomainSearchList) Length() int {
@@ -42,11 +43,11 @@ func (op *OptDomainSearchList) String() string {
// ParseOptDomainSearchList builds an OptDomainSearchList structure from a sequence
// of bytes. The input data does not include option code and length bytes.
func ParseOptDomainSearchList(data []byte) (*OptDomainSearchList, error) {
- opt := OptDomainSearchList{}
- labels, err := rfc1035label.FromBytes(data)
+ var opt OptDomainSearchList
+ var err error
+ opt.DomainSearchList, err = rfc1035label.FromBytes(data)
if err != nil {
return nil, err
}
- opt.DomainSearchList = labels
return &opt, nil
}