PcapPlusPlus  21.05
pcpp::PayloadLayer Class Reference

#include <PayloadLayer.h>

Inheritance diagram for pcpp::PayloadLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 PayloadLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 PayloadLayer (const uint8_t *data, size_t dataLen, bool dummy)
 
 PayloadLayer (const std::string &payloadAsHexStream)
 
uint8_t * getPayload () const
 
size_t getPayloadLen () const
 
void parseNextLayer ()
 
size_t getHeaderLen () const
 
void computeCalculateFields ()
 
void setPayload (const uint8_t *newPayload, size_t newPayloadLength)
 
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 a generic or unknown layer or a packet payload

Constructor & Destructor Documentation

◆ PayloadLayer() [1/3]

pcpp::PayloadLayer::PayloadLayer ( 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
[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

◆ PayloadLayer() [2/3]

pcpp::PayloadLayer::PayloadLayer ( const uint8_t *  data,
size_t  dataLen,
bool  dummy 
)

A constructor that allocates a new payload

Parameters
[in]dataA raw buffer that will be used as a payload. This data will be copied to the layer
[in]dataLenThe raw buffer length
[in]dummyA dummy parameter to separate the constructor signature from the other constructor. Its value isn't used anywhere

◆ PayloadLayer() [3/3]

pcpp::PayloadLayer::PayloadLayer ( const std::string &  payloadAsHexStream)

A constructor that allocates a new payload from an hex stream

Parameters
[in]payloadAsHexStreamA string that represents an hex stream of the payload. For example: 0001080006040002842b2b774c56c0a80078000000000000c0a8. In order for the hex stream to be valid it has to contain valid hex chars only (which means, for example, that it can't begin with "0x") and it also has to have an even number of chars (each char represents one nibble). If the string is not a valid hex stream an error will be printed to log and the payload layer will be empty (no data)

Member Function Documentation

◆ computeCalculateFields()

void pcpp::PayloadLayer::computeCalculateFields ( )
inlinevirtual

Does nothing for this layer

Implements pcpp::Layer.

◆ getHeaderLen()

size_t pcpp::PayloadLayer::getHeaderLen ( ) const
inlinevirtual
Returns
Payload data length in bytes

Implements pcpp::Layer.

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getPayload()

uint8_t* pcpp::PayloadLayer::getPayload ( ) const
inline

Get a pointer to the payload data

Returns
A pointer to the payload data

◆ getPayloadLen()

size_t pcpp::PayloadLayer::getPayloadLen ( ) const
inline

Get the payload data length

Returns
The payload data length in bytes

◆ parseNextLayer()

void pcpp::PayloadLayer::parseNextLayer ( )
inlinevirtual

Does nothing for this layer (PayloadLayer is always last)

Implements pcpp::Layer.

◆ setPayload()

void pcpp::PayloadLayer::setPayload ( const uint8_t *  newPayload,
size_t  newPayloadLength 
)

Sets the payload of the PayloadLayer to the given pointer. This will resize (extend/shorten) the underlying packet respectively if there is one.

Parameters
[in]newPayloadNew payload that shall be set
[in]newPayloadLengthNew length of payload

◆ toString()

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

Implements pcpp::Layer.