udplite.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2012 Google, Inc. All rights reserved.
  2. // Copyright 2009-2011 Andreas Krennmair. All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license
  5. // that can be found in the LICENSE file in the root of the source
  6. // tree.
  7. package layers
  8. import (
  9. "encoding/binary"
  10. "github.com/google/gopacket"
  11. )
  12. // UDPLite is the layer for UDP-Lite headers (rfc 3828).
  13. type UDPLite struct {
  14. BaseLayer
  15. SrcPort, DstPort UDPLitePort
  16. ChecksumCoverage uint16
  17. Checksum uint16
  18. sPort, dPort []byte
  19. }
  20. // LayerType returns gopacket.LayerTypeUDPLite
  21. func (u *UDPLite) LayerType() gopacket.LayerType { return LayerTypeUDPLite }
  22. func decodeUDPLite(data []byte, p gopacket.PacketBuilder) error {
  23. udp := &UDPLite{
  24. SrcPort: UDPLitePort(binary.BigEndian.Uint16(data[0:2])),
  25. sPort: data[0:2],
  26. DstPort: UDPLitePort(binary.BigEndian.Uint16(data[2:4])),
  27. dPort: data[2:4],
  28. ChecksumCoverage: binary.BigEndian.Uint16(data[4:6]),
  29. Checksum: binary.BigEndian.Uint16(data[6:8]),
  30. BaseLayer: BaseLayer{data[:8], data[8:]},
  31. }
  32. p.AddLayer(udp)
  33. p.SetTransportLayer(udp)
  34. return p.NextDecoder(gopacket.LayerTypePayload)
  35. }
  36. func (u *UDPLite) TransportFlow() gopacket.Flow {
  37. return gopacket.NewFlow(EndpointUDPLitePort, u.sPort, u.dPort)
  38. }