github.com/gopacket/gopacket@v1.1.0/layers/fddi.go (about)

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