PcapPlusPlus  Next
pcpp::internal::LayerAllocationInfo Struct Reference

Holds information about a Layer's data and object ownership. More...

#include <Layer.h>

Public Member Functions

void attachPacket (Packet *packet, bool managed, bool force=false)
 Sets the state of attachment to a specified Packet. More...
 
void detach ()
 Clears the attachment to any Packet, resetting to unmanaged state.
 

Public Attributes

PacketattachedPacket = nullptr
 Pointer to the Packet this layer is attached to (if any). More...
 
bool ownedByPacket = false
 Controls if the layer object is considered owned by the attached Packet. More...
 

Detailed Description

Holds information about a Layer's data and object ownership.

Member Function Documentation

◆ attachPacket()

void pcpp::internal::LayerAllocationInfo::attachPacket ( Packet packet,
bool  managed,
bool  force = false 
)
inline

Sets the state of attachment to a specified Packet.

Parameters
packetPointer to the Packet this layer is attached to (or nullptr if not attached to any Packet)
managedTrue if the layer object's lifetime is to be managed by the Packet, false otherwise
forceIf true, bypasses the check for existing attachment. Default is false.
Exceptions
std::runtime_errorif the layer is already attached to a Packet and 'force' is false

Member Data Documentation

◆ attachedPacket

Packet* pcpp::internal::LayerAllocationInfo::attachedPacket = nullptr

Pointer to the Packet this layer is attached to (if any).

If the layer is attached to a Packet, the layer's memory span (data) is considered managed by the Packet. The Packet is responsible for keeping the layer's memory span valid and updating it should it become necessary as long as the layer is attached to it.

In an event the Packet is destroyed, all of its attached layers's memory views are considered invalid. Accessing layer data after the Packet is destroyed results in undefined behavior.

If nullptr, the layer is not attached to any Packet and is considered unmanaged. It also means the layer's memory span is considered owned by the layer itself and will be freed when the layer is destroyed.

◆ ownedByPacket

bool pcpp::internal::LayerAllocationInfo::ownedByPacket = false

Controls if the layer object is considered owned by the attached Packet.

If 'true', the Layer object is considered owned by the attached Packet and will be freed by it on Packet destruction.

If 'false', the Layer object is considered unmanaged and the user is responsible for freeing it. This is commonly the case for layers created on the stack and attached to a Packet.