Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 1 | // 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 | |
| 7 | package layers |
| 8 | |
| 9 | import ( |
| 10 | "github.com/google/gopacket" |
| 11 | "net" |
| 12 | ) |
| 13 | |
| 14 | // FDDI contains the header for FDDI frames. |
| 15 | type FDDI struct { |
| 16 | BaseLayer |
| 17 | FrameControl FDDIFrameControl |
| 18 | Priority uint8 |
| 19 | SrcMAC, DstMAC net.HardwareAddr |
| 20 | } |
| 21 | |
| 22 | // LayerType returns LayerTypeFDDI. |
| 23 | func (f *FDDI) LayerType() gopacket.LayerType { return LayerTypeFDDI } |
| 24 | |
| 25 | // LinkFlow returns a new flow of type EndpointMAC. |
| 26 | func (f *FDDI) LinkFlow() gopacket.Flow { |
| 27 | return gopacket.NewFlow(EndpointMAC, f.SrcMAC, f.DstMAC) |
| 28 | } |
| 29 | |
| 30 | func 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 | } |