github.com/gopacket/gopacket@v1.1.0/layers/etherip.go (about)

     1  // Copyright 2012 Google, Inc. All rights reserved.
     2  //
     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
     5  // tree.
     6  
     7  package layers
     8  
     9  import (
    10  	"encoding/binary"
    11  
    12  	"github.com/gopacket/gopacket"
    13  )
    14  
    15  // EtherIP is the struct for storing RFC 3378 EtherIP packet headers.
    16  type EtherIP struct {
    17  	BaseLayer
    18  	Version  uint8
    19  	Reserved uint16
    20  }
    21  
    22  // LayerType returns gopacket.LayerTypeEtherIP.
    23  func (e *EtherIP) LayerType() gopacket.LayerType { return LayerTypeEtherIP }
    24  
    25  // DecodeFromBytes decodes the given bytes into this layer.
    26  func (e *EtherIP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
    27  	e.Version = data[0] >> 4
    28  	e.Reserved = binary.BigEndian.Uint16(data[:2]) & 0x0fff
    29  	e.BaseLayer = BaseLayer{data[:2], data[2:]}
    30  	return nil
    31  }
    32  
    33  // CanDecode returns the set of layer types that this DecodingLayer can decode.
    34  func (e *EtherIP) CanDecode() gopacket.LayerClass {
    35  	return LayerTypeEtherIP
    36  }
    37  
    38  // NextLayerType returns the layer type contained by this DecodingLayer.
    39  func (e *EtherIP) NextLayerType() gopacket.LayerType {
    40  	return LayerTypeEthernet
    41  }
    42  
    43  func decodeEtherIP(data []byte, p gopacket.PacketBuilder) error {
    44  	e := &EtherIP{}
    45  	return decodingLayerDecoder(e, data, p)
    46  }