PcapPlusPlus  23.09
RawPacket.h
Go to the documentation of this file.
1 #ifndef PCAPPP_RAW_PACKET
2 #define PCAPPP_RAW_PACKET
3 
4 #include <stdint.h>
5 #ifdef _MSC_VER
6 #include <WinSock2.h>
7 #include <time.h>
8 #else
9 #include <sys/time.h>
10 #endif
11 #include <stddef.h>
12 
14 
19 namespace pcpp
20 {
21 
26  {
54  LINKTYPE_RAW = 101,
241  };
242 
246 #define PCPP_MAX_PACKET_SIZE 65536
247 
254  class RawPacket
255  {
256  protected:
257  uint8_t* m_RawData;
258  int m_RawDataLen;
259  int m_FrameLength;
260  timespec m_TimeStamp;
261  bool m_DeleteRawDataAtDestructor;
262  bool m_RawPacketSet;
263  LinkLayerType m_LinkLayerType;
264  void init(bool deleteRawDataAtDestructor = true);
265  void copyDataFrom(const RawPacket& other, bool allocateData = true);
266  public:
278  RawPacket(const uint8_t* pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
279 
291  RawPacket(const uint8_t* pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
292 
300  RawPacket();
301 
305  virtual ~RawPacket();
306 
312  RawPacket(const RawPacket& other);
313 
320  RawPacket& operator=(const RawPacket& other);
321 
325  virtual uint8_t getObjectType() const { return 0; }
326 
337  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
338 
349  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
350 
355  const uint8_t* getRawData() const { return m_RawData; }
356 
361  LinkLayerType getLinkLayerType() const { return m_LinkLayerType; }
362 
368  static bool isLinkTypeValid(int linkTypeValue);
369 
374  int getRawDataLen() const { return m_RawDataLen; }
375 
380  int getFrameLength() const { return m_FrameLength; }
385  timespec getPacketTimeStamp() const { return m_TimeStamp; }
386 
392  virtual bool setPacketTimeStamp(timeval timestamp);
393 
399  virtual bool setPacketTimeStamp(timespec timestamp);
400 
407  bool isPacketSet() const { return m_RawPacketSet; }
408 
415  virtual void clear();
416 
424  virtual void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
425 
434  virtual void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
435 
442  virtual bool removeData(int atIndex, size_t numOfBytesToRemove);
443 
452  virtual bool reallocateData(size_t newBufferLength);
453  };
454 
455 } // namespace pcpp
456 
457 #endif
Definition: RawPacket.h:34
The main namespace for the PcapPlusPlus lib.
Definition: RawPacket.h:144
Definition: RawPacket.h:60
Definition: RawPacket.h:112
Definition: RawPacket.h:124
Definition: RawPacket.h:154
Definition: RawPacket.h:90
Definition: RawPacket.h:58
Definition: RawPacket.h:208
Definition: RawPacket.h:224
Definition: RawPacket.h:30
int getRawDataLen() const
Definition: RawPacket.h:374
Definition: RawPacket.h:170
Definition: RawPacket.h:66
Definition: RawPacket.h:204
Definition: RawPacket.h:140
Definition: RawPacket.h:114
Definition: RawPacket.h:202
Definition: RawPacket.h:38
Definition: RawPacket.h:110
Definition: RawPacket.h:46
Definition: RawPacket.h:92
Definition: RawPacket.h:158
Definition: RawPacket.h:222
Definition: RawPacket.h:84
Definition: RawPacket.h:148
Definition: RawPacket.h:116
virtual bool removeData(int atIndex, size_t numOfBytesToRemove)
static bool isLinkTypeValid(int linkTypeValue)
Definition: RawPacket.h:122
Definition: RawPacket.h:160
virtual void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
virtual bool reallocateData(size_t newBufferLength)
Definition: RawPacket.h:254
Definition: RawPacket.h:82
Definition: RawPacket.h:196
Definition: RawPacket.h:178
Definition: RawPacket.h:236
Definition: RawPacket.h:72
Definition: RawPacket.h:76
Definition: RawPacket.h:98
Definition: RawPacket.h:174
Definition: RawPacket.h:54
RawPacket & operator=(const RawPacket &other)
Definition: RawPacket.h:168
Definition: RawPacket.h:48
Definition: RawPacket.h:188
Definition: RawPacket.h:230
virtual ~RawPacket()
Definition: RawPacket.h:64
Definition: RawPacket.h:96
Definition: RawPacket.h:146
const uint8_t * getRawData() const
Definition: RawPacket.h:355
Definition: RawPacket.h:150
Definition: RawPacket.h:56
virtual uint8_t getObjectType() const
Definition: RawPacket.h:325
Definition: RawPacket.h:216
Definition: RawPacket.h:162
Definition: RawPacket.h:70
Definition: RawPacket.h:134
Definition: RawPacket.h:226
Definition: RawPacket.h:88
Definition: RawPacket.h:212
Definition: RawPacket.h:194
Definition: RawPacket.h:210
Definition: RawPacket.h:42
Definition: RawPacket.h:186
Definition: RawPacket.h:40
Definition: RawPacket.h:130
Definition: RawPacket.h:166
Definition: RawPacket.h:214
Definition: RawPacket.h:136
Definition: RawPacket.h:28
LinkLayerType
Definition: RawPacket.h:25
bool isPacketSet() const
Definition: RawPacket.h:407
Definition: RawPacket.h:138
int getFrameLength() const
Definition: RawPacket.h:380
Definition: RawPacket.h:218
Definition: RawPacket.h:228
Definition: RawPacket.h:106
Definition: RawPacket.h:52
Definition: RawPacket.h:86
Definition: RawPacket.h:120
Definition: RawPacket.h:182
Definition: RawPacket.h:50
Definition: RawPacket.h:108
timespec getPacketTimeStamp() const
Definition: RawPacket.h:385
Definition: RawPacket.h:232
Definition: RawPacket.h:176
Definition: RawPacket.h:44
Definition: RawPacket.h:80
Definition: RawPacket.h:102
virtual void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
Definition: RawPacket.h:32
Definition: RawPacket.h:180
Definition: RawPacket.h:94
Definition: RawPacket.h:200
Definition: RawPacket.h:238
Definition: RawPacket.h:128
Definition: RawPacket.h:36
virtual bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
Definition: RawPacket.h:156
Definition: RawPacket.h:240
Definition: RawPacket.h:220
Definition: RawPacket.h:74
Definition: RawPacket.h:206
Definition: RawPacket.h:104
Definition: RawPacket.h:234
LinkLayerType getLinkLayerType() const
Definition: RawPacket.h:361
Definition: RawPacket.h:164
Definition: RawPacket.h:192
Definition: RawPacket.h:172
Definition: RawPacket.h:198
Definition: RawPacket.h:126
Definition: RawPacket.h:100
Definition: RawPacket.h:68
Definition: RawPacket.h:78
Definition: RawPacket.h:62
Definition: RawPacket.h:190
Definition: RawPacket.h:118
Definition: RawPacket.h:184
Definition: RawPacket.h:132
virtual bool setPacketTimeStamp(timeval timestamp)
Definition: RawPacket.h:142
virtual void clear()