PcapPlusPlus  20.08
pcpp::UdpLayer Class Reference

#include <UdpLayer.h>

Inheritance diagram for pcpp::UdpLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 UdpLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 UdpLayer (uint16_t portSrc, uint16_t portDst)
 
udphdrgetUdpHeader () const
 
uint16_t calculateChecksum (bool writeResultToPacket)
 
void parseNextLayer ()
 
size_t getHeaderLen () const
 
void computeCalculateFields ()
 
std::string toString () const
 
OsiModelLayer getOsiModelLayer () const
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Detailed Description

Represents an UDP (User Datagram Protocol) protocol layer

Constructor & Destructor Documentation

◆ UdpLayer() [1/2]

pcpp::UdpLayer::UdpLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
inline

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data (will be casted to udphdr)
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ UdpLayer() [2/2]

pcpp::UdpLayer::UdpLayer ( uint16_t  portSrc,
uint16_t  portDst 
)

A constructor that allocates a new UDP header with source and destination ports

Parameters
[in]portSrcSource UDP port address
[in]portDstDestination UDP port

Member Function Documentation

◆ calculateChecksum()

uint16_t pcpp::UdpLayer::calculateChecksum ( bool  writeResultToPacket)

Calculate the checksum from header and data and possibly write the result to udphdr::headerChecksum

Parameters
[in]writeResultToPacketIf set to true then checksum result will be written to udphdr::headerChecksum
Returns
The checksum result

◆ computeCalculateFields()

void pcpp::UdpLayer::computeCalculateFields ( )
virtual

Calculate udphdr::headerChecksum field

Implements pcpp::Layer.

◆ getHeaderLen()

size_t pcpp::UdpLayer::getHeaderLen ( ) const
inlinevirtual
Returns
Size of udphdr

Implements pcpp::Layer.

◆ getOsiModelLayer()

OsiModelLayer pcpp::UdpLayer::getOsiModelLayer ( ) const
inlinevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getUdpHeader()

udphdr* pcpp::UdpLayer::getUdpHeader ( ) const
inline

Get a pointer to the UDP header. Notice this points directly to the data, so every change will change the actual packet data

Returns
A pointer to the udphdr

◆ parseNextLayer()

void pcpp::UdpLayer::parseNextLayer ( )
virtual

Currently identifies the following next layers: DnsLayer, DhcpLayer, VxlanLayer, SipRequestLayer, SipResponseLayer, RadiusLayer. Otherwise sets PayloadLayer

Implements pcpp::Layer.

◆ toString()

std::string pcpp::UdpLayer::toString ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.