1 // Copyright 2012, Google, Inc. All rights reserved.
2 // Copyright 2009-2011 Andreas Krennmair. All rights reserved.
4 // Use of this source code is governed by a BSD-style license
5 // that can be found in the LICENSE file in the root of the source
11 "github.com/google/gopacket"
17 // testPacketICMPv6 is the packet:
18 // 10:48:30.088384 IP6 2620:0:1005:0:26be:5ff:fe27:b17 > fe80::21f:caff:feb3:7640: ICMP6, neighbor advertisement, tgt is 2620:0:1005:0:26be:5ff:fe27:b17, length 24
19 // 0x0000: 001f cab3 7640 24be 0527 0b17 86dd 6000 ....v@$..'....`.
20 // 0x0010: 0000 0018 3aff 2620 0000 1005 0000 26be ....:.&.......&.
21 // 0x0020: 05ff fe27 0b17 fe80 0000 0000 0000 021f ...'............
22 // 0x0030: caff feb3 7640 8800 1ed6 4000 0000 2620 ....v@....@...&.
23 // 0x0040: 0000 1005 0000 26be 05ff fe27 0b17 ......&....'..
24 var testPacketICMPv6 = []byte{
25 0x00, 0x1f, 0xca, 0xb3, 0x76, 0x40, 0x24, 0xbe, 0x05, 0x27, 0x0b, 0x17, 0x86, 0xdd, 0x60, 0x00,
26 0x00, 0x00, 0x00, 0x18, 0x3a, 0xff, 0x26, 0x20, 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe,
27 0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1f,
28 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40, 0x88, 0x00, 0x1e, 0xd6, 0x40, 0x00, 0x00, 0x00, 0x26, 0x20,
29 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x26, 0xbe, 0x05, 0xff, 0xfe, 0x27, 0x0b, 0x17,
32 func TestPacketICMPv6(t *testing.T) {
33 p := gopacket.NewPacket(testPacketICMPv6, LinkTypeEthernet, gopacket.Default)
34 if p.ErrorLayer() != nil {
35 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
37 checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeICMPv6, gopacket.LayerTypePayload}, t)
38 if got, ok := p.Layer(LayerTypeIPv6).(*IPv6); ok {
41 Contents: []byte{0x60, 0x0, 0x0, 0x0, 0x0, 0x18,
42 0x3a, 0xff, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5,
43 0xff, 0xfe, 0x27, 0xb, 0x17, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
44 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
45 Payload: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0, 0x26, 0x20,
46 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb,
53 NextHeader: IPProtocolICMPv6,
55 SrcIP: net.IP{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
56 DstIP: net.IP{0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
58 if !reflect.DeepEqual(got, want) {
59 t.Errorf("IPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
62 t.Error("No IPv6 layer type found in packet")
64 if got, ok := p.Layer(LayerTypeICMPv6).(*ICMPv6); ok {
67 Contents: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0},
68 Payload: []byte{0x26, 0x20, 0x0, 0x0, 0x10,
69 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
73 TypeBytes: []byte{0x40, 0x0, 0x0, 0x0},
75 if !reflect.DeepEqual(got, want) {
76 t.Errorf("ICMPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
78 if got.TypeCode.String() != "NeighborAdvertisement" {
79 t.Errorf("ICMPv6 type code, got %q want 'NeighborAdvertisement'", got.TypeCode.String())
82 t.Error("No ICMPv6 layer type found in packet")