fddi.go 1.0 KB

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