blob: ed9e1957b92b6735ce011ed0e8c1c018c1b90477 [file] [log] [blame]
Andrea Campanella7167ebb2020-02-24 09:56:38 +01001// 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 "github.com/google/gopacket"
11 "net"
12)
13
14// FDDI contains the header for FDDI frames.
15type FDDI struct {
16 BaseLayer
17 FrameControl FDDIFrameControl
18 Priority uint8
19 SrcMAC, DstMAC net.HardwareAddr
20}
21
22// LayerType returns LayerTypeFDDI.
23func (f *FDDI) LayerType() gopacket.LayerType { return LayerTypeFDDI }
24
25// LinkFlow returns a new flow of type EndpointMAC.
26func (f *FDDI) LinkFlow() gopacket.Flow {
27 return gopacket.NewFlow(EndpointMAC, f.SrcMAC, f.DstMAC)
28}
29
30func decodeFDDI(data []byte, p gopacket.PacketBuilder) error {
31 f := &FDDI{
32 FrameControl: FDDIFrameControl(data[0] & 0xF8),
33 Priority: data[0] & 0x07,
34 SrcMAC: net.HardwareAddr(data[1:7]),
35 DstMAC: net.HardwareAddr(data[7:13]),
36 BaseLayer: BaseLayer{data[:13], data[13:]},
37 }
38 p.SetLinkLayer(f)
39 p.AddLayer(f)
40 return p.NextDecoder(f.FrameControl)
41}