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