PcapPlusPlus
21.05
|
#include <RawPacket.h>
Public Member Functions | |
RawPacket (const uint8_t *pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType=LINKTYPE_ETHERNET) | |
RawPacket (const uint8_t *pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType=LINKTYPE_ETHERNET) | |
RawPacket () | |
virtual | ~RawPacket () |
RawPacket (const RawPacket &other) | |
RawPacket & | operator= (const RawPacket &other) |
virtual uint8_t | getObjectType () const |
virtual bool | setRawData (const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1) |
virtual bool | setRawData (const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1) |
const uint8_t * | getRawData () const |
LinkLayerType | getLinkLayerType () const |
int | getRawDataLen () const |
int | getFrameLength () const |
timespec | getPacketTimeStamp () const |
virtual bool | setPacketTimeStamp (timeval timestamp) |
virtual bool | setPacketTimeStamp (timespec timestamp) |
bool | isPacketSet () const |
virtual void | clear () |
virtual void | appendData (const uint8_t *dataToAppend, size_t dataToAppendLen) |
virtual void | insertData (int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen) |
virtual bool | removeData (int atIndex, size_t numOfBytesToRemove) |
virtual bool | reallocateData (size_t newBufferLength) |
Static Public Member Functions | |
static bool | isLinkTypeValid (int linkTypeValue) |
This class holds the packet as raw (not parsed) data. The data is held as byte array. In addition to the data itself every instance also holds a timestamp representing the time the packet was received by the NIC. RawPacket instance isn't read only. The user can change the packet data, add or remove data, etc.
pcpp::RawPacket::RawPacket | ( | const uint8_t * | pRawData, |
int | rawDataLen, | ||
timeval | timestamp, | ||
bool | deleteRawDataAtDestructor, | ||
LinkLayerType | layerType = LINKTYPE_ETHERNET |
||
) |
A constructor that receives a pointer to the raw data (allocated elsewhere). This constructor is usually used when packet is captured using a packet capturing engine (like libPcap. WinPcap, Npcap, PF_RING, etc.). The capturing engine allocates the raw data memory and give the user a pointer to it + a timestamp it has arrived to the device
[in] | pRawData | A pointer to the raw data |
[in] | rawDataLen | The raw data length in bytes |
[in] | timestamp | The timestamp packet was received by the NIC (in usec precision) |
[in] | deleteRawDataAtDestructor | An indicator whether raw data pointer should be freed when the instance is freed or not. If set to 'true' than pRawData will be freed when instanced is being freed |
[in] | layerType | The link layer type of this raw packet. The default is Ethernet |
pcpp::RawPacket::RawPacket | ( | const uint8_t * | pRawData, |
int | rawDataLen, | ||
timespec | timestamp, | ||
bool | deleteRawDataAtDestructor, | ||
LinkLayerType | layerType = LINKTYPE_ETHERNET |
||
) |
A constructor that receives a pointer to the raw data (allocated elsewhere). This constructor is usually used when packet is captured using a packet capturing engine (like libPcap. WinPcap, Npcap, PF_RING, etc.). The capturing engine allocates the raw data memory and give the user a pointer to it + a timestamp it has arrived to the device
[in] | pRawData | A pointer to the raw data |
[in] | rawDataLen | The raw data length in bytes |
[in] | timestamp | The timestamp packet was received by the NIC (in nsec precision) |
[in] | deleteRawDataAtDestructor | An indicator whether raw data pointer should be freed when the instance is freed or not. If set to 'true' than pRawData will be freed when instanced is being freed |
[in] | layerType | The link layer type of this raw packet. The default is Ethernet |
pcpp::RawPacket::RawPacket | ( | ) |
A default constructor that initializes class'es attributes to default value:
|
virtual |
A destructor for this class. Frees the raw data if deleteRawDataAtDestructor was set to 'true'
pcpp::RawPacket::RawPacket | ( | const RawPacket & | other | ) |
A copy constructor that copies all data from another instance. Notice all raw data is copied (using memcpy), so when the original or the other instance are freed, the other won't be affected
[in] | other | The instance to copy from |
|
virtual |
Append data to the end of current data. This method works without allocating more memory, it just uses memcpy() to copy dataToAppend at the end of the current data. This means that the method assumes this memory was already allocated by the user. If it isn't the case then this method will cause memory corruption
[in] | dataToAppend | A pointer to the data to append to current raw data |
[in] | dataToAppendLen | Length in bytes of dataToAppend |
Reimplemented in pcpp::MBufRawPacket.
|
virtual |
Clears all members of this instance, meaning setting raw data to NULL, raw data length to 0, etc. Currently raw data is always freed, even if deleteRawDataAtDestructor was set to 'false'
Reimplemented in pcpp::MBufRawPacket.
|
inline |
Get frame length in bytes
|
inline |
Get the link layer type
|
inlinevirtual |
Reimplemented in pcpp::MBufRawPacket.
|
inline |
Get raw data timestamp
|
inline |
Get raw data pointer
|
inline |
Get raw data length in bytes
|
virtual |
Insert new data at some index of the current data and shift the remaining old data to the end. This method works without allocating more memory, it just copies dataToAppend at the relevant index and shifts the remaining data to the end. This means that the method assumes this memory was already allocated by the user. If it isn't the case then this method will cause memory corruption
[in] | atIndex | The index to insert the new data to |
[in] | dataToInsert | A pointer to the new data to insert |
[in] | dataToInsertLen | Length in bytes of dataToInsert |
Reimplemented in pcpp::MBufRawPacket.
|
static |
This static method validates whether a link type integer value is valid
[in] | linkTypeValue | Link type integer value |
|
inline |
Get an indication whether raw data was already set for this instance.
Assignment operator overload for this class. When using this operator on an already initialized RawPacket instance, the original raw data is freed first. Then the other instance is copied to this instance, the same way the copy constructor works
[in] | other | The instance to copy from |
|
virtual |
Re-allocate raw packet buffer meaning add size to it without losing the current packet data. This method allocates the required buffer size as instructed by the use and then copies the raw data from the current allocated buffer to the new one. This method can become useful if the user wants to insert or append data to the raw data, and the previous allocated buffer is too small, so the user wants to allocate a larger buffer and get RawPacket instance to point to it
[in] | newBufferLength | The new buffer length as required by the user. The method is responsible to allocate the memory |
Reimplemented in pcpp::MBufRawPacket.
|
virtual |
Remove certain number of bytes from current raw data buffer. All data after the removed bytes will be shifted back
[in] | atIndex | The index to start removing bytes from |
[in] | numOfBytesToRemove | Number of bytes to remove |
Reimplemented in pcpp::MBufRawPacket.
|
virtual |
Set raw packet timestamp with usec precision
[in] | timestamp | The timestamp to set (with usec precision) |
|
virtual |
Set raw packet timestamp with nsec precision
[in] | timestamp | The timestamp to set (with nsec precision) |
|
virtual |
Set a raw data. If data was already set and deleteRawDataAtDestructor was set to 'true' the old data will be freed first
[in] | pRawData | A pointer to the new raw data |
[in] | rawDataLen | The new raw data length in bytes |
[in] | timestamp | The timestamp packet was received by the NIC (in usec precision) |
[in] | layerType | The link layer type for this raw data |
[in] | frameLength | When reading from pcap files, sometimes the captured length is different from the actual packet length. This parameter represents the packet length. This parameter is optional, if not set or set to -1 it is assumed both lengths are equal |
|
virtual |
Set a raw data. If data was already set and deleteRawDataAtDestructor was set to 'true' the old data will be freed first
[in] | pRawData | A pointer to the new raw data |
[in] | rawDataLen | The new raw data length in bytes |
[in] | timestamp | The timestamp packet was received by the NIC (in nsec precision) |
[in] | layerType | The link layer type for this raw data |
[in] | frameLength | When reading from pcap files, sometimes the captured length is different from the actual packet length. This parameter represents the packet length. This parameter is optional, if not set or set to -1 it is assumed both lengths are equal |
Reimplemented in pcpp::MBufRawPacket.