1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
10 "github.com/google/gopacket"
13 // BaseLayer is a convenience struct which implements the LayerData and
14 // LayerPayload functions of the Layer interface.
15 type BaseLayer struct {
16 // Contents is the set of bytes that make up this layer. IE: for an
17 // Ethernet packet, this would be the set of bytes making up the
20 // Payload is the set of bytes contained by (but not part of) this
21 // Layer. Again, to take Ethernet as an example, this would be the
22 // set of bytes encapsulated by the Ethernet protocol.
26 // LayerContents returns the bytes of the packet layer.
27 func (b *BaseLayer) LayerContents() []byte { return b.Contents }
29 // LayerPayload returns the bytes contained within the packet layer.
30 func (b *BaseLayer) LayerPayload() []byte { return b.Payload }
32 type layerDecodingLayer interface {
34 DecodeFromBytes([]byte, gopacket.DecodeFeedback) error
35 NextLayerType() gopacket.LayerType
38 func decodingLayerDecoder(d layerDecodingLayer, data []byte, p gopacket.PacketBuilder) error {
39 err := d.DecodeFromBytes(data, p)
44 next := d.NextLayerType()
45 if next == gopacket.LayerTypeZero {
48 return p.NextDecoder(next)
51 // hacky way to zero out memory... there must be a better way?
52 var lotsOfZeros [1024]byte