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
12 "github.com/google/gopacket"
15 // PPP is the layer for PPP encapsulation headers.
21 // PPPEndpoint is a singleton endpoint for PPP. Since there is no actual
22 // addressing for the two ends of a PPP connection, we use a singleton value
23 // named 'point' for each endpoint.
24 var PPPEndpoint = gopacket.NewEndpoint(EndpointPPP, nil)
26 // PPPFlow is a singleton flow for PPP. Since there is no actual addressing for
27 // the two ends of a PPP connection, we use a singleton value to represent the
28 // flow for all PPP connections.
29 var PPPFlow = gopacket.NewFlow(EndpointPPP, nil, nil)
31 // LayerType returns LayerTypePPP
32 func (p *PPP) LayerType() gopacket.LayerType { return LayerTypePPP }
34 // LinkFlow returns PPPFlow.
35 func (p *PPP) LinkFlow() gopacket.Flow { return PPPFlow }
37 func decodePPP(data []byte, p gopacket.PacketBuilder) error {
41 return errors.New("PPP has invalid type")
43 ppp.PPPType = PPPType(binary.BigEndian.Uint16(data[:2]))
44 ppp.Contents = data[:2]
45 ppp.Payload = data[2:]
47 ppp.PPPType = PPPType(data[0])
48 ppp.Contents = data[:1]
49 ppp.Payload = data[1:]
53 return p.NextDecoder(ppp.PPPType)
56 // SerializeTo writes the serialized form of this layer into the
57 // SerializationBuffer, implementing gopacket.SerializableLayer.
58 // See the docs for gopacket.SerializableLayer for more info.
59 func (p *PPP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
60 if p.PPPType&0x100 == 0 {
61 bytes, err := b.PrependBytes(2)
65 binary.BigEndian.PutUint16(bytes, uint16(p.PPPType))
67 bytes, err := b.PrependBytes(1)
71 bytes[0] = uint8(p.PPPType)