|
PcapPlusPlus
Next
|
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 | |
| Packet * | attachedPacket = 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... | |
Holds information about a Layer's data and object ownership.
|
inline |
Sets the state of attachment to a specified Packet.
| packet | Pointer to the Packet this layer is attached to (or nullptr if not attached to any Packet) |
| managed | True if the layer object's lifetime is to be managed by the Packet, false otherwise |
| force | If true, bypasses the check for existing attachment. Default is false. |
| std::runtime_error | if the layer is already attached to a Packet and 'force' is false |
| 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.
| 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.