PcapPlusPlus  20.08
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,
239  };
240 
244 #define PCPP_MAX_PACKET_SIZE 65536
245 
252  class RawPacket
253  {
254  protected:
255  uint8_t* m_RawData;
256  int m_RawDataLen;
257  int m_FrameLength;
258  timespec m_TimeStamp;
259  bool m_DeleteRawDataAtDestructor;
260  bool m_RawPacketSet;
261  LinkLayerType m_LinkLayerType;
262  void init(bool deleteRawDataAtDestructor = true);
263  void copyDataFrom(const RawPacket& other, bool allocateData = true);
264  public:
276  RawPacket(const uint8_t* pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
277 
289  RawPacket(const uint8_t* pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
290 
298  RawPacket();
299 
303  virtual ~RawPacket();
304 
310  RawPacket(const RawPacket& other);
311 
318  RawPacket& operator=(const RawPacket& other);
319 
323  virtual uint8_t getObjectType() const { return 0; }
324 
335  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
336 
347  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
348 
353  const uint8_t* getRawData() const { return m_RawData; }
354 
359  LinkLayerType getLinkLayerType() const { return m_LinkLayerType; }
360 
366  static bool isLinkTypeValid(int linkTypeValue);
367 
372  int getRawDataLen() const { return m_RawDataLen; }
373 
378  int getFrameLength() const { return m_FrameLength; }
383  timespec getPacketTimeStamp() const { return m_TimeStamp; }
384 
390  virtual bool setPacketTimeStamp(timeval timestamp);
391 
397  virtual bool setPacketTimeStamp(timespec timestamp);
398 
405  bool isPacketSet() const { return m_RawPacketSet; }
406 
413  virtual void clear();
414 
422  virtual void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
423 
432  virtual void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
433 
440  virtual bool removeData(int atIndex, size_t numOfBytesToRemove);
441 
450  virtual bool reallocateData(size_t newBufferLength);
451  };
452 
453 } // namespace pcpp
454 
455 #endif
pcpp::RawPacket::removeData
virtual bool removeData(int atIndex, size_t numOfBytesToRemove)
pcpp::LINKTYPE_DOCSIS
@ LINKTYPE_DOCSIS
Definition: RawPacket.h:90
pcpp::LINKTYPE_IEEE802_11
@ LINKTYPE_IEEE802_11
Definition: RawPacket.h:58
pcpp::LINKTYPE_FC_2
@ LINKTYPE_FC_2
Definition: RawPacket.h:170
pcpp::LINKTYPE_FRELAY
@ LINKTYPE_FRELAY
Definition: RawPacket.h:60
pcpp::LINKTYPE_USER9
@ LINKTYPE_USER9
Definition: RawPacket.h:112
pcpp::LINKTYPE_BLUETOOTH_HCI_H4
@ LINKTYPE_BLUETOOTH_HCI_H4
Definition: RawPacket.h:140
pcpp::RawPacket::RawPacket
RawPacket()
pcpp::RawPacket::appendData
virtual void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
pcpp::LINKTYPE_USER10
@ LINKTYPE_USER10
Definition: RawPacket.h:114
pcpp::LINKTYPE_AX25_KISS
@ LINKTYPE_AX25_KISS
Definition: RawPacket.h:154
pcpp::LINKTYPE_USER8
@ LINKTYPE_USER8
Definition: RawPacket.h:110
pcpp::LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR
@ LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR
Definition: RawPacket.h:222
pcpp::LINKTYPE_SCTP
@ LINKTYPE_SCTP
Definition: RawPacket.h:208
pcpp::LINKTYPE_PROFIBUS_DL
@ LINKTYPE_PROFIBUS_DL
Definition: RawPacket.h:224
pcpp::LINKTYPE_MTP2
@ LINKTYPE_MTP2
Definition: RawPacket.h:84
pcpp::LINKTYPE_ETHERNET
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:30
pcpp::LINKTYPE_USER14
@ LINKTYPE_USER14
Definition: RawPacket.h:122
pcpp::LINKTYPE_C_HDLC_WITH_DIR
@ LINKTYPE_C_HDLC_WITH_DIR
Definition: RawPacket.h:160
pcpp::LINKTYPE_MTP2_WITH_PHDR
@ LINKTYPE_MTP2_WITH_PHDR
Definition: RawPacket.h:82
pcpp::RawPacket::setRawData
virtual bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
pcpp::LINKTYPE_LTALK
@ LINKTYPE_LTALK
Definition: RawPacket.h:66
pcpp::LINKTYPE_NFC_LLCP
@ LINKTYPE_NFC_LLCP
Definition: RawPacket.h:204
pcpp::LINKTYPE_NG40
@ LINKTYPE_NG40
Definition: RawPacket.h:202
pcpp::LINKTYPE_SLIP
@ LINKTYPE_SLIP
Definition: RawPacket.h:38
pcpp::LINKTYPE_WATTSTOPPER_DLM
@ LINKTYPE_WATTSTOPPER_DLM
Definition: RawPacket.h:236
pcpp::LINKTYPE_DLT_RAW2
@ LINKTYPE_DLT_RAW2
Definition: RawPacket.h:46
pcpp::LINKTYPE_LINUX_IRDA
@ LINKTYPE_LINUX_IRDA
Definition: RawPacket.h:92
pcpp::LINKTYPE_PPP_WITH_DIR
@ LINKTYPE_PPP_WITH_DIR
Definition: RawPacket.h:158
pcpp::LINKTYPE_IP_OVER_FC
@ LINKTYPE_IP_OVER_FC
Definition: RawPacket.h:72
pcpp::LINKTYPE_SITA
@ LINKTYPE_SITA
Definition: RawPacket.h:148
pcpp::LINKTYPE_USER11
@ LINKTYPE_USER11
Definition: RawPacket.h:116
pcpp::RawPacket::getRawDataLen
int getRawDataLen() const
Definition: RawPacket.h:372
pcpp::RawPacket::getObjectType
virtual uint8_t getObjectType() const
Definition: RawPacket.h:323
pcpp::LINKTYPE_IEEE802_11_RADIOTAP
@ LINKTYPE_IEEE802_11_RADIOTAP
Definition: RawPacket.h:76
pcpp::RawPacket::reallocateData
virtual bool reallocateData(size_t newBufferLength)
pcpp::LINKTYPE_USER2
@ LINKTYPE_USER2
Definition: RawPacket.h:98
pcpp::LINKTYPE_RAW
@ LINKTYPE_RAW
Definition: RawPacket.h:54
pcpp::RawPacket::getFrameLength
int getFrameLength() const
Definition: RawPacket.h:378
pcpp::LINKTYPE_NETANALYZER_TRANSPARENT
@ LINKTYPE_NETANALYZER_TRANSPARENT
Definition: RawPacket.h:196
pcpp::LINKTYPE_IPV4
@ LINKTYPE_IPV4
Definition: RawPacket.h:178
pcpp::LINKTYPE_USB_LINUX_MMAPPED
@ LINKTYPE_USB_LINUX_MMAPPED
Definition: RawPacket.h:168
pcpp::LINKTYPE_MUX27010
@ LINKTYPE_MUX27010
Definition: RawPacket.h:188
pcpp::LINKTYPE_IPMI_HPM_2
@ LINKTYPE_IPMI_HPM_2
Definition: RawPacket.h:230
pcpp::LINKTYPE_IPNET
@ LINKTYPE_IPNET
Definition: RawPacket.h:174
pcpp::LINKTYPE_USER1
@ LINKTYPE_USER1
Definition: RawPacket.h:96
pcpp::LINKTYPE_ERF
@ LINKTYPE_ERF
Definition: RawPacket.h:150
pcpp::LINKTYPE_C_HDLC
@ LINKTYPE_C_HDLC
Definition: RawPacket.h:56
pcpp::RawPacket::getRawData
const uint8_t * getRawData() const
Definition: RawPacket.h:353
pcpp::LINKTYPE_PPP_HDLC
@ LINKTYPE_PPP_HDLC
Definition: RawPacket.h:48
pcpp::LINKTYPE_FRELAY_WITH_DIR
@ LINKTYPE_FRELAY_WITH_DIR
Definition: RawPacket.h:162
pcpp::LINKTYPE_LINUX_SLL
@ LINKTYPE_LINUX_SLL
Definition: RawPacket.h:64
pcpp::LINKTYPE_IEEE802_15_4
@ LINKTYPE_IEEE802_15_4
Definition: RawPacket.h:146
pcpp::LINKTYPE_IEEE802_11_PRISM
@ LINKTYPE_IEEE802_11_PRISM
Definition: RawPacket.h:70
pcpp::LINKTYPE_PKTAP
@ LINKTYPE_PKTAP
Definition: RawPacket.h:226
pcpp::LINKTYPE_SCCP
@ LINKTYPE_SCCP
Definition: RawPacket.h:88
pcpp::LINKTYPE_RTAC_SERIAL
@ LINKTYPE_RTAC_SERIAL
Definition: RawPacket.h:212
pcpp::LINKTYPE_NETANALYZER
@ LINKTYPE_NETANALYZER
Definition: RawPacket.h:194
pcpp::RawPacket::~RawPacket
virtual ~RawPacket()
pcpp::RawPacket::operator=
RawPacket & operator=(const RawPacket &other)
pcpp::LINKTYPE_DVB_CI
@ LINKTYPE_DVB_CI
Definition: RawPacket.h:186
pcpp::LINKTYPE_PPP
@ LINKTYPE_PPP
Definition: RawPacket.h:40
pcpp::LINKTYPE_PPP_PPPD
@ LINKTYPE_PPP_PPPD
Definition: RawPacket.h:130
pcpp::LINKTYPE_GPF_F
@ LINKTYPE_GPF_F
Definition: RawPacket.h:136
pcpp::LINKTYPE_NULL
@ LINKTYPE_NULL
Definition: RawPacket.h:28
pcpp::RawPacket::insertData
virtual void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
pcpp::LINKTYPE_LINUX_LAPD
@ LINKTYPE_LINUX_LAPD
Definition: RawPacket.h:138
pcpp::LINKTYPE_BLUETOOTH_LINUX_MONITOR
@ LINKTYPE_BLUETOOTH_LINUX_MONITOR
Definition: RawPacket.h:218
pcpp::LINKTYPE_NETLINK
@ LINKTYPE_NETLINK
Definition: RawPacket.h:216
pcpp::LINKTYPE_GPF_T
@ LINKTYPE_GPF_T
Definition: RawPacket.h:134
pcpp::LINKTYPE_USER6
@ LINKTYPE_USER6
Definition: RawPacket.h:106
pcpp::LINKTYPE_USBPCAP
@ LINKTYPE_USBPCAP
Definition: RawPacket.h:210
pcpp::LINKTYPE_FDDI
@ LINKTYPE_FDDI
Definition: RawPacket.h:42
pcpp::LINKTYPE_ATM_RFC1483
@ LINKTYPE_ATM_RFC1483
Definition: RawPacket.h:52
pcpp::RawPacket::getLinkLayerType
LinkLayerType getLinkLayerType() const
Definition: RawPacket.h:359
pcpp::LINKTYPE_USER13
@ LINKTYPE_USER13
Definition: RawPacket.h:120
pcpp::LINKTYPE_IEEE802_15_4_NONASK_PHY
@ LINKTYPE_IEEE802_15_4_NONASK_PHY
Definition: RawPacket.h:166
pcpp::LINKTYPE_BLUETOOTH_LE_LL
@ LINKTYPE_BLUETOOTH_LE_LL
Definition: RawPacket.h:214
pcpp::LINKTYPE_PPP_ETHER
@ LINKTYPE_PPP_ETHER
Definition: RawPacket.h:50
pcpp::RawPacket::isPacketSet
bool isPacketSet() const
Definition: RawPacket.h:405
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR
@ LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR
Definition: RawPacket.h:152
pcpp::LINKTYPE_CAN_SOCKETCAN
@ LINKTYPE_CAN_SOCKETCAN
Definition: RawPacket.h:176
pcpp::LINKTYPE_EPON
@ LINKTYPE_EPON
Definition: RawPacket.h:228
pcpp::LINKTYPE_DLT_RAW1
@ LINKTYPE_DLT_RAW1
Definition: RawPacket.h:44
pcpp::LINKTYPE_APPLE_IP_OVER_IEEE1394
@ LINKTYPE_APPLE_IP_OVER_IEEE1394
Definition: RawPacket.h:80
pcpp::LinkLayerType
LinkLayerType
Definition: RawPacket.h:25
pcpp::LINKTYPE_AX25
@ LINKTYPE_AX25
Definition: RawPacket.h:32
pcpp::LINKTYPE_USER0
@ LINKTYPE_USER0
Definition: RawPacket.h:94
pcpp::LINKTYPE_MPEG_2_TS
@ LINKTYPE_MPEG_2_TS
Definition: RawPacket.h:200
pcpp::LINKTYPE_MTP3
@ LINKTYPE_MTP3
Definition: RawPacket.h:86
pcpp::LINKTYPE_IEEE802_15_4_NOFCS
@ LINKTYPE_IEEE802_15_4_NOFCS
Definition: RawPacket.h:182
pcpp::LINKTYPE_USER7
@ LINKTYPE_USER7
Definition: RawPacket.h:108
pcpp::LINKTYPE_ZWAVE_R1_R2
@ LINKTYPE_ZWAVE_R1_R2
Definition: RawPacket.h:232
pcpp::RawPacket::isLinkTypeValid
static bool isLinkTypeValid(int linkTypeValue)
pcpp::LINKTYPE_BLUETOOTH_BREDR_BB
@ LINKTYPE_BLUETOOTH_BREDR_BB
Definition: RawPacket.h:220
pcpp::LINKTYPE_SUNATM
@ LINKTYPE_SUNATM
Definition: RawPacket.h:74
pcpp::LINKTYPE_INFINIBAND
@ LINKTYPE_INFINIBAND
Definition: RawPacket.h:206
pcpp::LINKTYPE_USER5
@ LINKTYPE_USER5
Definition: RawPacket.h:104
pcpp::LINKTYPE_USER4
@ LINKTYPE_USER4
Definition: RawPacket.h:102
pcpp::LINKTYPE_ZWAVE_R3
@ LINKTYPE_ZWAVE_R3
Definition: RawPacket.h:234
pcpp::LINKTYPE_IPMB_LINUX
@ LINKTYPE_IPMB_LINUX
Definition: RawPacket.h:164
pcpp::LINKTYPE_FC_2_WITH_FRAME_DELIMS
@ LINKTYPE_FC_2_WITH_FRAME_DELIMS
Definition: RawPacket.h:172
pcpp::LINKTYPE_IEEE802_11_AVS
@ LINKTYPE_IEEE802_11_AVS
Definition: RawPacket.h:126
pcpp::LINKTYPE_IPV6
@ LINKTYPE_IPV6
Definition: RawPacket.h:180
pcpp::LINKTYPE_USER3
@ LINKTYPE_USER3
Definition: RawPacket.h:100
pcpp::LINKTYPE_LOOP
@ LINKTYPE_LOOP
Definition: RawPacket.h:62
pcpp::LINKTYPE_STANAG_5066_D_PDU
@ LINKTYPE_STANAG_5066_D_PDU
Definition: RawPacket.h:190
pcpp::LINKTYPE_ISO_14443
@ LINKTYPE_ISO_14443
Definition: RawPacket.h:238
pcpp::LINKTYPE_BACNET_MS_TP
@ LINKTYPE_BACNET_MS_TP
Definition: RawPacket.h:128
pcpp::RawPacket::clear
virtual void clear()
pcpp::LINKTYPE_ARCNET_BSD
@ LINKTYPE_ARCNET_BSD
Definition: RawPacket.h:36
pcpp::LINKTYPE_LAPD
@ LINKTYPE_LAPD
Definition: RawPacket.h:156
pcpp::LINKTYPE_NFLOG
@ LINKTYPE_NFLOG
Definition: RawPacket.h:192
pcpp::LINKTYPE_USB_LINUX
@ LINKTYPE_USB_LINUX
Definition: RawPacket.h:142
pcpp::LINKTYPE_IPOIB
@ LINKTYPE_IPOIB
Definition: RawPacket.h:198
pcpp::RawPacket::getPacketTimeStamp
timespec getPacketTimeStamp() const
Definition: RawPacket.h:383
pcpp::LINKTYPE_IEEE802_5
@ LINKTYPE_IEEE802_5
Definition: RawPacket.h:34
pcpp::LINKTYPE_PFLOG
@ LINKTYPE_PFLOG
Definition: RawPacket.h:68
pcpp::RawPacket::setPacketTimeStamp
virtual bool setPacketTimeStamp(timeval timestamp)
pcpp::LINKTYPE_PPI
@ LINKTYPE_PPI
Definition: RawPacket.h:144
pcpp::LINKTYPE_ARCNET_LINUX
@ LINKTYPE_ARCNET_LINUX
Definition: RawPacket.h:78
pcpp::RawPacket
Definition: RawPacket.h:252
pcpp::LINKTYPE_USER12
@ LINKTYPE_USER12
Definition: RawPacket.h:118
pcpp::LINKTYPE_DBUS
@ LINKTYPE_DBUS
Definition: RawPacket.h:184
pcpp::LINKTYPE_GPRS_LLC
@ LINKTYPE_GPRS_LLC
Definition: RawPacket.h:132
pcpp::LINKTYPE_USER15
@ LINKTYPE_USER15
Definition: RawPacket.h:124