PcapPlusPlus
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 ()
 
uint16_t calculateChecksum (bool writeResultToPacket)
 
void parseNextLayer ()
 
size_t getHeaderLen ()
 
void computeCalculateFields ()
 
std::string toString ()
 
OsiModelLayer getOsiModelLayer ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer ()
 
LayergetPrevLayer ()
 
ProtocolType getProtocol ()
 
uint8_t * getData ()
 
size_t getDataLen ()
 
uint8_t * getLayerPayload ()
 
size_t getLayerPayloadSize ()
 
bool isAllocatedToPacket ()
 
void copyData (uint8_t *toArr)
 
uint8_t * getDataPtr (size_t offset=0)
 

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 ( )
inlinevirtual
Returns
Size of udphdr

Implements pcpp::Layer.

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getUdpHeader()

udphdr* pcpp::UdpLayer::getUdpHeader ( )
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 ( )
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.