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