diff options
author | Xuehao (David) Hu <xuehaohu@google.com> | 2020-02-04 12:00:29 -0800 |
---|---|---|
committer | Xuehao (David) Hu <xuehaohu@google.com> | 2020-02-06 18:15:13 -0800 |
commit | 8a245966f316b2f19e13e806a95ef1c4e6806eb5 (patch) | |
tree | c077ddd63a2f91cade9c6e14be46c6fef1b9e234 /dhcpv6/option_fqdn.go | |
parent | 5214532ecf392e5a8818355f3fff993aaef42c06 (diff) |
hcpv6 fqdn: implements OptionFQDN option
per https://tools.ietf.org/rfc/rfc4704.txt
Signed-off-by: Xuehao (David) Hu <xuehaohu@google.com>
Diffstat (limited to 'dhcpv6/option_fqdn.go')
-rw-r--r-- | dhcpv6/option_fqdn.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dhcpv6/option_fqdn.go b/dhcpv6/option_fqdn.go new file mode 100644 index 0000000..82d1254 --- /dev/null +++ b/dhcpv6/option_fqdn.go @@ -0,0 +1,41 @@ +package dhcpv6 + +import ( + "fmt" + + "github.com/u-root/u-root/pkg/uio" +) + +// OptFQDN implements OptionFQDN option. +// +// https://tools.ietf.org/html/rfc4704 +type OptFQDN struct { + Flags uint8 + DomainName string +} + +// Code returns the option code. +func (op *OptFQDN) Code() OptionCode { + return OptionFQDN +} + +// ToBytes serializes the option and returns it as a sequence of bytes +func (op *OptFQDN) ToBytes() []byte { + buf := uio.NewBigEndianBuffer(nil) + buf.Write8(op.Flags) + buf.WriteBytes([]byte(op.DomainName)) + return buf.Data() +} + +func (op *OptFQDN) String() string { + return fmt.Sprintf("OptFQDN{flags=%d, domainname=%s}", op.Flags, op.DomainName) +} + +// ParseOptFQDN deserializes from bytes to build a OptFQDN structure. +func ParseOptFQDN(data []byte) (*OptFQDN, error) { + var opt OptFQDN + buf := uio.NewBigEndianBuffer(data) + opt.Flags = buf.Read8() + opt.DomainName = string(buf.ReadAll()) + return &opt, buf.FinError() +} |