func init() { LayerTypeMachTop = gopacket.RegisterLayerType(11000, gopacket.LayerTypeMetadata{"MachTop", gopacket.DecodeFunc(decodeMach)}) LayerTypeMach = gopacket.RegisterLayerType(11001, gopacket.LayerTypeMetadata{"Mach", gopacket.DecodeFunc(decodeMach)}) MachTopLayerFactory = packet.NewSingleDecodingLayerFactory( LayerTypeMachTop, func() gopacket.DecodingLayer { return &MachTop{} }, ) MachLayerFactory = packet.NewSingleDecodingLayerFactory( LayerTypeMach, func() gopacket.DecodingLayer { return &Mach{} }, ) }
func init() { LayerTypeMoldUDP64MessageBlock = gopacket.RegisterLayerType(10001, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlock", gopacket.DecodeFunc(decodeMoldUDP64MessageBlock)}) LayerTypeMoldUDP64MessageBlockChained = gopacket.RegisterLayerType(10003, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlockChained", gopacket.DecodeFunc(decodeMoldUDP64MessageBlockChained)}) MoldUDP64LayerFactory = packet.NewSingleDecodingLayerFactory( LayerTypeMoldUDP64, func() gopacket.DecodingLayer { return &MoldUDP64{} }, ) MoldUDP64MessageBlockLayerFactory = packet.NewSingleDecodingLayerFactory( LayerTypeMoldUDP64MessageBlock, func() gopacket.DecodingLayer { return &MoldUDP64MessageBlock{} }, ) }
func init() { layerTypes := make([]gopacket.LayerType, 0, 256) for i := 0; i < 256; i++ { if TomMessageTypeNames[i] == "" { continue } tomMessageType := TomMessageType(i) layerTypeMetadata := gopacket.LayerTypeMetadata{ Name: TomMessageTypeNames[i], Decoder: tomMessageType, } layerType := gopacket.RegisterLayerType(TOM_LAYERS_BASE_NUM+i, layerTypeMetadata) layerTypes = append(layerTypes, layerType) creator := TomMessageCreators[i] createLayer := func() TomMessage { m := creator() m.Base().Type = tomMessageType return m } TomMessageTypeMetadata[i] = EnumMessageTypeMetadata{ Name: TomMessageTypeNames[i], LayerType: layerType, CreateLayer: createLayer, } } for i := 0; i < 256; i++ { if TomMessageTypeMetadata[i].Name == "" { // unknown message type TomMessageTypeMetadata[i] = TomMessageTypeMetadata[TomMessageTypeUnknown] } } LayerClassTom = gopacket.NewLayerClass(layerTypes) }
func init() { layerTypes := make([]gopacket.LayerType, 0, 256) for i := 0; i < 256; i++ { if IttoMessageTypeNames[i] == "" { continue } ittoMessageType := IttoMessageType(i) layerTypeMetadata := gopacket.LayerTypeMetadata{ Name: IttoMessageTypeNames[i], Decoder: ittoMessageType, } layerType := gopacket.RegisterLayerType(ITTO_LAYERS_BASE_NUM+i, layerTypeMetadata) layerTypes = append(layerTypes, layerType) creator := IttoMessageCreators[i] createLayer := func() IttoMessage { m := creator() m.Base().Type = ittoMessageType return m } IttoMessageTypeMetadata[i] = EnumMessageTypeMetadata{ Name: IttoMessageTypeNames[i], IsShort: IttoMessageIsShort[i], LayerType: layerType, CreateLayer: createLayer, } } for i := 0; i < 256; i++ { if IttoMessageTypeMetadata[i].Name == "" { // unknown message type IttoMessageTypeMetadata[i] = IttoMessageTypeMetadata[IttoMessageTypeUnknown] } } LayerClassItto = gopacket.NewLayerClass(layerTypes) }
// Copyright 2012 Google, gopacket.LayerTypeMetadata{Inc. All rights reserved}. // // Use of this source code is governed by a BSD-style license // that can be found in the LICENSE file in the root of the source // tree. package layers import ( "github.com/google/gopacket" ) var ( LayerTypeARP = gopacket.RegisterLayerType(10, gopacket.LayerTypeMetadata{Name: "ARP", Decoder: gopacket.DecodeFunc(decodeARP)}) LayerTypeCiscoDiscovery = gopacket.RegisterLayerType(11, gopacket.LayerTypeMetadata{Name: "CiscoDiscovery", Decoder: gopacket.DecodeFunc(decodeCiscoDiscovery)}) LayerTypeEthernetCTP = gopacket.RegisterLayerType(12, gopacket.LayerTypeMetadata{Name: "EthernetCTP", Decoder: gopacket.DecodeFunc(decodeEthernetCTP)}) LayerTypeEthernetCTPForwardData = gopacket.RegisterLayerType(13, gopacket.LayerTypeMetadata{Name: "EthernetCTPForwardData", Decoder: nil}) LayerTypeEthernetCTPReply = gopacket.RegisterLayerType(14, gopacket.LayerTypeMetadata{Name: "EthernetCTPReply", Decoder: nil}) LayerTypeDot1Q = gopacket.RegisterLayerType(15, gopacket.LayerTypeMetadata{Name: "Dot1Q", Decoder: gopacket.DecodeFunc(decodeDot1Q)}) LayerTypeEtherIP = gopacket.RegisterLayerType(16, gopacket.LayerTypeMetadata{Name: "EtherIP", Decoder: gopacket.DecodeFunc(decodeEtherIP)}) LayerTypeEthernet = gopacket.RegisterLayerType(17, gopacket.LayerTypeMetadata{Name: "Ethernet", Decoder: gopacket.DecodeFunc(decodeEthernet)}) LayerTypeGRE = gopacket.RegisterLayerType(18, gopacket.LayerTypeMetadata{Name: "GRE", Decoder: gopacket.DecodeFunc(decodeGRE)}) LayerTypeICMPv4 = gopacket.RegisterLayerType(19, gopacket.LayerTypeMetadata{Name: "ICMPv4", Decoder: gopacket.DecodeFunc(decodeICMPv4)}) LayerTypeIPv4 = gopacket.RegisterLayerType(20, gopacket.LayerTypeMetadata{Name: "IPv4", Decoder: gopacket.DecodeFunc(decodeIPv4)}) LayerTypeIPv6 = gopacket.RegisterLayerType(21, gopacket.LayerTypeMetadata{Name: "IPv6", Decoder: gopacket.DecodeFunc(decodeIPv6)}) LayerTypeLLC = gopacket.RegisterLayerType(22, gopacket.LayerTypeMetadata{Name: "LLC", Decoder: gopacket.DecodeFunc(decodeLLC)}) LayerTypeSNAP = gopacket.RegisterLayerType(23, gopacket.LayerTypeMetadata{Name: "SNAP", Decoder: gopacket.DecodeFunc(decodeSNAP)}) LayerTypeMPLS = gopacket.RegisterLayerType(24, gopacket.LayerTypeMetadata{Name: "MPLS", Decoder: gopacket.DecodeFunc(decodeMPLS)}) LayerTypePPP = gopacket.RegisterLayerType(25, gopacket.LayerTypeMetadata{Name: "PPP", Decoder: gopacket.DecodeFunc(decodePPP)}) LayerTypePPPoE = gopacket.RegisterLayerType(26, gopacket.LayerTypeMetadata{Name: "PPPoE", Decoder: gopacket.DecodeFunc(decodePPPoE)}) LayerTypeRUDP = gopacket.RegisterLayerType(27, gopacket.LayerTypeMetadata{Name: "RUDP", Decoder: gopacket.DecodeFunc(decodeRUDP)})
// Copyright (c) Ilia Kravets, 2015. All rights reserved. PROVIDED "AS IS" // WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. See LICENSE file for details. package miax import ( "encoding/binary" "time" "github.com/google/gopacket" "github.com/ikravets/errs" "my/ev/packet" ) var LayerTypeTom = gopacket.RegisterLayerType(11002, gopacket.LayerTypeMetadata{"Tom", gopacket.DecodeFunc(decodeTom)}) func decodeTom(data []byte, p gopacket.PacketBuilder) error { tomMessageType := TomMessageType(data[0]) return tomMessageType.Decode(data, p) } /************************************************************************/ type TomSide struct { Price packet.Price Size int PriorityCustomerSize int Condition byte Side packet.MarketSide // inferred from message type }
// Copyright (c) Ilia Kravets, 2015. All rights reserved. PROVIDED "AS IS" // WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. See LICENSE file for details. package bats import ( "encoding/binary" "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/ikravets/errs" "my/ev/packet" ) var LayerTypeBSU = gopacket.RegisterLayerType(12000, gopacket.LayerTypeMetadata{"BatsSequencedUnit", nil /*FIXME*/}) type BSU struct { layers.BaseLayer Length uint16 Count uint8 Unit uint8 Sequence uint32 tps []packet.TypedPayload } var ( _ packet.DecodingMultiLayer = &BSU{} _ gopacket.Layer = &BSU{} _ gopacket.DecodingLayer = &BSU{} )
package bats import ( "encoding/binary" "errors" "github.com/google/gopacket" "github.com/ikravets/errs" "my/ev/packet" ) /************************************************************************/ var LayerTypePitch = gopacket.RegisterLayerType(12001, gopacket.LayerTypeMetadata{"Pitch", gopacket.DecodeFunc(decodePitch)}) func decodePitch(data []byte, p gopacket.PacketBuilder) error { if len(data) < 2 { return errors.New("message to short") } pitchMessageType := PitchMessageType(data[1]) return pitchMessageType.Decode(data, p) } /************************************************************************/ type PitchMessageType uint8 func (a PitchMessageType) Decode(data []byte, p gopacket.PacketBuilder) error { layer := PitchMessageTypeMetadata[a].CreateLayer() if err := layer.DecodeFromBytes(data, p); err != nil {
package nasdaq import ( "bytes" "encoding/binary" "fmt" "time" "github.com/google/gopacket" "github.com/ikravets/errs" "my/ev/packet" ) var LayerTypeItto = gopacket.RegisterLayerType(10002, gopacket.LayerTypeMetadata{"Itto", gopacket.DecodeFunc(decodeItto)}) func decodeItto(data []byte, p gopacket.PacketBuilder) error { ittoMessageType := IttoMessageType(data[0]) return ittoMessageType.Decode(data, p) } /************************************************************************/ type OrderSide struct { Side packet.MarketSide RefNumD packet.OrderId Price packet.Price Size int } type ReplaceOrderSide struct {
layers.MPLSPayloadDecoder = gopacket.DecodeFunc(decodeMPLS) layers.EthernetTypeMetadata[ethernetTypeDot1QSTag] = layers.EthernetTypeMetadata[layers.EthernetTypeDot1Q] layers.EthernetTypeMetadata[ethernetTypeDot1QITag] = layers.EnumMetadata{ DecodeWith: gopacket.DecodeFunc(decodePBB), Name: "PBB", LayerType: LayerTypePBB, } layers.EthernetTypeMetadata[ethernetTypeLwapp] = layers.EnumMetadata{ DecodeWith: gopacket.DecodeFunc(decodeLwapp), Name: "Lwapp", LayerType: LayerTypeLwapp, } } var ( LayerTypePBB = gopacket.RegisterLayerType(500, gopacket.LayerTypeMetadata{"PBB", gopacket.DecodeFunc(decodePBB)}) LayerTypeLwapp = gopacket.RegisterLayerType(501, gopacket.LayerTypeMetadata{"Lwapp", gopacket.DecodeFunc(decodeLwapp)}) LayerTypeLwappControl = gopacket.RegisterLayerType(502, gopacket.LayerTypeMetadata{"LwappControl", gopacket.DecodeFunc(decodeLwappControl)}) LayerTypeCapwapControl = gopacket.RegisterLayerType(503, gopacket.LayerTypeMetadata{"CapwapControl", gopacket.DecodeFunc(decodeCapwapControl)}) LayerTypeCapwapData = gopacket.RegisterLayerType(504, gopacket.LayerTypeMetadata{"CapwapData", gopacket.DecodeFunc(decodeCapwapData)}) LayerTypeCapwapControlHeader = gopacket.RegisterLayerType(505, gopacket.LayerTypeMetadata{"CapwapControlHeader", gopacket.DecodeFunc(decodeCapwapControlHeader)}) LayerTypeCapwapDataKeepAlive = gopacket.RegisterLayerType(506, gopacket.LayerTypeMetadata{"CapwapDataKeepAlive", gopacket.DecodeFunc(decodeCapwapDataKeepAlive)}) LayerTypeDot11NoFCS = gopacket.RegisterLayerType(507, gopacket.LayerTypeMetadata{"Dot11NoFCS", gopacket.DecodeFunc(decodeDot11NoFCS)}) ) func decodeMPLS(data []byte, p gopacket.PacketBuilder) error { g := layers.ProtocolGuessingDecoder{} if err := g.Decode(data, p); err != nil { return gopacket.DecodePayload.Decode(data, p) } return nil
// by Kelly Lauren-Summer Becker-Neuding <*****@*****.**>, 2015 package packet import ( "encoding/binary" "fmt" "strconv" "github.com/google/gopacket" "github.com/google/gopacket/layers" ) // LayerTypeUDP is a extensible UDP packet LayerType var LayerTypeUDP = gopacket.RegisterLayerType(1045, gopacket.LayerTypeMetadata{ Name: "UDP", Decoder: gopacket.DecodeFunc(decodeUDP), }) // Replace the UDP Packet handler with out new custom one. func init() { layers.IPProtocolMetadata[layers.IPProtocolUDP] = layers.EnumMetadata{ DecodeWith: gopacket.DecodeFunc(decodeUDP), Name: "UDP", LayerType: LayerTypeUDP, } } // UDP is the layer for UDP headers. type UDP struct { layers.BaseLayer SrcPort, DstPort UDPPort Length uint16
* KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package flow import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" ) // Create a layer type, should be unique and high, so it doesn't conflict, // giving it a name and a decoder to use. var LayerTypeInGRE = gopacket.RegisterLayerType(55555, gopacket.LayerTypeMetadata{Name: "LayerTypeInGRE", Decoder: gopacket.DecodeFunc(decodeInGRELayer)}) type InGRELayer struct { StrangeHeader []byte payload []byte } func (m InGRELayer) LayerType() gopacket.LayerType { return LayerTypeInGRE } func (m InGRELayer) LayerContents() []byte { return m.StrangeHeader } func (m InGRELayer) LayerPayload() []byte {
"encoding/binary" "errors" "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/ikravets/errs" "my/ev/packet" ) var EndpointMoldUDP64SessionMetadata = gopacket.EndpointTypeMetadata{"MoldUDP64", func(b []byte) string { return string(b[:10]) }} var EndpointMoldUDP64Session = gopacket.RegisterEndpointType(10000, EndpointMoldUDP64SessionMetadata) var LayerTypeMoldUDP64 = gopacket.RegisterLayerType(10000, gopacket.LayerTypeMetadata{"MoldUDP64", gopacket.DecodeFunc(decodeMoldUDP64)}) // must initialize in init() to avoid false detection of potential initialization loop var LayerTypeMoldUDP64MessageBlock gopacket.LayerType var LayerTypeMoldUDP64MessageBlockChained gopacket.LayerType var MoldUDP64LayerFactory, MoldUDP64MessageBlockLayerFactory packet.DecodingLayerFactory func init() { LayerTypeMoldUDP64MessageBlock = gopacket.RegisterLayerType(10001, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlock", gopacket.DecodeFunc(decodeMoldUDP64MessageBlock)}) LayerTypeMoldUDP64MessageBlockChained = gopacket.RegisterLayerType(10003, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlockChained", gopacket.DecodeFunc(decodeMoldUDP64MessageBlockChained)}) MoldUDP64LayerFactory = packet.NewSingleDecodingLayerFactory( LayerTypeMoldUDP64, func() gopacket.DecodingLayer { return &MoldUDP64{} },
// Create custom layer structure type CustomLayer struct { // This layer just has two bytes at the front SomeByte byte AnotherByte byte restOfData []byte } // Register the layer type so we can use it // The first argument is an ID. Use negative // or 2000+ for custom layers. It must be unique var CustomLayerType = gopacket.RegisterLayerType( 2001, gopacket.LayerTypeMetadata{ "CustomLayerType", gopacket.DecodeFunc(decodeCustomLayer), }, ) // When we inquire about the type, what type of layer should // we say it is? We want it to return our custom layer type func (l CustomLayer) LayerType() gopacket.LayerType { return CustomLayerType } // LayerContents returns the information that our layer // provides. In this case it is a header layer so // we return the header information func (l CustomLayer) LayerContents() []byte { return []byte{l.SomeByte, l.AnotherByte}