blob: 5b7b7229ecaf0d7b8d4635f044aee8f32052587d [file] [log] [blame]
Takahiro Suzuki241c10e2020-12-17 20:17:57 +09001// 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
7package layers
8
9import (
10 "encoding/binary"
11 "github.com/google/gopacket"
12)
13
14// EtherIP is the struct for storing RFC 3378 EtherIP packet headers.
15type EtherIP struct {
16 BaseLayer
17 Version uint8
18 Reserved uint16
19}
20
21// LayerType returns gopacket.LayerTypeEtherIP.
22func (e *EtherIP) LayerType() gopacket.LayerType { return LayerTypeEtherIP }
23
24// DecodeFromBytes decodes the given bytes into this layer.
25func (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.
33func (e *EtherIP) CanDecode() gopacket.LayerClass {
34 return LayerTypeEtherIP
35}
36
37// NextLayerType returns the layer type contained by this DecodingLayer.
38func (e *EtherIP) NextLayerType() gopacket.LayerType {
39 return LayerTypeEthernet
40}
41
42func decodeEtherIP(data []byte, p gopacket.PacketBuilder) error {
43 e := &EtherIP{}
44 return decodingLayerDecoder(e, data, p)
45}