PcapPlusPlus  Next
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 getSrcPort () const
 
uint16_t getDstPort () const
 
uint16_t calculateChecksum (bool writeResultToPacket)
 
void parseNextLayer () override
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 
std::string toString () const override
 
OsiModelLayer getOsiModelLayer () const override
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) 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 override
 

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 ( )
overridevirtual

Calculate udphdr::headerChecksum field

Implements pcpp::Layer.

◆ getDstPort()

uint16_t pcpp::UdpLayer::getDstPort ( ) const
Returns
UDP destination port

◆ getHeaderLen()

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

Implements pcpp::Layer.

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getSrcPort()

uint16_t pcpp::UdpLayer::getSrcPort ( ) const
Returns
UDP source port

◆ 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 ( )
overridevirtual

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
overridevirtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.