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

     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  
     8  package layers
     9  
    10  import (
    11  	"encoding/binary"
    12  
    13  	"github.com/gopacket/gopacket"
    14  )
    15  
    16  // UDPLite is the layer for UDP-Lite headers (rfc 3828).
    17  type UDPLite struct {
    18  	BaseLayer
    19  	SrcPort, DstPort UDPLitePort
    20  	ChecksumCoverage uint16
    21  	Checksum         uint16
    22  	sPort, dPort     []byte
    23  }
    24  
    25  // LayerType returns gopacket.LayerTypeUDPLite
    26  func (u *UDPLite) LayerType() gopacket.LayerType { return LayerTypeUDPLite }
    27  
    28  func decodeUDPLite(data []byte, p gopacket.PacketBuilder) error {
    29  	udp := &UDPLite{
    30  		SrcPort:          UDPLitePort(binary.BigEndian.Uint16(data[0:2])),
    31  		sPort:            data[0:2],
    32  		DstPort:          UDPLitePort(binary.BigEndian.Uint16(data[2:4])),
    33  		dPort:            data[2:4],
    34  		ChecksumCoverage: binary.BigEndian.Uint16(data[4:6]),
    35  		Checksum:         binary.BigEndian.Uint16(data[6:8]),
    36  		BaseLayer:        BaseLayer{data[:8], data[8:]},
    37  	}
    38  	p.AddLayer(udp)
    39  	p.SetTransportLayer(udp)
    40  	return p.NextDecoder(gopacket.LayerTypePayload)
    41  }
    42  
    43  func (u *UDPLite) TransportFlow() gopacket.Flow {
    44  	return gopacket.NewFlow(EndpointUDPLitePort, u.sPort, u.dPort)
    45  }