func TestPacketDot11CtrlAck(t *testing.T) { p := gopacket.NewPacket(testPacketDot11CtrlAck, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t) if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok { if !got.ChecksumValid() { t.Errorf("Dot11 packet processing failed:\nchecksum failed. got :\n%#v\n\n", got) } } if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok { want := &Dot11{ BaseLayer: BaseLayer{ Contents: []uint8{0xd4, 0x0, 0x0, 0x0, 0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52}, Payload: []uint8{}, }, Type: Dot11TypeCtrlAck, Proto: 0x0, Flags: 0x0, DurationID: 0x0, Address1: net.HardwareAddr{0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52}, Address2: net.HardwareAddr(nil), Address3: net.HardwareAddr(nil), Address4: net.HardwareAddr(nil), Checksum: 0x8776e946, } if !reflect.DeepEqual(got, want) { t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }
func TestPacketUSB0(t *testing.T) { p := gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeUSB, LayerTypeUSBInterrupt}, t) if got, ok := p.Layer(LayerTypeUSB).(*USB); ok { want := &USB{ BaseLayer: BaseLayer{ Contents: []uint8{0x0, 0x38, 0x4a, 0x3b, 0x0, 0x88, 0xff, 0xff, 0x43, 0x1, 0x81, 0x1, 0x2, 0x0, 0x2d, 0x0, 0xc0, 0xd3, 0x5b, 0x50, 0x0, 0x0, 0x0, 0x0, 0x8a, 0x85, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0}, Payload: []uint8{0x4}, }, ID: 0xffff88003b4a3800, EventType: USBEventTypeComplete, TransferType: USBTransportTypeInterrupt, Direction: 0x1, EndpointNumber: 0x1, DeviceAddress: 0x1, BusID: 0x2, TimestampSec: 1348195264, TimestampUsec: 689546, Setup: false, Data: true, Status: 0, UrbLength: 0x1, UrbDataLength: 0x1, } if !reflect.DeepEqual(got, want) { t.Errorf("USB packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }
func TestPacketDot11DataIP(t *testing.T) { p := gopacket.NewPacket(testPacketDot11DataIP, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11Data, LayerTypeLLC, LayerTypeSNAP, LayerTypeIPv4, LayerTypeUDP, gopacket.LayerTypePayload}, t) }
func TestPacketDot11DataARP(t *testing.T) { p := gopacket.NewPacket(testPacketDot11DataARP, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11Data, LayerTypeLLC, LayerTypeSNAP, LayerTypeARP}, t) if got, ok := p.Layer(LayerTypeARP).(*ARP); ok { want := &ARP{ BaseLayer: BaseLayer{ Contents: []uint8{0x0, 0x1, 0x8, 0x0, 0x6, 0x4, 0x0, 0x1, 0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52, 0xa9, 0xfe, 0xf7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x43, 0x8, 0xe, 0x36}, Payload: []uint8{}, }, AddrType: 0x1, Protocol: 0x800, HwAddressSize: 0x6, ProtAddressSize: 0x4, Operation: 0x1, SourceHwAddress: []uint8{0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52}, SourceProtAddress: []uint8{0xa9, 0xfe, 0xf7, 0x0}, DstHwAddress: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, DstProtAddress: []uint8{0x43, 0x8, 0xe, 0x36}, } if !reflect.DeepEqual(got, want) { t.Errorf("ARP packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }
func TestPacketIPSecESP(t *testing.T) { p := gopacket.NewPacket(testPacketIPSecESP, LinkTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecESP}, t) }
func TestPacketP6196(t *testing.T) { p := gopacket.NewPacket(testPacketP6196, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11WEP}, t) }
func TestPacketPrism(t *testing.T) { p := gopacket.NewPacket(testPacketPrism, LinkTypePrismHeader, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypePrismHeader, LayerTypeDot11, LayerTypeDot11MgmtProbeReq}, t) if got, ok := p.Layer(LayerTypePrismHeader).(*PrismHeader); ok { want := &PrismHeader{ BaseLayer: BaseLayer{ Contents: []uint8{0x44, 0x0, 0x0, 0x0, 0x90, 0x0, 0x0, 0x0, 0x72, 0x61, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x1, 0x0, 0x0, 0x0, 0x4, 0x0, 0xf9, 0xc1, 0x29, 0x0, 0x44, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x3, 0x0, 0x0, 0x0, 0x4, 0x0, 0xa, 0x0, 0x0, 0x0, 0x44, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0xe1, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x6, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x7, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x8, 0x0, 0x0, 0x0, 0x4, 0x0, 0x2, 0x0, 0x0, 0x0, 0x44, 0x0, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0xa, 0x0, 0x0, 0x0, 0x4, 0x0, 0x7e, 0x0, 0x0, 0x0}, Payload: []uint8{0x40, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x41, 0x0, 0x0, 0x1, 0x4, 0x2, 0x4, 0xb, 0x16, 0x32, 0x8, 0xc, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x1, 0x2d, 0x1a, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xdd, 0x9, 0x0, 0x10, 0x18, 0x2, 0x0, 0x0, 0x10, 0x0, 0x0, 0xdd, 0x1e, 0x0, 0x90, 0x4c, 0x33, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, Code: 0x44, Length: 0x90, DeviceName: "ra0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", Values: []PrismValue{ PrismValue{DID: PrismDIDType1HostTime, Status: 0x0, Length: 0x4, Data: []uint8{0xf9, 0xc1, 0x29, 0x0}}, PrismValue{DID: PrismDIDType1MACTime, Status: 0x0, Length: 0x0, Data: []uint8{}}, PrismValue{DID: PrismDIDType1Channel, Status: 0x0, Length: 0x4, Data: []uint8{0xa, 0x0, 0x0, 0x0}}, PrismValue{DID: PrismDIDType1RSSI, Status: 0x0, Length: 0x4, Data: []uint8{0xe1, 0xff, 0xff, 0xff}}, PrismValue{DID: 0x0, Status: 0x0, Length: 0x0, Data: []uint8{}}, PrismValue{DID: PrismDIDType1Signal, Status: 0x0, Length: 0x4, Data: []uint8{0x0, 0x0, 0x0, 0x0}}, PrismValue{DID: PrismDIDType1Noise, Status: 0x0, Length: 0x4, Data: []uint8{0x0, 0x0, 0x0, 0x0}}, PrismValue{DID: PrismDIDType1Rate, Status: 0x0, Length: 0x4, Data: []uint8{0x2, 0x0, 0x0, 0x0}}, PrismValue{DID: PrismDIDType1TransmittedFrameIndicator, Status: 0x0, Length: 0x0, Data: []uint8{}}, PrismValue{DID: PrismDIDType1FrameLength, Status: 0x0, Length: 0x4, Data: []uint8{0x7e, 0x0, 0x0, 0x0}}, }, } if !reflect.DeepEqual(got, want) { t.Errorf("RadioTap packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok { want := &Dot11{ BaseLayer: BaseLayer{ Contents: []uint8{0x40, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x41}, Payload: []uint8{0x0, 0x0, 0x1, 0x4, 0x2, 0x4, 0xb, 0x16, 0x32, 0x8, 0xc, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x1, 0x2d, 0x1a, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xdd, 0x9, 0x0, 0x10, 0x18, 0x2, 0x0, 0x0, 0x10, 0x0, 0x0, 0xdd, 0x1e, 0x0, 0x90, 0x4c, 0x33, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, }, Type: 0x10, Proto: 0x0, Flags: 0x0, DurationID: 0x0, Address1: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, Address2: net.HardwareAddr{0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8}, Address3: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, Address4: net.HardwareAddr(nil), SequenceNumber: 0x106, FragmentNumber: 0x20, Checksum: 0x0, } if !reflect.DeepEqual(got, want) { t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }
func TestPacketICMPv6(t *testing.T) { p := gopacket.NewPacket(testPacketICMPv6, LinkTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeICMPv6, gopacket.LayerTypePayload}, t) if got, ok := p.Layer(LayerTypeIPv6).(*IPv6); ok { want := &IPv6{ BaseLayer: BaseLayer{ Contents: []byte{0x60, 0x0, 0x0, 0x0, 0x0, 0x18, 0x3a, 0xff, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40}, Payload: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17}, }, Version: 6, TrafficClass: 0, FlowLabel: 0, Length: 24, NextHeader: IPProtocolICMPv6, HopLimit: 255, SrcIP: net.IP{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17}, DstIP: net.IP{0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40}, } if !reflect.DeepEqual(got, want) { t.Errorf("IPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } else { t.Error("No IPv6 layer type found in packet") } if got, ok := p.Layer(LayerTypeICMPv6).(*ICMPv6); ok { want := &ICMPv6{ BaseLayer: BaseLayer{ Contents: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0}, Payload: []byte{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17}, }, TypeCode: 0x8800, Checksum: 0x1ed6, TypeBytes: []byte{0x40, 0x0, 0x0, 0x0}, } if !reflect.DeepEqual(got, want) { t.Errorf("ICMPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } if got.TypeCode.String() != "NeighborAdvertisement(0)" { t.Errorf("ICMPv6 type code, got %q want 'NeighborAdvertisement(0)'", got.TypeCode.String()) } } else { t.Error("No ICMPv6 layer type found in packet") } }
func TestPacketRadiotap0(t *testing.T) { p := gopacket.NewPacket(testPacketRadiotap0, LayerTypeRadioTap, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t) rt := p.Layer(LayerTypeRadioTap).(*RadioTap) if rt.ChannelFrequency != 2412 || rt.DBMAntennaSignal != -58 || rt.Antenna != 7 { t.Error("Radiotap decode error") } if rt.Rate != 2 { // 500Kbps unit t.Error("Radiotap Rate decode error") } }
func loadDNS(dnspacket []byte, t *testing.T) *DNS { p := gopacket.NewPacket(dnspacket, LinkTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t) dnsL := p.Layer(LayerTypeDNS) if dnsL == nil { t.Error("No DNS Layer found") } dns, ok := dnsL.(*DNS) if !ok { return nil } return dns }
func TestInformationElement(t *testing.T) { bin := []byte{ 0, 0, 0, 2, 1, 3, 221, 5, 1, 2, 3, 4, 5, } pkt := gopacket.NewPacket(bin, LayerTypeDot11InformationElement, gopacket.NoCopy) buf := gopacket.NewSerializeBuffer() var sLayers []gopacket.SerializableLayer for _, l := range pkt.Layers() { sLayers = append(sLayers, l.(*Dot11InformationElement)) } if err := gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, sLayers...); err != nil { t.Error(err.Error()) } if !bytes.Equal(bin, buf.Bytes()) { t.Error("build failed") } }
func TestUDPPacketDNS(t *testing.T) { p := gopacket.NewPacket(testUDPPacketDNS, LinkTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t) if got, ok := p.TransportLayer().(*UDP); ok { want := &UDP{ BaseLayer: BaseLayer{ Contents: []byte{0x0, 0x35, 0x89, 0x6d, 0x0, 0xd2, 0x75, 0x4a}, Payload: []byte{0xb8, 0xd8, 0x81, 0x80, 0x0, 0x1, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x4, 0x78, 0x6b, 0x63, 0x64, 0x3, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0xf, 0x0, 0x1, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0x18, 0x0, 0x14, 0x4, 0x41, 0x4c, 0x54, 0x32, 0x5, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x1, 0x4c, 0x6, 0x47, 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0xc0, 0x11, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0x16, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x32, 0xa, 0x47, 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0x4d, 0x41, 0x49, 0x4c, 0xc0, 0x11, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x33, 0xc0, 0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x34, 0xc0, 0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x35, 0xc0, 0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0x4, 0x0, 0xa, 0xc0, 0x2d, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0x9, 0x0, 0x14, 0x4, 0x41, 0x4c, 0x54, 0x31, 0xc0, 0x2d}, }, SrcPort: 53, DstPort: 35181, Length: 210, Checksum: 30026, sPort: []byte{0x0, 0x35}, dPort: []byte{0x89, 0x6d}, } if !reflect.DeepEqual(got, want) { t.Errorf("UDP packet mismatch:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } else { t.Error("Transport layer packet not UDP") } }
func TestPacketDot11MgmtBeacon(t *testing.T) { p := gopacket.NewPacket(testPacketDot11MgmtBeacon, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtBeacon}, t) if got, ok := p.Layer(LayerTypeRadioTap).(*RadioTap); ok { want := &RadioTap{BaseLayer: BaseLayer{Contents: []uint8{0x0, 0x0, 0x20, 0x0, 0x67, 0x8, 0x4, 0x0, 0xe9, 0xa2, 0xfe, 0x25, 0x0, 0x0, 0x0, 0x0, 0x22, 0xc, 0xd8, 0xa0, 0x2, 0x0, 0x0, 0x0, 0x40, 0x1, 0x0, 0x0, 0x3c, 0x14, 0x24, 0x11}, Payload: []uint8{0x80, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xd0, 0x9b, 0x38, 0x40, 0x10, 0x28, 0x0, 0x0, 0x0, 0x0, 0x64, 0x0, 0x0, 0x5, 0x0, 0x0, 0x1, 0x8, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x24, 0x5, 0x4, 0x0, 0x1, 0x0, 0x0, 0x7, 0x2a, 0x55, 0x53, 0x20, 0x24, 0x1, 0x11, 0x28, 0x1, 0x11, 0x2c, 0x1, 0x11, 0x30, 0x1, 0x11, 0x34, 0x1, 0x17, 0x38, 0x1, 0x17, 0x3c, 0x1, 0x17, 0x40, 0x1, 0x17, 0x95, 0x1, 0x1e, 0x99, 0x1, 0x1e, 0x9d, 0x1, 0x1e, 0xa1, 0x1, 0x1e, 0xa5, 0x1, 0x1e, 0x20, 0x1, 0x0, 0xdd, 0x18, 0x0, 0x50, 0xf2, 0x2, 0x1, 0x1, 0x0, 0x0, 0x3, 0xa4, 0x0, 0x0, 0x27, 0xa4, 0x0, 0x0, 0x42, 0x43, 0x5e, 0x0, 0x62, 0x32, 0x2f, 0x0, 0x34, 0xc, 0x66, 0x72, 0x65, 0x65, 0x62, 0x73, 0x64, 0x2d, 0x6d, 0x65, 0x73, 0x68, 0x33, 0x17, 0x1, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xdf}}, Version: 0x0, Length: 0x20, Present: 0x40867, TSFT: 0x25fea2e9, Flags: 0x22, Rate: 0xc, ChannelFrequency: 0x0, ChannelFlags: 0x0, FHSS: 0x0, DBMAntennaSignal: -40, DBMAntennaNoise: -96, LockQuality: 0x0, TxAttenuation: 0x0, DBTxAttenuation: 0x0, DBMTxPower: 0, Antenna: 0x2, DBAntennaSignal: 0x0, DBAntennaNoise: 0x0} if !reflect.DeepEqual(got, want) { t.Errorf("RadioTap packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok { want := &Dot11{ BaseLayer: BaseLayer{ Contents: []uint8{0x80, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xd0, 0x9b}, Payload: []uint8{0x38, 0x40, 0x10, 0x28, 0x0, 0x0, 0x0, 0x0, 0x64, 0x0, 0x0, 0x5, 0x0, 0x0, 0x1, 0x8, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x24, 0x5, 0x4, 0x0, 0x1, 0x0, 0x0, 0x7, 0x2a, 0x55, 0x53, 0x20, 0x24, 0x1, 0x11, 0x28, 0x1, 0x11, 0x2c, 0x1, 0x11, 0x30, 0x1, 0x11, 0x34, 0x1, 0x17, 0x38, 0x1, 0x17, 0x3c, 0x1, 0x17, 0x40, 0x1, 0x17, 0x95, 0x1, 0x1e, 0x99, 0x1, 0x1e, 0x9d, 0x1, 0x1e, 0xa1, 0x1, 0x1e, 0xa5, 0x1, 0x1e, 0x20, 0x1, 0x0, 0xdd, 0x18, 0x0, 0x50, 0xf2, 0x2, 0x1, 0x1, 0x0, 0x0, 0x3, 0xa4, 0x0, 0x0, 0x27, 0xa4, 0x0, 0x0, 0x42, 0x43, 0x5e, 0x0, 0x62, 0x32, 0x2f, 0x0, 0x34, 0xc, 0x66, 0x72, 0x65, 0x65, 0x62, 0x73, 0x64, 0x2d, 0x6d, 0x65, 0x73, 0x68, 0x33, 0x17, 0x1, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf}, }, Type: Dot11TypeMgmtBeacon, Proto: 0x0, Flags: 0x0, DurationID: 0x0, Address1: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, Address2: net.HardwareAddr{0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16}, Address3: net.HardwareAddr{0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, Address4: net.HardwareAddr(nil), SequenceNumber: 0x26f, FragmentNumber: 0x10, Checksum: 0xdf00ffac, } if !reflect.DeepEqual(got, want) { t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }
func TestDecodeUDPSFlow(t *testing.T) { p := gopacket.NewPacket(SFlowTestPacket1, LayerTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t) if got, ok := p.TransportLayer().(*UDP); ok { want := &UDP{ BaseLayer: BaseLayer{SFlowTestPacket1[34:42], SFlowTestPacket1[42:]}, sPort: []byte{199, 87}, dPort: []byte{24, 199}, SrcPort: 51031, DstPort: 6343, Checksum: 8763, Length: 1448, } if !reflect.DeepEqual(want, got) { t.Errorf("UDP layer mismatch, \nwant %#v\ngot %#v\n", want, got) } } else { t.Error("Transport layer packet not UDP") } }
func TestPacketDot11MgmtAction(t *testing.T) { p := gopacket.NewPacket(testPacketDot11MgmtAction, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtAction}, t) want := `PACKET: 97 bytes - Layer 1 (32 bytes) = RadioTap {Contents=[..32..] Payload=[..65..] Version=0 Length=32 Present=264295 TSFT=634199967 Flags=SHORT-PREAMBLE,DATAPAD Rate=6 Mb/s ChannelFrequency=0 MHz ChannelFlags= FHSS=0 DBMAntennaSignal=-41 DBMAntennaNoise=-96 LockQuality=0 TxAttenuation=0 DBTxAttenuation=0 DBMTxPower=0 Antenna=1 DBAntennaSignal=0 DBAntennaNoise=0} - Layer 2 (24 bytes) = Dot11 {Contents=[..24..] Payload=[..37..] Type=MgmtAction Proto=0 Flags= DurationID=0 Address1=ff:ff:ff:ff:ff:ff Address2=00:03:7f:07:a0:16 Address3=00:03:7f:07:a0:16 Address4= SequenceNumber=10 FragmentNumber=32 Checksum=0} - Layer 3 (37 bytes) = Dot11MgmtAction {Contents=[..37..] Payload=[]} ` if got := p.String(); got != want { t.Errorf("packet string mismatch:\n---got---\n%q\n---want---\n%q", got, want) } if _, ok := p.Layer(LayerTypeDot11).(*Dot11); !ok { t.Errorf("could not get Dot11 layer from packet") } else { // See note above: this checksum fails most likely due to datapad. // wireshark also says this packet is malformed, so I'm not going to waste // too much more time on it. // if !got.ChecksumValid() { t.Errorf("Dot11 packet processing failed: checksum failed") } } }
func BenchmarkDecodePacketDot11CtrlCTS(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testPacketDot11CtrlCTS, LinkTypeIEEE80211Radio, gopacket.NoCopy) } }
func BenchmarkDecodePacketPrism(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testPacketPrism, LinkTypePrismHeader, gopacket.NoCopy) } }
func TestPacketPacket0(t *testing.T) { p := gopacket.NewPacket(SFlowTestPacket2, LinkTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t) if got, ok := p.ApplicationLayer().(*SFlowDatagram); ok { want := &SFlowDatagram{ DatagramVersion: uint32(5), AgentAddress: []byte{192, 168, 91, 17}, SubAgentID: uint32(0), SequenceNumber: uint32(46394), AgentUptime: uint32(52000), SampleCount: uint32(3), FlowSamples: []SFlowFlowSample{ SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 340, SequenceNumber: 139118, SourceIDClass: 0, SourceIDIndex: 3, SamplingRate: 1, SamplePool: 139118, Dropped: 0, InputInterface: 3, OutputInterface: 1073741823, RecordCount: 4, Records: []SFlowRecord{ SFlowExtendedURLRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1005, FlowDataLength: 48, }, Direction: SFlowURLsrc, URL: "http://www.sflow.org", Host: "host1.sflow.org", }, SFlowExtendedUserFlow{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1004, FlowDataLength: 44, }, SourceCharSet: SFlowCSUTF8, SourceUserID: "source user", DestinationCharSet: SFlowCSUTF8, DestinationUserID: "destination user", }, SFlowExtendedGatewayFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1003, FlowDataLength: 100, }, NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a}, AS: 65001, SourceAS: 123, PeerAS: 999, ASPathCount: 3, ASPath: []SFlowASDestination{ SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{123, 456, 789}, }, SFlowASDestination{ Type: SFlowASSet, Count: 3, Members: []uint32{11111, 22222, 33333}, }, SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{777, 888, 999}, }, }, Communities: []uint32{12, 13}, LocalPref: 432, }, SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 84, }, HeaderProtocol: 1, FrameLength: 70, PayloadRemoved: 4, HeaderLength: 0x42, Header: gopacket.NewPacket(SFlowTestPacket2[350:418], LayerTypeEthernet, gopacket.Default), }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 400, SequenceNumber: 139119, SourceIDClass: 0, SourceIDIndex: 3, SamplingRate: 1, SamplePool: 139119, Dropped: 0, InputInterface: 1073741823, OutputInterface: 3, RecordCount: 4, Records: []SFlowRecord{ SFlowExtendedURLRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1005, FlowDataLength: 48, }, Direction: SFlowURLsrc, URL: "http://www.sflow.org", Host: "host1.sflow.org", }, SFlowExtendedUserFlow{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1004, FlowDataLength: 44, }, SourceCharSet: SFlowCSUTF8, SourceUserID: "source user", DestinationCharSet: SFlowCSUTF8, DestinationUserID: "destination user", }, SFlowExtendedGatewayFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1003, FlowDataLength: 100, }, NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a}, AS: 65001, SourceAS: 123, PeerAS: 999, ASPathCount: 3, ASPath: []SFlowASDestination{ SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{123, 456, 789}, }, SFlowASDestination{ Type: SFlowASSet, Count: 3, Members: []uint32{11111, 22222, 33333}, }, SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{777, 888, 999}, }, }, Communities: []uint32{12, 13}, LocalPref: 432, }, SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 144, }, HeaderProtocol: 1, FrameLength: 390, PayloadRemoved: 4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket2[698:826], LayerTypeEthernet, gopacket.Default), }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 340, SequenceNumber: 139120, SourceIDClass: 0, SourceIDIndex: 3, SamplingRate: 1, SamplePool: 139120, Dropped: 0, InputInterface: 3, OutputInterface: 1073741823, RecordCount: 4, Records: []SFlowRecord{ SFlowExtendedURLRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1005, FlowDataLength: 48, }, Direction: SFlowURLsrc, URL: "http://www.sflow.org", Host: "host1.sflow.org", }, SFlowExtendedUserFlow{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1004, FlowDataLength: 44, }, SourceCharSet: SFlowCSUTF8, SourceUserID: "source user", DestinationCharSet: SFlowCSUTF8, DestinationUserID: "destination user", }, SFlowExtendedGatewayFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0, Format: 1003, FlowDataLength: 100, }, NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a}, AS: 65001, SourceAS: 123, PeerAS: 999, ASPathCount: 3, ASPath: []SFlowASDestination{ SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{123, 456, 789}, }, SFlowASDestination{ Type: SFlowASSet, Count: 3, Members: []uint32{11111, 22222, 33333}, }, SFlowASDestination{ Type: SFlowASSequence, Count: 3, Members: []uint32{777, 888, 999}, }, }, Communities: []uint32{12, 13}, LocalPref: 432, }, SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 84, }, HeaderProtocol: 1, FrameLength: 70, PayloadRemoved: 4, HeaderLength: 0x42, Header: gopacket.NewPacket(SFlowTestPacket2[1106:1174], LayerTypeEthernet, gopacket.Default), }, }, }, }, } if !reflect.DeepEqual(want, got) { t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got) } } else { t.Error("Application layer packet not UDP") } }
func BenchmarkDecodePacketRadiotap0(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testPacketRadiotap0, LayerTypeRadioTap, gopacket.NoCopy) } }
func TestDecodeSFlowDatagram(t *testing.T) { p := gopacket.NewPacket(SFlowTestPacket1, LayerTypeEthernet, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t) if got, ok := p.ApplicationLayer().(*SFlowDatagram); ok { want := &SFlowDatagram{ DatagramVersion: uint32(5), AgentAddress: []byte{0xa, 0x1, 0xf8, 0x16}, SubAgentID: uint32(17), SequenceNumber: uint32(40443), AgentUptime: uint32(1078576845), SampleCount: uint32(7), FlowSamples: []SFlowFlowSample{ SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0xd0, SequenceNumber: 0x2627e8, SourceIDClass: 0x0, SourceIDIndex: 0x213, SamplingRate: 0x3e80, SamplePool: 0x50bde580, Dropped: 0x0, InputInterface: 0x213, OutputInterface: 0x0, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x90, }, HeaderProtocol: 0x1, FrameLength: 0x5d2, PayloadRemoved: 0x4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket1[134:262], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x0, OutgoingVLANPriority: 0x0, }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0xd0, SequenceNumber: 0x15e5c1e, SourceIDClass: 0x0, SourceIDIndex: 0x257, SamplingRate: 0x7d0, SamplePool: 0xb12fa290, Dropped: 0x0, InputInterface: 0x257, OutputInterface: 0x0, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x90, }, HeaderProtocol: 0x1, FrameLength: 0x5ee, PayloadRemoved: 0x4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket1[350:478], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x0, OutgoingVLANPriority: 0x0, }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0xd0, SequenceNumber: 0x15acdd0, SourceIDClass: 0x0, SourceIDIndex: 0x255, SamplingRate: 0x7d0, SamplePool: 0x9567e130, Dropped: 0x0, InputInterface: 0x255, OutputInterface: 0x0, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x90, }, HeaderProtocol: 0x1, FrameLength: 0x446, PayloadRemoved: 0x4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket1[566:694], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x0, OutgoingVLANPriority: 0x0, }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0xd0, SequenceNumber: 0x15e5c1f, SourceIDClass: 0x0, SourceIDIndex: 0x257, SamplingRate: 0x7d0, SamplePool: 0xb12faa60, Dropped: 0x0, InputInterface: 0x257, OutputInterface: 0x0, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x90, }, HeaderProtocol: 0x1, FrameLength: 0x5ee, PayloadRemoved: 0x4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket1[958:1086], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x0, OutgoingVLANPriority: 0x0, }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0xd0, SequenceNumber: 0x15acdd1, SourceIDClass: 0x0, SourceIDIndex: 0x255, SamplingRate: 0x7d0, SamplePool: 0x9567e900, Dropped: 0x0, InputInterface: 0x255, OutputInterface: 0x257, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x90, }, HeaderProtocol: 0x1, FrameLength: 0x5ee, PayloadRemoved: 0x4, HeaderLength: 0x80, Header: gopacket.NewPacket(SFlowTestPacket1[1174:1302], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x202, OutgoingVLANPriority: 0x0, }, }, }, SFlowFlowSample{ EnterpriseID: 0x0, Format: 0x1, SampleLength: 0x94, SequenceNumber: 0x15e5c20, SourceIDClass: 0x0, SourceIDIndex: 0x257, SamplingRate: 0x7d0, SamplePool: 0xb12fb230, Dropped: 0x0, InputInterface: 0x257, OutputInterface: 0x0, RecordCount: 0x2, Records: []SFlowRecord{ SFlowRawPacketFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x54, }, HeaderProtocol: 0x1, FrameLength: 0x46, PayloadRemoved: 0x4, HeaderLength: 0x42, Header: gopacket.NewPacket(SFlowTestPacket1[1390:1458], LayerTypeEthernet, gopacket.Default), }, SFlowExtendedSwitchFlowRecord{ SFlowBaseFlowRecord: SFlowBaseFlowRecord{ EnterpriseID: 0x0, Format: 0x3e9, FlowDataLength: 0x10, }, IncomingVLAN: 0x202, IncomingVLANPriority: 0x0, OutgoingVLAN: 0x0, OutgoingVLANPriority: 0x0, }, }, }, }, CounterSamples: []SFlowCounterSample{ SFlowCounterSample{ Format: 0x2, SampleLength: 0xa8, SequenceNumber: 0x20f2, SourceIDClass: 0x0, SourceIDIndex: 0x20a, RecordCount: 0x2, Records: []SFlowRecord{ SFlowGenericInterfaceCounters{ SFlowBaseCounterRecord: SFlowBaseCounterRecord{ EnterpriseID: 0x0, Format: 0x1, FlowDataLength: 0x58, }, IfIndex: 0x20a, IfType: 0x6, IfSpeed: 0x2540be400, IfDirection: 0x1, IfStatus: 0x3, IfInOctets: 0x129826db06c0b, IfInUcastPkts: 0xcb0ddd96, IfInMulticastPkts: 0x6a8c6, IfInBroadcastPkts: 0x7b, IfInDiscards: 0x0, IfInErrors: 0x0, IfInUnknownProtos: 0x0, IfOutOctets: 0x340235587c9e, IfOutUcastPkts: 0x56642571, IfOutMulticastPkts: 0x705ac4, IfOutBroadcastPkts: 0x908f1, IfOutDiscards: 0x0, IfOutErrors: 0x0, IfPromiscuousMode: 0x0, }, SFlowEthernetCounters{ SFlowBaseCounterRecord: SFlowBaseCounterRecord{ EnterpriseID: 0x0, Format: 0x2, FlowDataLength: 0x34, }, AlignmentErrors: 0x0, FCSErrors: 0x0, SingleCollisionFrames: 0x0, MultipleCollisionFrames: 0x0, SQETestErrors: 0x0, DeferredTransmissions: 0x0, LateCollisions: 0x0, ExcessiveCollisions: 0x0, InternalMacTransmitErrors: 0x0, CarrierSenseErrors: 0x0, FrameTooLongs: 0x0, InternalMacReceiveErrors: 0x0, SymbolErrors: 0x0, }, }, }, }, } if !reflect.DeepEqual(want, got) { t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got) } } else { t.Error("Application layer packet not UDP") } }
func BenchmarkDecodePacketUSB0(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.NoCopy) } }
func BenchmarkDecodeSFlowPacket2(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(SFlowTestPacket2, LinkTypeEthernet, gopacket.NoCopy) } }
func BenchmarkDecodeDNS(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testDNSQueryA, LinkTypeEthernet, gopacket.NoCopy) } }
func BenchmarkDecodePacketIPSecESP(b *testing.B) { for i := 0; i < b.N; i++ { gopacket.NewPacket(testPacketIPSecESP, LinkTypeEthernet, gopacket.NoCopy) } }
func TestPacketDot11CtrlCTS(t *testing.T) { p := gopacket.NewPacket(testPacketDot11CtrlCTS, LinkTypeIEEE80211Radio, gopacket.Default) if p.ErrorLayer() != nil { t.Error("Failed to decode packet:", p.ErrorLayer().Error()) } checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t) if got, ok := p.Layer(LayerTypeRadioTap).(*RadioTap); ok { want := &RadioTap{ BaseLayer: BaseLayer{ Contents: []uint8{0x0, 0x0, 0x19, 0x0, 0x6f, 0x8, 0x0, 0x0, 0x37, 0x68, 0x3a, 0x1, 0x0, 0x0, 0x0, 0x0, 0x12, 0x30, 0x78, 0x14, 0x40, 0x1, 0xb1, 0xa4, 0x1}, Payload: []uint8{0xc4, 0x0, 0x94, 0x0, 0xd8, 0xa2, 0x5e, 0x97, 0x61, 0xc1, 0x36, 0x50, 0x95, 0x8e}, }, Version: 0x0, Length: 0x19, Present: 0x86f, TSFT: 0x13a6837, Flags: 0x12, Rate: 0x30, ChannelFrequency: 0x1478, ChannelFlags: 0x140, FHSS: 0x0, DBMAntennaSignal: -79, DBMAntennaNoise: -92, LockQuality: 0x0, TxAttenuation: 0x0, DBTxAttenuation: 0x0, DBMTxPower: 0, Antenna: 1, DBAntennaSignal: 0x0, DBAntennaNoise: 0x0, } if !reflect.DeepEqual(got, want) { t.Errorf("RadioTap packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok { if !got.ChecksumValid() { t.Errorf("Dot11 packet processing failed:\nchecksum failed. got :\n%#v\n\n", got) } want := &Dot11{ BaseLayer: BaseLayer{ Contents: []uint8{0xc4, 0x0, 0x94, 0x0, 0xd8, 0xa2, 0x5e, 0x97, 0x61, 0xc1}, Payload: []uint8{}, }, Type: Dot11TypeCtrlCTS, Proto: 0x0, Flags: 0x0, DurationID: 0x94, Address1: net.HardwareAddr{0xd8, 0xa2, 0x5e, 0x97, 0x61, 0xc1}, // check Address2: net.HardwareAddr(nil), Address3: net.HardwareAddr(nil), Address4: net.HardwareAddr(nil), Checksum: 0x8e955036, } if !reflect.DeepEqual(got, want) { t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want) } } }