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 // PPPoE is the layer for PPPoE encapsulation headers.
24 // LayerType returns gopacket.LayerTypePPPoE.
25 func (p *PPPoE) LayerType() gopacket.LayerType {
29 // decodePPPoE decodes the PPPoE header (see http://tools.ietf.org/html/rfc2516).
30 func decodePPPoE(data []byte, p gopacket.PacketBuilder) error {
32 Version: data[0] >> 4,
34 Code: PPPoECode(data[1]),
35 SessionId: binary.BigEndian.Uint16(data[2:4]),
36 Length: binary.BigEndian.Uint16(data[4:6]),
38 pppoe.BaseLayer = BaseLayer{data[:6], data[6 : 6+pppoe.Length]}
40 return p.NextDecoder(pppoe.Code)
43 // SerializeTo writes the serialized form of this layer into the
44 // SerializationBuffer, implementing gopacket.SerializableLayer.
45 // See the docs for gopacket.SerializableLayer for more info.
46 func (p *PPPoE) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
48 bytes, err := b.PrependBytes(6)
52 bytes[0] = (p.Version << 4) | p.Type
53 bytes[1] = byte(p.Code)
54 binary.BigEndian.PutUint16(bytes[2:], p.SessionId)
56 p.Length = uint16(len(payload))
58 binary.BigEndian.PutUint16(bytes[4:], p.Length)