diff options
author | Christopher Koch <c@chrisko.ch> | 2019-01-20 04:41:32 +0000 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-26 23:34:26 +0000 |
commit | e62883f5b5683ae2259ad01b7ffbe20671deb6b2 (patch) | |
tree | 7c48b75d9ddfd123a1fee5d3e8c4fba503cdfb7a /dhcpv6/dhcpv6message.go | |
parent | 116fb1d0a3124d2a2dc14ead7db6b497224377ab (diff) |
dhcpv6: use uio buffer in DHCPv6 message parsing
Diffstat (limited to 'dhcpv6/dhcpv6message.go')
-rw-r--r-- | dhcpv6/dhcpv6message.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index 85d93a3..078f72a 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -9,6 +9,7 @@ import ( "time" "github.com/insomniacslk/dhcp/iana" + "github.com/u-root/u-root/pkg/uio" ) const MessageHeaderSize = 4 @@ -307,16 +308,16 @@ func (d *DHCPv6Message) Summary() string { return ret } -// Convert a DHCPv6Message structure into its binary representation, suitable for being -// sent over the network +// ToBytes returns the serialized version of this message as defined by RFC +// 3315, Section 5. func (d *DHCPv6Message) ToBytes() []byte { - var ret []byte - ret = append(ret, byte(d.messageType)) - ret = append(ret, d.transactionID[:]...) // discard the first byte + buf := uio.NewBigEndianBuffer(nil) + buf.Write8(uint8(d.messageType)) + buf.WriteBytes(d.transactionID[:]) for _, opt := range d.options { - ret = append(ret, opt.ToBytes()...) + buf.WriteBytes(opt.ToBytes()) } - return ret + return buf.Data() } func (d *DHCPv6Message) Length() int { |