Coverage Report

Created: 2025-11-16 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Pcap++/header/PcapFileDevice.h
Line
Count
Source
1
#pragma once
2
3
#include "PcapDevice.h"
4
#include "RawPacket.h"
5
#include <fstream>
6
7
// forward declaration for structs and typedefs defined in pcap.h
8
struct pcap_dumper;
9
typedef struct pcap_dumper pcap_dumper_t;
10
11
/// @file
12
13
/// @namespace pcpp
14
/// @brief The main namespace for the PcapPlusPlus lib
15
namespace pcpp
16
{
17
  namespace internal
18
  {
19
    /// @struct LightPcapNgHandle
20
    /// An opaque struct representing a handle for pcapng files.
21
    struct LightPcapNgHandle;
22
  }  // namespace internal
23
24
  /// @enum FileTimestampPrecision
25
  /// An enumeration representing the precision of timestamps in a pcap file.
26
  /// The precision can be Unknown, Micro, or Nano.
27
  enum class FileTimestampPrecision : int8_t
28
  {
29
    /// Precision is unknown or not set/determined
30
    Unknown = -1,
31
    /// Precision is in microseconds.
32
    Microseconds = 0,
33
    /// Precision is in nanoseconds.
34
    Nanoseconds = 1
35
  };
36
37
  /// @class IFileDevice
38
  /// An abstract class (cannot be instantiated, has a private c'tor) which is the parent class for all file devices
39
  class IFileDevice : public IPcapDevice
40
  {
41
  protected:
42
    bool m_DeviceOpened = false;
43
    std::string m_FileName;
44
45
    explicit IFileDevice(const std::string& fileName);
46
    virtual ~IFileDevice();
47
48
  public:
49
    /// @return The name of the file
50
    std::string getFileName() const;
51
52
    // override methods
53
54
    /// Close the file
55
    void close() override;
56
57
    bool isOpened() const override
58
1.02k
    {
59
1.02k
      return m_DeviceOpened;
60
1.02k
    }
61
62
    /// @brief Get the statistics for this device.
63
    ///
64
    /// The PcapStats structure will hold the following:
65
    /// - packetsRecv: Number of packets processed (read or written, depending on the device type)
66
    /// - packetsDrop: Number of packets dropped (not read or not written, depending on the device type)
67
    /// - packetsDropByInterface: Not supported for file devices, will always be 0
68
    ///
69
    /// @param[out] stats The stats object to fill in.
70
    void getStatistics(PcapStats& stats) const override;
71
72
  protected:
73
    /// @brief Report that packets were processed (read or written, depending on the device type).
74
    /// @param numPackets The number of packets processed. Default is 1.
75
    void reportPacketProcessed(uint64_t numPackets = 1)
76
214k
    {
77
214k
      m_NumOfPacketsProcessed += numPackets;
78
214k
    }
79
80
    /// @brief Report that packets were dropped (not read or not written, depending on the device type).
81
    /// @param numPackets The number of packets dropped. Default is 1.
82
    void reportPacketDropped(uint64_t numPackets = 1)
83
4.24k
    {
84
4.24k
      m_NumOfPacketsDropped += numPackets;
85
4.24k
    }
86
87
    /// @brief Reset the internal statistic counters to zero.
88
    void resetStatisticCounters();
89
90
  private:
91
    uint64_t m_NumOfPacketsProcessed = 0;
92
    uint64_t m_NumOfPacketsDropped = 0;
93
  };
94
95
  /// @class IFileReaderDevice
96
  /// An abstract class (cannot be instantiated, has a private c'tor) which is the parent class for file reader
97
  /// devices
98
  class IFileReaderDevice : public IFileDevice
99
  {
100
  protected:
101
    /// A constructor for this class that gets the pcap full path file name to open. Notice that after calling this
102
    /// constructor the file isn't opened yet, so reading packets will fail. For opening the file call open()
103
    /// @param[in] fileName The full path of the file to read
104
    IFileReaderDevice(const std::string& fileName);
105
106
  public:
107
    /// A destructor for this class
108
    virtual ~IFileReaderDevice() = default;
109
110
    /// @return The file size in bytes
111
    uint64_t getFileSize() const;
112
113
    virtual bool getNextPacket(RawPacket& rawPacket) = 0;
114
115
    /// Read the next N packets into a raw packet vector
116
    /// @param[out] packetVec The raw packet vector to read packets into
117
    /// @param[in] numOfPacketsToRead Number of packets to read. If value <0 all remaining packets in the file will
118
    /// be read into the raw packet vector (this is the default value)
119
    /// @return The number of packets actually read
120
    int getNextPackets(RawPacketVector& packetVec, int numOfPacketsToRead = -1);
121
122
    /// A static method that creates an instance of the reader best fit to read the file. It decides by the file
123
    /// extension: for .pcapng files it returns an instance of PcapNgFileReaderDevice and for all other extensions
124
    /// it returns an instance of PcapFileReaderDevice
125
    /// @param[in] fileName The file name to open
126
    /// @return An instance of the reader to read the file. Notice you should free this instance when done using it
127
    static IFileReaderDevice* getReader(const std::string& fileName);
128
  };
129
130
  /// @class IFileWriterDevice
131
  /// An abstract class (cannot be instantiated, has a private c'tor) which is the parent class for file writer
132
  /// devices
133
  class IFileWriterDevice : public IFileDevice
134
  {
135
  protected:
136
    IFileWriterDevice(const std::string& fileName);
137
138
  public:
139
    /// A destructor for this class
140
    virtual ~IFileWriterDevice() = default;
141
142
    virtual bool writePacket(RawPacket const& packet) = 0;
143
144
    virtual bool writePackets(const RawPacketVector& packets) = 0;
145
146
    using IFileDevice::open;
147
    virtual bool open(bool appendMode) = 0;
148
  };
149
150
  /// @class PcapFileReaderDevice
151
  /// A class for opening a pcap file in read-only mode. This class enable to open the file and read all packets,
152
  /// packet-by-packet
153
  class PcapFileReaderDevice : public IFileReaderDevice
154
  {
155
  private:
156
    FileTimestampPrecision m_Precision;
157
    LinkLayerType m_PcapLinkLayerType;
158
159
    // private copy c'tor
160
    PcapFileReaderDevice(const PcapFileReaderDevice& other);
161
    PcapFileReaderDevice& operator=(const PcapFileReaderDevice& other);
162
163
  public:
164
    /// A constructor for this class that gets the pcap full path file name to open. Notice that after calling this
165
    /// constructor the file isn't opened yet, so reading packets will fail. For opening the file call open()
166
    /// @param[in] fileName The full path of the file to read
167
    PcapFileReaderDevice(const std::string& fileName)
168
4.41k
        : IFileReaderDevice(fileName), m_Precision(FileTimestampPrecision::Unknown),
169
4.41k
          m_PcapLinkLayerType(LINKTYPE_ETHERNET)
170
4.41k
    {}
171
172
    /// A destructor for this class
173
    virtual ~PcapFileReaderDevice() = default;
174
175
    /// @return The link layer type of this file
176
    LinkLayerType getLinkLayerType() const
177
0
    {
178
0
      return m_PcapLinkLayerType;
179
0
    }
180
181
    /// @return The precision of the timestamps in the file. If the platform supports nanosecond precision, this
182
    /// method will return nanoseconds even if the file has microseconds since libpcap scales timestamps before
183
    /// supply. Otherwise, it will return microseconds.
184
    FileTimestampPrecision getTimestampPrecision() const
185
0
    {
186
0
      return m_Precision;
187
0
    }
188
189
    /// A static method that checks if nano-second precision is supported in the current platform and environment
190
    /// @return True if nano-second precision is supported, false otherwise
191
    static bool isNanoSecondPrecisionSupported();
192
193
    // overridden methods
194
195
    /// Read the next packet from the file. Before using this method please verify the file is opened using open()
196
    /// @param[out] rawPacket A reference for an empty RawPacket where the packet will be written
197
    /// @return True if a packet was read successfully. False will be returned if the file isn't opened (also, an
198
    /// error log will be printed) or if reached end-of-file
199
    bool getNextPacket(RawPacket& rawPacket);
200
201
    /// Open the file name which path was specified in the constructor in a read-only mode
202
    /// @return True if file was opened successfully or if file is already opened. False if opening the file failed
203
    /// for some reason (for example: file path does not exist)
204
    bool open();
205
  };
206
207
  /// @class PcapFileWriterDevice
208
  /// A class for opening a pcap file for writing or create a new pcap file and write packets to it. This class adds
209
  /// a unique capability that isn't supported in WinPcap and in older libpcap versions which is to open a pcap file
210
  /// in append mode where packets are written at the end of the pcap file instead of running it over
211
  class PcapFileWriterDevice : public IFileWriterDevice
212
  {
213
  private:
214
    pcap_dumper_t* m_PcapDumpHandler;
215
    LinkLayerType m_PcapLinkLayerType;
216
    bool m_AppendMode;
217
    FileTimestampPrecision m_Precision;
218
    FILE* m_File;
219
220
    // private copy c'tor
221
    PcapFileWriterDevice(const PcapFileWriterDevice& other);
222
    PcapFileWriterDevice& operator=(const PcapFileWriterDevice& other);
223
224
    void closeFile();
225
226
  public:
227
    /// A constructor for this class that gets the pcap full path file name to open for writing or create. Notice
228
    /// that after calling this constructor the file isn't opened yet, so writing packets will fail. For opening the
229
    /// file call open()
230
    /// @param[in] fileName The full path of the file
231
    /// @param[in] linkLayerType The link layer type all packet in this file will be based on. The default is
232
    /// Ethernet
233
    /// @param[in] nanosecondsPrecision A boolean indicating whether to write timestamps in nano-precision. If set
234
    /// to false, timestamps will be written in micro-precision
235
    /// @throws std::runtime_error if nanosecondsPrecision is set to `true` but the current platform and environment
236
    /// doesn't support it.
237
    PcapFileWriterDevice(const std::string& fileName, LinkLayerType linkLayerType = LINKTYPE_ETHERNET,
238
                         bool nanosecondsPrecision = false);
239
240
    /// A destructor for this class
241
    ~PcapFileWriterDevice()
242
1.02k
    {
243
1.02k
      PcapFileWriterDevice::close();
244
1.02k
    }
245
246
    /// Write a RawPacket to the file. Before using this method please verify the file is opened using open(). This
247
    /// method won't change the written packet
248
    /// @param[in] packet A reference for an existing RawPcket to write to the file
249
    /// @return True if a packet was written successfully. False will be returned if the file isn't opened
250
    /// or if the packet link layer type is different than the one defined for the file
251
    /// (in all cases, an error will be printed to log)
252
    bool writePacket(RawPacket const& packet) override;
253
254
    /// Write multiple RawPacket to the file. Before using this method please verify the file is opened using
255
    /// open(). This method won't change the written packets or the RawPacketVector instance
256
    /// @param[in] packets A reference for an existing RawPcketVector, all of its packets will be written to the
257
    /// file
258
    /// @return True if all packets were written successfully to the file. False will be returned if the file isn't
259
    /// opened (also, an error log will be printed) or if at least one of the packets wasn't written successfully to
260
    /// the file
261
    bool writePackets(const RawPacketVector& packets) override;
262
263
    /// @return The precision of the timestamps in the file.
264
    FileTimestampPrecision getTimestampPrecision() const
265
0
    {
266
0
      return m_Precision;
267
0
    }
268
269
    /// A static method that checks if nano-second precision is supported in the current platform and environment
270
    /// @return True if nano-second precision is supported, false otherwise
271
    static bool isNanoSecondPrecisionSupported();
272
273
    // override methods
274
275
    /// Open the file in a write mode. If file doesn't exist, it will be created. If it does exist it will be
276
    /// overwritten, meaning all its current content will be deleted
277
    /// @return True if file was opened/created successfully or if file is already opened. False if opening the file
278
    /// failed for some reason (an error will be printed to log)
279
    bool open() override;
280
281
    /// Same as open(), but enables to open the file in append mode in which packets will be appended to the file
282
    /// instead of overwrite its current content. In append mode file must exist, otherwise opening will fail
283
    /// @param[in] appendMode A boolean indicating whether to open the file in append mode or not. If set to false
284
    /// this method will act exactly like open(). If set to true, file will be opened in append mode
285
    /// @return True of managed to open the file successfully. In case appendMode is set to true, false will be
286
    /// returned if file wasn't found or couldn't be read, if file type is not pcap, or if link type specified in
287
    /// c'tor is different from current file link type. In case appendMode is set to false, please refer to open()
288
    /// for return values
289
    bool open(bool appendMode) override;
290
291
    /// Flush and close the pacp file
292
    void close() override;
293
294
    /// Flush packets to disk.
295
    void flush();
296
297
  private:
298
    bool openWrite();
299
    bool openAppend();
300
  };
301
302
  /// @class PcapNgFileReaderDevice
303
  /// A class for opening a pcap-ng file in read-only mode. This class enable to open the file and read all packets,
304
  /// packet-by-packet
305
  class PcapNgFileReaderDevice : public IFileReaderDevice
306
  {
307
  private:
308
    internal::LightPcapNgHandle* m_LightPcapNg;
309
    BpfFilterWrapper m_BpfWrapper;
310
311
    // private copy c'tor
312
    PcapNgFileReaderDevice(const PcapNgFileReaderDevice& other);
313
    PcapNgFileReaderDevice& operator=(const PcapNgFileReaderDevice& other);
314
315
  public:
316
    /// A constructor for this class that gets the pcap-ng full path file name to open. Notice that after calling
317
    /// this constructor the file isn't opened yet, so reading packets will fail. For opening the file call open()
318
    /// @param[in] fileName The full path of the file to read
319
    PcapNgFileReaderDevice(const std::string& fileName);
320
321
    /// A destructor for this class
322
    virtual ~PcapNgFileReaderDevice()
323
5.90k
    {
324
5.90k
      close();
325
5.90k
    }
326
327
    /// The pcap-ng format allows storing metadata at the header of the file. Part of this metadata is a string
328
    /// specifying the operating system that was used for capturing the packets. This method reads this string from
329
    /// the metadata (if exists) and returns it
330
    /// @return The operating system string if exists, or an empty string otherwise
331
    std::string getOS() const;
332
333
    /// The pcap-ng format allows storing metadata at the header of the file. Part of this metadata is a string
334
    /// specifying the hardware that was used for capturing the packets. This method reads this string from the
335
    /// metadata (if exists) and returns it
336
    /// @return The hardware string if exists, or an empty string otherwise
337
    std::string getHardware() const;
338
339
    /// The pcap-ng format allows storing metadata at the header of the file. Part of this metadata is a string
340
    /// specifying the capture application that was used for capturing the packets. This method reads this string
341
    /// from the metadata (if exists) and returns it
342
    /// @return The capture application string if exists, or an empty string otherwise
343
    std::string getCaptureApplication() const;
344
345
    /// The pcap-ng format allows storing metadata at the header of the file. Part of this metadata is a string
346
    /// containing a user-defined comment (can be any string). This method reads this string from the metadata (if
347
    /// exists) and returns it
348
    /// @return The comment written inside the file if exists, or an empty string otherwise
349
    std::string getCaptureFileComment() const;
350
351
    /// The pcap-ng format allows storing a user-defined comment for every packet (besides the comment per-file).
352
    /// This method reads the next packet and the comment attached to it (if such comment exists), and returns them
353
    /// both
354
    /// @param[out] rawPacket A reference for an empty RawPacket where the packet will be written
355
    /// @param[out] packetComment The comment attached to the packet or an empty string if no comment exists
356
    /// @return True if a packet was read successfully. False will be returned if the file isn't opened (also, an
357
    /// error log will be printed) or if reached end-of-file
358
    bool getNextPacket(RawPacket& rawPacket, std::string& packetComment);
359
360
    // overridden methods
361
362
    /// Read the next packet from the file. Before using this method please verify the file is opened using open()
363
    /// @param[out] rawPacket A reference for an empty RawPacket where the packet will be written
364
    /// @return True if a packet was read successfully. False will be returned if the file isn't opened (also, an
365
    /// error log will be printed) or if reached end-of-file
366
    bool getNextPacket(RawPacket& rawPacket);
367
368
    /// Open the file name which path was specified in the constructor in a read-only mode
369
    /// @return True if file was opened successfully or if file is already opened. False if opening the file failed
370
    /// for some reason (for example: file path does not exist)
371
    bool open();
372
373
    /// Set a filter for PcapNG reader device. Only packets that match the filter will be received
374
    /// @param[in] filterAsString The filter to be set in Berkeley Packet Filter (BPF) syntax
375
    /// (http://biot.com/capstats/bpf.html)
376
    /// @return True if filter set successfully, false otherwise
377
    bool setFilter(std::string filterAsString);
378
379
    /// Close the pacp-ng file
380
    void close();
381
  };
382
383
  /// @class PcapNgFileWriterDevice
384
  /// A class for opening a pcap-ng file for writing or creating a new pcap-ng file and write packets to it. This
385
  /// class adds unique capabilities such as writing metadata attributes into the file header, adding comments per
386
  /// packet and opening the file in append mode where packets are added to a file instead of overriding it. This
387
  /// capabilities are part of the pcap-ng standard but aren't supported in most tools and libraries
388
  class PcapNgFileWriterDevice : public IFileWriterDevice
389
  {
390
  private:
391
    internal::LightPcapNgHandle* m_LightPcapNg;
392
    int m_CompressionLevel;
393
    BpfFilterWrapper m_BpfWrapper;
394
395
    // private copy c'tor
396
    PcapNgFileWriterDevice(const PcapFileWriterDevice& other);
397
    PcapNgFileWriterDevice& operator=(const PcapNgFileWriterDevice& other);
398
399
  public:
400
    /// A constructor for this class that gets the pcap-ng full path file name to open for writing or create. Notice
401
    /// that after calling this constructor the file isn't opened yet, so writing packets will fail. For opening the
402
    /// file call open()
403
    /// @param[in] fileName The full path of the file
404
    /// @param[in] compressionLevel The compression level to use when writing the file, use 0 to disable compression
405
    /// or 10 for max compression. Default is 0
406
    PcapNgFileWriterDevice(const std::string& fileName, int compressionLevel = 0);
407
408
    /// A destructor for this class
409
    virtual ~PcapNgFileWriterDevice()
410
3.67k
    {
411
3.67k
      PcapNgFileWriterDevice::close();
412
3.67k
    }
413
414
    /// The pcap-ng format allows adding a user-defined comment for each stored packet. This method writes a
415
    /// RawPacket to the file and adds a comment to it. Before using this method please verify the file is opened
416
    /// using open(). This method won't change the written packet or the input comment
417
    /// @param[in] packet A reference for an existing RawPcket to write to the file
418
    /// @param[in] comment The comment to be written for the packet. If this string is empty or null it will be
419
    /// ignored
420
    /// @return True if a packet was written successfully. False will be returned if the file isn't opened (an error
421
    /// will be printed to log)
422
    bool writePacket(RawPacket const& packet, const std::string& comment);
423
424
    // overridden methods
425
426
    /// Write a RawPacket to the file. Before using this method please verify the file is opened using open(). This
427
    /// method won't change the written packet
428
    /// @param[in] packet A reference for an existing RawPcket to write to the file
429
    /// @return True if a packet was written successfully. False will be returned if the file isn't opened (an error
430
    /// will be printed to log)
431
    bool writePacket(RawPacket const& packet) override;
432
433
    /// Write multiple RawPacket to the file. Before using this method please verify the file is opened using
434
    /// open(). This method won't change the written packets or the RawPacketVector instance
435
    /// @param[in] packets A reference for an existing RawPcketVector, all of its packets will be written to the
436
    /// file
437
    /// @return True if all packets were written successfully to the file. False will be returned if the file isn't
438
    /// opened (also, an error log will be printed) or if at least one of the packets wasn't written successfully to
439
    /// the file
440
    bool writePackets(const RawPacketVector& packets) override;
441
442
    /// Open the file in a write mode. If file doesn't exist, it will be created. If it does exist it will be
443
    /// overwritten, meaning all its current content will be deleted
444
    /// @return True if file was opened/created successfully or if file is already opened. False if opening the file
445
    /// failed for some reason (an error will be printed to log)
446
    bool open() override;
447
448
    /// Same as open(), but enables to open the file in append mode in which packets will be appended to the file
449
    /// instead of overwrite its current content. In append mode file must exist, otherwise opening will fail
450
    /// @param[in] appendMode A boolean indicating whether to open the file in append mode or not. If set to false
451
    /// this method will act exactly like open(). If set to true, file will be opened in append mode
452
    /// @return True of managed to open the file successfully. In case appendMode is set to true, false will be
453
    /// returned if file wasn't found or couldn't be read, if file type is not pcap-ng. In case appendMode is set to
454
    /// false, please refer to open() for return values
455
    bool open(bool appendMode) override;
456
457
    /// Open the file in a write mode. If file doesn't exist, it will be created. If it does exist it will be
458
    /// overwritten, meaning all its current content will be deleted. As opposed to open(), this method also allows
459
    /// writing several metadata attributes that will be stored in the header of the file
460
    /// @param[in] os A string describing the operating system that was used to capture the packets. If this string
461
    /// is empty or null it will be ignored
462
    /// @param[in] hardware A string describing the hardware that was used to capture the packets. If this string is
463
    /// empty or null it will be ignored
464
    /// @param[in] captureApp A string describing the application that was used to capture the packets. If this
465
    /// string is empty or null it will be ignored
466
    /// @param[in] fileComment A string containing a user-defined comment that will be part of the metadata of the
467
    /// file. If this string is empty or null it will be ignored
468
    /// @return True if file was opened/created successfully or if file is already opened. False if opening the file
469
    /// failed for some reason (an error will be printed to log)
470
    bool open(const std::string& os, const std::string& hardware, const std::string& captureApp,
471
              const std::string& fileComment);
472
473
    /// Flush packets to the pcap-ng file
474
    void flush();
475
476
    /// Flush and close the pcap-ng file
477
    void close() override;
478
479
    /// Set a filter for PcapNG writer device. Only packets that match the filter will be persisted
480
    /// @param[in] filterAsString The filter to be set in Berkeley Packet Filter (BPF) syntax
481
    /// (http://biot.com/capstats/bpf.html)
482
    /// @return True if filter set successfully, false otherwise
483
    bool setFilter(std::string filterAsString) override;
484
485
  private:
486
    /// @struct PcapNgMetadata
487
    /// @brief A struct for holding the metadata of a pcap-ng file. The metadata includes the operating system,
488
    /// hardware, capture application and file comment.
489
    struct PcapNgMetadata
490
    {
491
      /// The operating system that was used for capturing the packets
492
      std::string os;
493
      /// The hardware that was used for capturing the packets
494
      std::string hardware;
495
      /// The capture application that was used for capturing the packets
496
      std::string captureApplication;
497
      /// The comment that was written inside the file
498
      std::string comment;
499
    };
500
501
    bool openWrite(PcapNgMetadata const* metadata = nullptr);
502
    bool openAppend();
503
  };
504
505
  /// @class SnoopFileReaderDevice
506
  /// A class for opening a snoop file in read-only mode. This class enable to open the file and read all packets,
507
  /// packet-by-packet
508
  class SnoopFileReaderDevice : public IFileReaderDevice
509
  {
510
  private:
511
#pragma pack(1)
512
    /// File format header.
513
    typedef struct
514
    {
515
      uint64_t identification_pattern;
516
      uint32_t version_number;
517
      uint32_t datalink_type;
518
    } snoop_file_header_t;
519
520
    /// Packet record header.
521
    typedef struct
522
    {
523
      uint32_t original_length;       ///< original packet length
524
      uint32_t included_length;       ///< saved packet length
525
      uint32_t packet_record_length;  ///< total record length
526
      uint32_t ndrops_cumulative;     ///< cumulative drops
527
      uint32_t time_sec;              ///< timestamp
528
      uint32_t time_usec;             ///< microsecond timestamp
529
    } snoop_packet_header_t;
530
#pragma pack()
531
532
    LinkLayerType m_PcapLinkLayerType;
533
    std::ifstream m_snoopFile;
534
535
    // private copy c'tor
536
    SnoopFileReaderDevice(const PcapFileReaderDevice& other);
537
    SnoopFileReaderDevice& operator=(const PcapFileReaderDevice& other);
538
539
  public:
540
    /// A constructor for this class that gets the snoop full path file name to open. Notice that after calling this
541
    /// constructor the file isn't opened yet, so reading packets will fail. For opening the file call open()
542
    /// @param[in] fileName The full path of the file to read
543
    SnoopFileReaderDevice(const std::string& fileName)
544
214
        : IFileReaderDevice(fileName), m_PcapLinkLayerType(LINKTYPE_ETHERNET)
545
214
    {}
546
547
    /// A destructor for this class
548
    virtual ~SnoopFileReaderDevice();
549
550
    /// @return The link layer type of this file
551
    LinkLayerType getLinkLayerType() const
552
0
    {
553
0
      return m_PcapLinkLayerType;
554
0
    }
555
556
    // overridden methods
557
558
    /// Read the next packet from the file. Before using this method please verify the file is opened using open()
559
    /// @param[out] rawPacket A reference for an empty RawPacket where the packet will be written
560
    /// @return True if a packet was read successfully. False will be returned if the file isn't opened (also, an
561
    /// error log will be printed) or if reached end-of-file
562
    bool getNextPacket(RawPacket& rawPacket);
563
564
    /// Open the file name which path was specified in the constructor in a read-only mode
565
    /// @return True if file was opened successfully or if file is already opened. False if opening the file failed
566
    /// for some reason (for example: file path does not exist)
567
    bool open();
568
569
    /// Close the snoop file
570
    void close();
571
  };
572
}  // namespace pcpp