diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-09 00:27:20 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-09 00:27:20 +0000 |
commit | d827b455cdc1a49a24479b7c444800ce9fa58145 (patch) | |
tree | a065054e8e4622ed91e0bf6c21ba1f970816938a | |
parent | 37d15e6162da76cb135ee09475b3f224f2567ca6 (diff) |
Fixed ParseOptIANA
-rw-r--r-- | dhcpv6/option_nontemporaryaddress.go | 2 | ||||
-rw-r--r-- | dhcpv6/option_nontemporaryaddress_test.go | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/dhcpv6/option_nontemporaryaddress.go b/dhcpv6/option_nontemporaryaddress.go index b387e43..cd3d830 100644 --- a/dhcpv6/option_nontemporaryaddress.go +++ b/dhcpv6/option_nontemporaryaddress.go @@ -81,6 +81,6 @@ func ParseOptIANA(data []byte) (*OptIANA, error) { copy(opt.iaId[:], data[:4]) opt.t1 = binary.BigEndian.Uint32(data[4:8]) opt.t2 = binary.BigEndian.Uint32(data[8:12]) - copy(opt.options, data[12:]) + opt.options = append(data[12:]) return &opt, nil } diff --git a/dhcpv6/option_nontemporaryaddress_test.go b/dhcpv6/option_nontemporaryaddress_test.go new file mode 100644 index 0000000..eac1ef9 --- /dev/null +++ b/dhcpv6/option_nontemporaryaddress_test.go @@ -0,0 +1,26 @@ +package dhcpv6 + +import ( + "testing" +) + +func TestOptIANAParseOptIANA(t *testing.T) { + data := []byte{ + 02, // advertise + 0, 0x80, 0x8b, // transaction ID + // IA_NA option + 0, 3, // option code + 0, 40, // option length + 1, 0, 0, 0, // IAID + 0, 0, 0, 1, // T1 + 0, 0, 0, 2, // T2 + 0, 5, 0, 0x18, 0x24, 1, 0xdb, 0, 0x30, 0x10, 0xc0, 0x8f, 0xfa, 0xce, 0, 0, 0, 0x44, 0, 0, 0, 0, 0xb2, 0x7a, 0, 0, 0xc0, 0x8a, // options + } + opt, err := ParseOptIANA(data) + if err != nil { + t.Fatal(err) + } + if oLen := opt.Length(); oLen != len(data) { + t.Fatalf("Invalid IANA option length. Expected %v, got %v", len(data), oLen) + } +} |