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
11 "github.com/google/gopacket"
14 // EAPOL defines an EAP over LAN (802.1x) layer.
22 // LayerType returns LayerTypeEAPOL.
23 func (e *EAPOL) LayerType() gopacket.LayerType { return LayerTypeEAPOL }
25 // DecodeFromBytes decodes the given bytes into this layer.
26 func (e *EAPOL) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
28 e.Type = EAPOLType(data[1])
29 e.Length = binary.BigEndian.Uint16(data[2:4])
30 e.BaseLayer = BaseLayer{data[:4], data[4:]}
34 // SerializeTo writes the serialized form of this layer into the
35 // SerializationBuffer, implementing gopacket.SerializableLayer
36 func (e *EAPOL) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
37 bytes, _ := b.PrependBytes(4)
39 bytes[1] = byte(e.Type)
40 binary.BigEndian.PutUint16(bytes[2:], e.Length)
44 // CanDecode returns the set of layer types that this DecodingLayer can decode.
45 func (e *EAPOL) CanDecode() gopacket.LayerClass {
49 // NextLayerType returns the layer type contained by this DecodingLayer.
50 func (e *EAPOL) NextLayerType() gopacket.LayerType {
51 return e.Type.LayerType()
54 func decodeEAPOL(data []byte, p gopacket.PacketBuilder) error {
56 return decodingLayerDecoder(e, data, p)