Coverage Report

Created: 2024-02-25 06:29

/src/PcapPlusPlus/Packet++/header/RawPacket.h
Line
Count
Source (jump to first uncovered line)
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
12
/// @file
13
14
/**
15
 * \namespace pcpp
16
 * \brief The main namespace for the PcapPlusPlus lib
17
 */
18
namespace pcpp
19
{
20
21
  /**
22
   * An enum describing all known link layer type. Taken from: http://www.tcpdump.org/linktypes.html .
23
   */
24
  enum LinkLayerType
25
  {
26
    /** BSD loopback encapsulation */
27
    LINKTYPE_NULL = 0,
28
    /** IEEE 802.3 Ethernet */
29
    LINKTYPE_ETHERNET = 1,
30
    /** AX.25 packet */
31
    LINKTYPE_AX25 = 3,
32
    /** IEEE 802.5 Token Ring */
33
    LINKTYPE_IEEE802_5 = 6,
34
    /** ARCNET Data Packets */
35
    LINKTYPE_ARCNET_BSD = 7,
36
    /** SLIP, encapsulated with a LINKTYPE_SLIP header */
37
    LINKTYPE_SLIP = 8,
38
    /** PPP, as per RFC 1661 and RFC 1662 */
39
    LINKTYPE_PPP = 9,
40
    /** FDDI, as specified by ANSI INCITS 239-1994 */
41
    LINKTYPE_FDDI = 10,
42
    /** Raw IP */
43
    LINKTYPE_DLT_RAW1 = 12,
44
    /** Raw IP (OpenBSD) */
45
    LINKTYPE_DLT_RAW2 = 14,
46
    /** PPP in HDLC-like framing, as per RFC 1662, or Cisco PPP with HDLC framing, as per section 4.3.1 of RFC 1547 */
47
    LINKTYPE_PPP_HDLC = 50,
48
    /** PPPoE */
49
    LINKTYPE_PPP_ETHER = 51,
50
    /** RFC 1483 LLC/SNAP-encapsulated ATM */
51
    LINKTYPE_ATM_RFC1483 = 100,
52
    /** Raw IP */
53
    LINKTYPE_RAW = 101,
54
    /** Cisco PPP with HDLC framing */
55
    LINKTYPE_C_HDLC = 104,
56
    /** IEEE 802.11 wireless LAN */
57
    LINKTYPE_IEEE802_11 = 105,
58
    /** Frame Relay */
59
    LINKTYPE_FRELAY = 107,
60
    /** OpenBSD loopback encapsulation */
61
    LINKTYPE_LOOP = 108,
62
    /** Linux "cooked" capture encapsulation */
63
    LINKTYPE_LINUX_SLL = 113,
64
    /** Apple LocalTalk */
65
    LINKTYPE_LTALK = 114,
66
    /** OpenBSD pflog */
67
    LINKTYPE_PFLOG = 117,
68
    /** Prism monitor mode information followed by an 802.11 header */
69
    LINKTYPE_IEEE802_11_PRISM = 119,
70
    /** RFC 2625 IP-over-Fibre Channel */
71
    LINKTYPE_IP_OVER_FC = 122,
72
    /** ATM traffic, encapsulated as per the scheme used by SunATM devices */
73
    LINKTYPE_SUNATM = 123,
74
    /** Radiotap link-layer information followed by an 802.11 header */
75
    LINKTYPE_IEEE802_11_RADIOTAP = 127,
76
    /** ARCNET Data Packets, as described by the ARCNET Trade Association standard ATA 878.1-1999 */
77
    LINKTYPE_ARCNET_LINUX = 129,
78
    /** Apple IP-over-IEEE 1394 cooked header */
79
    LINKTYPE_APPLE_IP_OVER_IEEE1394 = 138,
80
    /** Signaling System 7 Message Transfer Part Level 2 */
81
    LINKTYPE_MTP2_WITH_PHDR = 139,
82
    /** Signaling System 7 Message Transfer Part Level 2 */
83
    LINKTYPE_MTP2 = 140,
84
    /** Signaling System 7 Message Transfer Part Level 3 */
85
    LINKTYPE_MTP3 = 141,
86
    /** Signaling System 7 Signalling Connection Control Part */
87
    LINKTYPE_SCCP = 142,
88
    /** Signaling System 7 Signalling Connection Control Part */
89
    LINKTYPE_DOCSIS = 143,
90
    /** Linux-IrDA packets */
91
    LINKTYPE_LINUX_IRDA = 144,
92
    /** Reserved for private use */
93
    LINKTYPE_USER0 = 147,
94
    /** Reserved for private use */
95
    LINKTYPE_USER1 = 148,
96
    /** Reserved for private use */
97
    LINKTYPE_USER2 = 149,
98
    /** Reserved for private use */
99
    LINKTYPE_USER3 = 150,
100
    /** Reserved for private use */
101
    LINKTYPE_USER4 = 151,
102
    /** Reserved for private use */
103
    LINKTYPE_USER5 = 152,
104
    /** Reserved for private use */
105
    LINKTYPE_USER6 = 153,
106
    /** Reserved for private use */
107
    LINKTYPE_USER7 = 154,
108
    /** Reserved for private use */
109
    LINKTYPE_USER8 = 155,
110
    /** Reserved for private use */
111
    LINKTYPE_USER9 = 156,
112
    /** Reserved for private use */
113
    LINKTYPE_USER10 = 157,
114
    /** Reserved for private use */
115
    LINKTYPE_USER11 = 158,
116
    /** Reserved for private use */
117
    LINKTYPE_USER12 = 159,
118
    /** Reserved for private use */
119
    LINKTYPE_USER13 = 160,
120
    /** Reserved for private use */
121
    LINKTYPE_USER14 = 161,
122
    /** Reserved for private use */
123
    LINKTYPE_USER15 = 162,
124
    /** AVS monitor mode information followed by an 802.11 header */
125
    LINKTYPE_IEEE802_11_AVS = 163,
126
    /** BACnet MS/TP frames */
127
    LINKTYPE_BACNET_MS_TP = 165,
128
    /** PPP in HDLC-like encapsulation, like LINKTYPE_PPP_HDLC, but with the 0xff address byte replaced by a direction indication - 0x00 for incoming and 0x01 for outgoing */
129
    LINKTYPE_PPP_PPPD = 166,
130
    /** General Packet Radio Service Logical Link Control */
131
    LINKTYPE_GPRS_LLC = 169,
132
    /** Transparent-mapped generic framing procedure */
133
    LINKTYPE_GPF_T = 170,
134
    /** Frame-mapped generic framing procedure */
135
    LINKTYPE_GPF_F = 171,
136
    /** Link Access Procedures on the D Channel (LAPD) frames */
137
    LINKTYPE_LINUX_LAPD = 177,
138
    /** Bluetooth HCI UART transport layer */
139
    LINKTYPE_BLUETOOTH_HCI_H4 = 187,
140
    /** USB packets, beginning with a Linux USB header */
141
    LINKTYPE_USB_LINUX = 189,
142
    /** Per-Packet Information information */
143
    LINKTYPE_PPI = 192,
144
    /** IEEE 802.15.4 wireless Personal Area Network */
145
    LINKTYPE_IEEE802_15_4 = 195,
146
    /** Various link-layer types, with a pseudo-header, for SITA */
147
    LINKTYPE_SITA = 196,
148
    /** Various link-layer types, with a pseudo-header, for Endace DAG cards; encapsulates Endace ERF record */
149
    LINKTYPE_ERF = 197,
150
    /** Bluetooth HCI UART transport layer */
151
    LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR = 201,
152
    /** AX.25 packet, with a 1-byte KISS header containing a type indicator */
153
    LINKTYPE_AX25_KISS = 202,
154
    /** Link Access Procedures on the D Channel (LAPD) frames */
155
    LINKTYPE_LAPD = 203,
156
    /** PPP, as per RFC 1661 and RFC 1662, preceded with a one-byte pseudo-header with a zero value meaning "received by this host" and a non-zero value meaning  "sent by this host" */
157
    LINKTYPE_PPP_WITH_DIR = 204,
158
    /** Cisco PPP with HDLC framing */
159
    LINKTYPE_C_HDLC_WITH_DIR = 205,
160
    /** Frame Relay */
161
    LINKTYPE_FRELAY_WITH_DIR = 206,
162
    /** IPMB over an I2C circuit */
163
    LINKTYPE_IPMB_LINUX = 209,
164
    /** IEEE 802.15.4 wireless Personal Area Network */
165
    LINKTYPE_IEEE802_15_4_NONASK_PHY = 215,
166
    /** USB packets, beginning with a Linux USB header */
167
    LINKTYPE_USB_LINUX_MMAPPED = 220,
168
    /** Fibre Channel FC-2 frames, beginning with a Frame_Header */
169
    LINKTYPE_FC_2 = 224,
170
    /** Fibre Channel FC-2 frames */
171
    LINKTYPE_FC_2_WITH_FRAME_DELIMS = 225,
172
    /** Solaris ipnet pseudo-header */
173
    LINKTYPE_IPNET = 226,
174
    /** CAN (Controller Area Network) frames, with a pseudo-header as supplied by Linux SocketCAN */
175
    LINKTYPE_CAN_SOCKETCAN = 227,
176
    /** Raw IPv4; the packet begins with an IPv4 header */
177
    LINKTYPE_IPV4 = 228,
178
    /** Raw IPv6; the packet begins with an IPv6 header */
179
    LINKTYPE_IPV6 = 229,
180
    /** IEEE 802.15.4 wireless Personal Area Network, without the FCS at the end of the frame */
181
    LINKTYPE_IEEE802_15_4_NOFCS = 230,
182
    /** Raw D-Bus messages, starting with the endianness flag, followed by the message type, etc., but without the authentication handshake before the message sequence */
183
    LINKTYPE_DBUS = 231,
184
    /** DVB-CI (DVB Common Interface for communication between a PC Card module and a DVB receiver), with the message format specified by the PCAP format for DVB-CI specification */
185
    LINKTYPE_DVB_CI = 235,
186
    /** Variant of 3GPP TS 27.010 multiplexing protocol (similar to, but not the same as, 27.010) */
187
    LINKTYPE_MUX27010 = 236,
188
    /** D_PDUs as described by NATO standard STANAG 5066, starting with the synchronization sequence, and including both header and data CRCs */
189
    LINKTYPE_STANAG_5066_D_PDU = 237,
190
    /** Linux netlink NETLINK NFLOG socket log messages */
191
    LINKTYPE_NFLOG = 239,
192
    /** Pseudo-header for Hilscher Gesellschaft für Systemautomation mbH netANALYZER devices, followed by an Ethernet frame, beginning with the MAC header and ending with the FCS */
193
    LINKTYPE_NETANALYZER = 240,
194
    /** Pseudo-header for Hilscher Gesellschaft für Systemautomation mbH netANALYZER devices, followed by an Ethernet frame, beginning with the preamble, SFD, and MAC header, and ending with the FCS */
195
    LINKTYPE_NETANALYZER_TRANSPARENT = 241,
196
    /** IP-over-InfiniBand, as specified by RFC 4391 section 6 */
197
    LINKTYPE_IPOIB = 242,
198
    /** MPEG-2 Transport Stream transport packets, as specified by ISO 13818-1/ITU-T Recommendation H.222.0 */
199
    LINKTYPE_MPEG_2_TS = 243,
200
    /** Pseudo-header for ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as used by their ng40 protocol tester */
201
    LINKTYPE_NG40 = 244,
202
    /** Pseudo-header for NFC LLCP packet captures, followed by frame data for the LLCP Protocol as specified by NFCForum-TS-LLCP_1.1 */
203
    LINKTYPE_NFC_LLCP = 245,
204
    /** Raw InfiniBand frames, starting with the Local Routing Header */
205
    LINKTYPE_INFINIBAND = 247,
206
    /** SCTP packets, as defined by RFC 4960, with no lower-level protocols such as IPv4 or IPv6 */
207
    LINKTYPE_SCTP = 248,
208
    /** USB packets, beginning with a USBPcap header */
209
    LINKTYPE_USBPCAP = 249,
210
    /** Serial-line packet header for the Schweitzer Engineering Laboratories "RTAC" product */
211
    LINKTYPE_RTAC_SERIAL = 250,
212
    /** Bluetooth Low Energy air interface Link Layer packets */
213
    LINKTYPE_BLUETOOTH_LE_LL = 251,
214
    /** Linux Netlink capture encapsulation */
215
    LINKTYPE_NETLINK = 253,
216
    /** Bluetooth Linux Monitor encapsulation of traffic for the BlueZ stack */
217
    LINKTYPE_BLUETOOTH_LINUX_MONITOR = 254,
218
    /** Bluetooth Basic Rate and Enhanced Data Rate baseband packets */
219
    LINKTYPE_BLUETOOTH_BREDR_BB = 255,
220
    /** Bluetooth Low Energy link-layer packets */
221
    LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR = 256,
222
    /** PROFIBUS data link layer packets, as specified by IEC standard 61158-6-3 */
223
    LINKTYPE_PROFIBUS_DL = 257,
224
    /** Apple PKTAP capture encapsulation */
225
    LINKTYPE_PKTAP = 258,
226
    /** Ethernet-over-passive-optical-network packets */
227
    LINKTYPE_EPON = 259,
228
    /** IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format" in the PICMG HPM.2 specification */
229
    LINKTYPE_IPMI_HPM_2 = 260,
230
    /** Per Joshua Wright <jwright@hasborg.com>, formats for Z-Wave RF profiles R1 and R2 captures */
231
    LINKTYPE_ZWAVE_R1_R2 = 261,
232
    /** Per Joshua Wright <jwright@hasborg.com>, formats for Z-Wave RF profile R3 captures */
233
    LINKTYPE_ZWAVE_R3 = 262,
234
    /** Formats for WattStopper Digital Lighting Management (DLM) and Legrand Nitoo Open protocol common packet structure captures */
235
    LINKTYPE_WATTSTOPPER_DLM = 263,
236
    /** Messages between ISO 14443 contactless smartcards (Proximity Integrated Circuit Card, PICC) and card readers (Proximity Coupling Device, PCD), with the message format specified by the PCAP format for ISO14443 specification */
237
    LINKTYPE_ISO_14443 = 264,
238
    /** Linux "cooked" capture encapsulation v2 */
239
    LINKTYPE_LINUX_SLL2 = 276
240
  };
241
242
  /**
243
   * Max packet size supported
244
   */
245
47
#define PCPP_MAX_PACKET_SIZE 65536
246
247
  /**
248
   * @class RawPacket
249
   * This class holds the packet as raw (not parsed) data. The data is held as byte array. In addition to the data itself
250
   * every instance also holds a timestamp representing the time the packet was received by the NIC.
251
   * RawPacket instance isn't read only. The user can change the packet data, add or remove data, etc.
252
   */
253
  class RawPacket
254
  {
255
  protected:
256
    uint8_t* m_RawData;
257
    int m_RawDataLen;
258
    int m_FrameLength;
259
    timespec m_TimeStamp;
260
    bool m_DeleteRawDataAtDestructor;
261
    bool m_RawPacketSet;
262
    LinkLayerType m_LinkLayerType;
263
    void init(bool deleteRawDataAtDestructor = true);
264
    void copyDataFrom(const RawPacket& other, bool allocateData = true);
265
  public:
266
    /**
267
     * A constructor that receives a pointer to the raw data (allocated elsewhere). This constructor is usually used when packet
268
     * is captured using a packet capturing engine (like libPcap. WinPcap, Npcap, PF_RING, etc.). The capturing engine allocates the raw data
269
     * memory and give the user a pointer to it + a timestamp it has arrived to the device
270
     * @param[in] pRawData A pointer to the raw data
271
     * @param[in] rawDataLen The raw data length in bytes
272
     * @param[in] timestamp The timestamp packet was received by the NIC (in usec precision)
273
     * @param[in] deleteRawDataAtDestructor An indicator whether raw data pointer should be freed when the instance is freed or not. If set
274
     * to 'true' than pRawData will be freed when instanced is being freed
275
     * @param[in] layerType The link layer type of this raw packet. The default is Ethernet
276
     */
277
    RawPacket(const uint8_t* pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
278
279
    /**
280
     * A constructor that receives a pointer to the raw data (allocated elsewhere). This constructor is usually used when packet
281
     * is captured using a packet capturing engine (like libPcap. WinPcap, Npcap, PF_RING, etc.). The capturing engine allocates the raw data
282
     * memory and give the user a pointer to it + a timestamp it has arrived to the device
283
     * @param[in] pRawData A pointer to the raw data
284
     * @param[in] rawDataLen The raw data length in bytes
285
     * @param[in] timestamp The timestamp packet was received by the NIC (in nsec precision)
286
     * @param[in] deleteRawDataAtDestructor An indicator whether raw data pointer should be freed when the instance is freed or not. If set
287
     * to 'true' than pRawData will be freed when instanced is being freed
288
     * @param[in] layerType The link layer type of this raw packet. The default is Ethernet
289
     */
290
    RawPacket(const uint8_t* pRawData, int rawDataLen, timespec timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
291
292
    /**
293
     * A default constructor that initializes class'es attributes to default value:
294
     * - data pointer is set to NULL
295
     * - data length is set to 0
296
     * - deleteRawDataAtDestructor is set to 'true'
297
     * @todo timestamp isn't set here to a default value
298
     */
299
    RawPacket();
300
301
    /**
302
     * A destructor for this class. Frees the raw data if deleteRawDataAtDestructor was set to 'true'
303
     */
304
    virtual ~RawPacket();
305
306
    /**
307
     * A copy constructor that copies all data from another instance. Notice all raw data is copied (using memcpy), so when the original or
308
     * the other instance are freed, the other won't be affected
309
     * @param[in] other The instance to copy from
310
     */
311
    RawPacket(const RawPacket& other);
312
313
    /**
314
     * Assignment operator overload for this class. When using this operator on an already initialized RawPacket instance,
315
     * the original raw data is freed first. Then the other instance is copied to this instance, the same way the copy constructor works
316
     * @todo free raw data only if deleteRawDataAtDestructor was set to 'true'
317
     * @param[in] other The instance to copy from
318
     */
319
    RawPacket& operator=(const RawPacket& other);
320
321
    /**
322
     * @return RawPacket object type. Each derived class should return a different value
323
     */
324
0
    virtual uint8_t getObjectType() const { return 0; }
325
326
    /**
327
     * Set a raw data. If data was already set and deleteRawDataAtDestructor was set to 'true' the old data will be freed first
328
     * @param[in] pRawData A pointer to the new raw data
329
     * @param[in] rawDataLen The new raw data length in bytes
330
     * @param[in] timestamp The timestamp packet was received by the NIC (in usec precision)
331
     * @param[in] layerType The link layer type for this raw data
332
     * @param[in] frameLength When reading from pcap files, sometimes the captured length is different from the actual packet length. This parameter represents the packet
333
     * length. This parameter is optional, if not set or set to -1 it is assumed both lengths are equal
334
     * @return True if raw data was set successfully, false otherwise
335
     */
336
    virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
337
338
    /**
339
     * Set a raw data. If data was already set and deleteRawDataAtDestructor was set to 'true' the old data will be freed first
340
     * @param[in] pRawData A pointer to the new raw data
341
     * @param[in] rawDataLen The new raw data length in bytes
342
     * @param[in] timestamp The timestamp packet was received by the NIC (in nsec precision)
343
     * @param[in] layerType The link layer type for this raw data
344
     * @param[in] frameLength When reading from pcap files, sometimes the captured length is different from the actual packet length. This parameter represents the packet
345
     * length. This parameter is optional, if not set or set to -1 it is assumed both lengths are equal
346
     * @return True if raw data was set successfully, false otherwise
347
     */
348
    virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
349
350
    /**
351
     * Initialize a raw packet with data. The main difference between this method and setRawData() is that setRawData()
352
     * is meant for replacing the data in an existing raw packet, whereas this method is meant to be used right after
353
     * constructing a raw packet using the default c'tor, before setting any data
354
     * @param pRawData A pointer to the new raw data
355
     * @param rawDataLen The new raw data length in bytes
356
     * @param timestamp The timestamp packet was received by the NIC (in nsec precision)
357
     * @param layerType The link layer type for this raw data
358
     * @return True if raw data was set successfully, false otherwise
359
     */
360
    bool initWithRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET);
361
362
    /**
363
     * Get raw data pointer
364
     * @return A read-only pointer to the raw data
365
     */
366
2.03M
    const uint8_t* getRawData() const { return m_RawData; }
367
368
    /**
369
     * Get the link layer type
370
     * @return the type of the link layer
371
     */
372
1.26M
    LinkLayerType getLinkLayerType() const { return m_LinkLayerType; }
373
374
    /**
375
     * This static method validates whether a link type integer value is valid
376
     * @param[in] linkTypeValue Link type integer value
377
     * @return True if the link type value is valid and can be casted into LinkLayerType enum, false otherwise
378
     */
379
    static bool isLinkTypeValid(int linkTypeValue);
380
381
    /**
382
     * Get raw data length in bytes
383
     * @return Raw data length in bytes
384
     */
385
2.31M
    int getRawDataLen() const { return m_RawDataLen; }
386
387
    /**
388
     * Get frame length in bytes
389
     * @return frame length in bytes
390
     */
391
26.0k
    int getFrameLength() const { return m_FrameLength; }
392
    /**
393
     * Get raw data timestamp
394
     * @return Raw data timestamp
395
     */
396
365k
    timespec getPacketTimeStamp() const { return m_TimeStamp; }
397
398
    /**
399
     * Set raw packet timestamp with usec precision
400
     * @param[in] timestamp The timestamp to set (with usec precision)
401
     * @return True if timestamp was set successfully, false otherwise
402
     */
403
    virtual bool setPacketTimeStamp(timeval timestamp);
404
405
    /**
406
     * Set raw packet timestamp with nsec precision
407
     * @param[in] timestamp The timestamp to set (with nsec precision)
408
     * @return True if timestamp was set successfully, false otherwise
409
     */
410
    virtual bool setPacketTimeStamp(timespec timestamp);
411
412
    /**
413
     * Get an indication whether raw data was already set for this instance.
414
     * @return True if raw data was set for this instance. Raw data can be set using the non-default constructor, using setRawData(), using
415
     * the copy constructor or using the assignment operator. Returns false otherwise, for example: if the instance was created using the
416
     * default constructor or clear() was called
417
     */
418
0
    bool isPacketSet() const { return m_RawPacketSet; }
419
420
    /**
421
     * Clears all members of this instance, meaning setting raw data to NULL, raw data length to 0, etc. Currently raw data is always freed,
422
     * even if deleteRawDataAtDestructor was set to 'false'
423
     * @todo deleteRawDataAtDestructor was set to 'true', don't free the raw data
424
     * @todo set timestamp to a default value as well
425
     */
426
    virtual void clear();
427
428
    /**
429
     * Append data to the end of current data. This method works without allocating more memory, it just uses memcpy() to copy dataToAppend at
430
     * 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
431
     * this method will cause memory corruption
432
     * @param[in] dataToAppend A pointer to the data to append to current raw data
433
     * @param[in] dataToAppendLen Length in bytes of dataToAppend
434
     */
435
    virtual void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
436
437
    /**
438
     * 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,
439
     * 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
440
     * already allocated by the user. If it isn't the case then this method will cause memory corruption
441
     * @param[in] atIndex The index to insert the new data to
442
     * @param[in] dataToInsert A pointer to the new data to insert
443
     * @param[in] dataToInsertLen Length in bytes of dataToInsert
444
     */
445
    virtual void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
446
447
    /**
448
     * Remove certain number of bytes from current raw data buffer. All data after the removed bytes will be shifted back
449
     * @param[in] atIndex The index to start removing bytes from
450
     * @param[in] numOfBytesToRemove Number of bytes to remove
451
     * @return True if all bytes were removed successfully, or false if atIndex+numOfBytesToRemove is out-of-bounds of the raw data buffer
452
     */
453
    virtual bool removeData(int atIndex, size_t numOfBytesToRemove);
454
455
    /**
456
     * 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
457
     * 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
458
     * 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
459
     * point to it
460
     * @param[in] newBufferLength The new buffer length as required by the user. The method is responsible to allocate the memory
461
     * @return True if data was reallocated successfully, false otherwise
462
     */
463
    virtual bool reallocateData(size_t newBufferLength);
464
  };
465
466
} // namespace pcpp