PcapPlusPlus  Next
RawPacket.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #ifdef _MSC_VER
5 # include <WinSock2.h>
6 # include <time.h>
7 #else
8 # include <sys/time.h>
9 #endif
10 #include <stddef.h>
11 
13 
18 namespace pcpp
19 {
20 
25  {
54  LINKTYPE_RAW = 101,
254  LINKTYPE_INVALID = 0xFFFF
255  };
256 
260 #define PCPP_MAX_PACKET_SIZE 65536
261 
268  class RawPacket
269  {
270  protected:
271  uint8_t* m_RawData;
272  int m_RawDataLen;
273  int m_FrameLength;
274  timespec m_TimeStamp;
275  bool m_DeleteRawDataAtDestructor;
276  bool m_RawPacketSet;
277  LinkLayerType m_LinkLayerType;
278  void init(bool deleteRawDataAtDestructor = true);
279  void copyDataFrom(const RawPacket& other, bool allocateData = true);
280 
281  public:
294  RawPacket(const uint8_t* pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor,
295  LinkLayerType layerType = LINKTYPE_ETHERNET);
296 
309  RawPacket(const uint8_t* pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor,
310  LinkLayerType layerType = LINKTYPE_ETHERNET);
311 
320 
324  virtual ~RawPacket();
325 
331  RawPacket(const RawPacket& other);
332 
340  RawPacket& operator=(const RawPacket& other);
341 
346  virtual RawPacket* clone() const;
347 
351  virtual uint8_t getObjectType() const
352  {
353  return 0;
354  }
355 
368  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timeval timestamp,
369  LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
370 
383  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp,
384  LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
385 
396  bool initWithRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp,
397  LinkLayerType layerType = LINKTYPE_ETHERNET);
398 
403  const uint8_t* getRawData() const
404  {
405  return m_RawData;
406  }
407 
413  {
414  return m_LinkLayerType;
415  }
416 
422  static bool isLinkTypeValid(int linkTypeValue);
423 
428  int getRawDataLen() const
429  {
430  return m_RawDataLen;
431  }
432 
437  int getFrameLength() const
438  {
439  return m_FrameLength;
440  }
445  timespec getPacketTimeStamp() const
446  {
447  return m_TimeStamp;
448  }
449 
455  virtual bool setPacketTimeStamp(timeval timestamp);
456 
462  virtual bool setPacketTimeStamp(timespec timestamp);
463 
470  bool isPacketSet() const
471  {
472  return m_RawPacketSet;
473  }
474 
481  virtual void clear();
482 
490  virtual void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
491 
501  virtual void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
502 
511  virtual bool removeData(int atIndex, size_t numOfBytesToRemove);
512 
523  virtual bool reallocateData(size_t newBufferLength);
524  };
525 
526 } // namespace pcpp
Definition: RawPacket.h:269
const uint8_t * getRawData() const
Definition: RawPacket.h:403
int getRawDataLen() const
Definition: RawPacket.h:428
int getFrameLength() const
Definition: RawPacket.h:437
static bool isLinkTypeValid(int linkTypeValue)
virtual void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
RawPacket(const RawPacket &other)
virtual bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
timespec getPacketTimeStamp() const
Definition: RawPacket.h:445
virtual void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
bool initWithRawData(const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET)
RawPacket(const uint8_t *pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType=LINKTYPE_ETHERNET)
virtual uint8_t getObjectType() const
Definition: RawPacket.h:351
RawPacket(const uint8_t *pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType=LINKTYPE_ETHERNET)
virtual bool removeData(int atIndex, size_t numOfBytesToRemove)
virtual bool setRawData(const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
virtual void clear()
virtual ~RawPacket()
virtual bool reallocateData(size_t newBufferLength)
bool isPacketSet() const
Definition: RawPacket.h:470
LinkLayerType getLinkLayerType() const
Definition: RawPacket.h:412
virtual bool setPacketTimeStamp(timespec timestamp)
virtual bool setPacketTimeStamp(timeval timestamp)
virtual RawPacket * clone() const
Clones the current packet. Caller is responsible for deallocation of the memory.
RawPacket & operator=(const RawPacket &other)
The main namespace for the PcapPlusPlus lib.
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_NG40
Definition: RawPacket.h:210
@ LINKTYPE_PPI
Definition: RawPacket.h:145
@ LINKTYPE_GPF_T
Definition: RawPacket.h:135
@ LINKTYPE_USBPCAP
Definition: RawPacket.h:219
@ LINKTYPE_LOOP
Definition: RawPacket.h:62
@ LINKTYPE_BLUETOOTH_LE_LL
Definition: RawPacket.h:223
@ LINKTYPE_USER15
Definition: RawPacket.h:124
@ LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR
Definition: RawPacket.h:231
@ LINKTYPE_IEEE802_15_4
Definition: RawPacket.h:147
@ LINKTYPE_BLUETOOTH_BREDR_BB
Definition: RawPacket.h:229
@ LINKTYPE_ARCNET_BSD
Definition: RawPacket.h:35
@ LINKTYPE_USER2
Definition: RawPacket.h:98
@ LINKTYPE_RAW
Definition: RawPacket.h:54
@ LINKTYPE_MTP3
Definition: RawPacket.h:86
@ LINKTYPE_MTP2_WITH_PHDR
Definition: RawPacket.h:82
@ LINKTYPE_INVALID
Definition: RawPacket.h:254
@ LINKTYPE_PROFIBUS_DL
Definition: RawPacket.h:233
@ LINKTYPE_LINUX_SLL
Definition: RawPacket.h:64
@ LINKTYPE_SLIP
Definition: RawPacket.h:37
@ LINKTYPE_LINUX_SLL2
Definition: RawPacket.h:252
@ LINKTYPE_BACNET_MS_TP
Definition: RawPacket.h:128
@ LINKTYPE_IPMI_HPM_2
Definition: RawPacket.h:239
@ LINKTYPE_USER7
Definition: RawPacket.h:108
@ LINKTYPE_DOCSIS
Definition: RawPacket.h:90
@ LINKTYPE_SCTP
Definition: RawPacket.h:217
@ LINKTYPE_IP_OVER_FC
Definition: RawPacket.h:72
@ LINKTYPE_BLUETOOTH_LINUX_MONITOR
Definition: RawPacket.h:227
@ LINKTYPE_ATM_RFC1483
Definition: RawPacket.h:52
@ LINKTYPE_USER8
Definition: RawPacket.h:110
@ LINKTYPE_MPEG_2_TS
Definition: RawPacket.h:207
@ LINKTYPE_FRELAY
Definition: RawPacket.h:60
@ LINKTYPE_PPP_WITH_DIR
Definition: RawPacket.h:160
@ LINKTYPE_GPRS_LLC
Definition: RawPacket.h:133
@ LINKTYPE_IEEE802_11_PRISM
Definition: RawPacket.h:70
@ LINKTYPE_AX25
Definition: RawPacket.h:31
@ LINKTYPE_EPON
Definition: RawPacket.h:237
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29
@ LINKTYPE_NULL
Definition: RawPacket.h:27
@ LINKTYPE_IEEE802_5
Definition: RawPacket.h:33
@ LINKTYPE_SITA
Definition: RawPacket.h:149
@ LINKTYPE_SUNATM
Definition: RawPacket.h:74
@ LINKTYPE_IEEE802_11_RADIOTAP
Definition: RawPacket.h:76
@ LINKTYPE_USB_LINUX_MMAPPED
Definition: RawPacket.h:170
@ LINKTYPE_C_HDLC
Definition: RawPacket.h:56
@ LINKTYPE_USER12
Definition: RawPacket.h:118
@ LINKTYPE_BLUETOOTH_HCI_H4
Definition: RawPacket.h:141
@ LINKTYPE_RTAC_SERIAL
Definition: RawPacket.h:221
@ LINKTYPE_NFLOG
Definition: RawPacket.h:197
@ LINKTYPE_ARCNET_LINUX
Definition: RawPacket.h:78
@ LINKTYPE_FC_2_WITH_FRAME_DELIMS
Definition: RawPacket.h:174
@ LINKTYPE_PFLOG
Definition: RawPacket.h:68
@ LINKTYPE_FDDI
Definition: RawPacket.h:41
@ LINKTYPE_ERF
Definition: RawPacket.h:151
@ LINKTYPE_USER5
Definition: RawPacket.h:104
@ LINKTYPE_DLT_RAW2
Definition: RawPacket.h:45
@ LINKTYPE_AX25_KISS
Definition: RawPacket.h:155
@ LINKTYPE_USER13
Definition: RawPacket.h:120
@ LINKTYPE_LINUX_IRDA
Definition: RawPacket.h:92
@ LINKTYPE_USER10
Definition: RawPacket.h:114
@ LINKTYPE_IEEE802_15_4_NOFCS
Definition: RawPacket.h:184
@ LINKTYPE_ZWAVE_R1_R2
Definition: RawPacket.h:241
@ LINKTYPE_FRELAY_WITH_DIR
Definition: RawPacket.h:164
@ LINKTYPE_PPP_PPPD
Definition: RawPacket.h:131
@ LINKTYPE_ZWAVE_R3
Definition: RawPacket.h:243
@ LINKTYPE_C_HDLC_WITH_DIR
Definition: RawPacket.h:162
@ LINKTYPE_APPLE_IP_OVER_IEEE1394
Definition: RawPacket.h:80
@ LINKTYPE_IEEE802_11
Definition: RawPacket.h:58
@ LINKTYPE_PKTAP
Definition: RawPacket.h:235
@ LINKTYPE_NETLINK
Definition: RawPacket.h:225
@ LINKTYPE_IPNET
Definition: RawPacket.h:176
@ LINKTYPE_IPOIB
Definition: RawPacket.h:205
@ LINKTYPE_USB_LINUX
Definition: RawPacket.h:143
@ LINKTYPE_USER6
Definition: RawPacket.h:106
@ LINKTYPE_LINUX_LAPD
Definition: RawPacket.h:139
@ LINKTYPE_FC_2
Definition: RawPacket.h:172
@ LINKTYPE_INFINIBAND
Definition: RawPacket.h:215
@ LINKTYPE_LAPD
Definition: RawPacket.h:157
@ LINKTYPE_DLT_RAW1
Definition: RawPacket.h:43
@ LINKTYPE_USER4
Definition: RawPacket.h:102
@ LINKTYPE_IPV4
Definition: RawPacket.h:180
@ LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR
Definition: RawPacket.h:153
@ LINKTYPE_USER14
Definition: RawPacket.h:122
@ LINKTYPE_IEEE802_15_4_NONASK_PHY
Definition: RawPacket.h:168
@ LINKTYPE_NFC_LLCP
Definition: RawPacket.h:213
@ LINKTYPE_USER9
Definition: RawPacket.h:112
@ LINKTYPE_DVB_CI
Definition: RawPacket.h:190
@ LINKTYPE_DBUS
Definition: RawPacket.h:187
@ LINKTYPE_STANAG_5066_D_PDU
Definition: RawPacket.h:195
@ LINKTYPE_GPF_F
Definition: RawPacket.h:137
@ LINKTYPE_SCCP
Definition: RawPacket.h:88
@ LINKTYPE_MUX27010
Definition: RawPacket.h:192
@ LINKTYPE_USER11
Definition: RawPacket.h:116
@ LINKTYPE_NETANALYZER_TRANSPARENT
Definition: RawPacket.h:203
@ LINKTYPE_WATTSTOPPER_DLM
Definition: RawPacket.h:246
@ LINKTYPE_IEEE802_11_AVS
Definition: RawPacket.h:126
@ LINKTYPE_USER3
Definition: RawPacket.h:100
@ LINKTYPE_USER1
Definition: RawPacket.h:96
@ LINKTYPE_CAN_SOCKETCAN
Definition: RawPacket.h:178
@ LINKTYPE_PPP
Definition: RawPacket.h:39
@ LINKTYPE_ISO_14443
Definition: RawPacket.h:250
@ LINKTYPE_MTP2
Definition: RawPacket.h:84
@ LINKTYPE_PPP_HDLC
Definition: RawPacket.h:48
@ LINKTYPE_LTALK
Definition: RawPacket.h:66
@ LINKTYPE_PPP_ETHER
Definition: RawPacket.h:50
@ LINKTYPE_USER0
Definition: RawPacket.h:94
@ LINKTYPE_IPMB_LINUX
Definition: RawPacket.h:166
@ LINKTYPE_IPV6
Definition: RawPacket.h:182
@ LINKTYPE_NETANALYZER
Definition: RawPacket.h:200