diff options
-rw-r--r-- | dhcpv6/option_iaprefix.go | 7 | ||||
-rw-r--r-- | dhcpv6/option_iaprefix_test.go | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/dhcpv6/option_iaprefix.go b/dhcpv6/option_iaprefix.go index abd7a34..c66b242 100644 --- a/dhcpv6/option_iaprefix.go +++ b/dhcpv6/option_iaprefix.go @@ -34,7 +34,12 @@ func (op *OptIAPrefix) ToBytes() []byte { t2.Marshal(buf) buf.Write8(op.prefixLength) - buf.WriteBytes(op.ipv6Prefix.To16()) + prefix := op.ipv6Prefix.To16() + if prefix != nil { + buf.WriteBytes(prefix) + } else { + buf.WriteBytes(make([]byte, net.IPv6len)) + } buf.WriteBytes(op.Options.ToBytes()) return buf.Data() } diff --git a/dhcpv6/option_iaprefix_test.go b/dhcpv6/option_iaprefix_test.go index 7a24d2b..a1c140e 100644 --- a/dhcpv6/option_iaprefix_test.go +++ b/dhcpv6/option_iaprefix_test.go @@ -56,6 +56,21 @@ func TestOptIAPrefixToBytes(t *testing.T) { } } +func TestOptIAPrefixToBytesDefault(t *testing.T) { + buf := []byte{ + 0, 0, 0, 0, // preferredLifetime + 0, 0, 0, 0, // validLifetime + 0, // prefixLength + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ipv6Prefix + } + opt := OptIAPrefix{ + } + toBytes := opt.ToBytes() + if !bytes.Equal(toBytes, buf) { + t.Fatalf("Invalid ToBytes result. Expected %v, got %v", buf, toBytes) + } +} + func TestOptIAPrefixParseInvalidTooShort(t *testing.T) { buf := []byte{ 0xaa, 0xbb, 0xcc, 0xdd, // preferredLifetime |