etherip.go 1.2 KB

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