39 std::string m_FileName;
67 m_NumOfPacketsProcessed += numPackets;
74 m_NumOfPacketsDropped += numPackets;
81 uint64_t m_NumOfPacketsProcessed = 0;
82 uint64_t m_NumOfPacketsDropped = 0;
103 virtual bool getNextPacket(
RawPacket& rawPacket) = 0;
119 PCPP_DEPRECATED(
"Prefer `tryCreateReader` due to selection of reader based on file content.")
157 virtual bool writePacket(
RawPacket const& packet) = 0;
162 virtual bool open(
bool appendMode) = 0;
186 return m_PcapLinkLayerType;
198 return m_SnapshotLength;
204 PCPP_DEPRECATED(
"Nanosecond precision is now natively supported by the internal parser and always returns true")
205 static
bool isNanoSecondPrecisionSupported()
215 return m_PcapFile.is_open();
235 std::ifstream m_PcapFile;
236 bool m_NeedsSwap =
false;
237 uint32_t m_SnapshotLength = 0;
238 std::vector<uint8_t> m_ReadBuffer;
240 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
241 uint32_t& capturedLength, uint32_t& frameLength);
263 bool nanosecondsPrecision =
false);
294 PCPP_DEPRECATED(
"Nanosecond precision is now natively supported by the internal parser and always returns true")
295 static
bool isNanoSecondPrecisionSupported()
302 return m_PcapLinkLayerType;
319 bool open(
bool appendMode)
override;
324 return m_PcapFile.is_open();
338 bool m_NeedsSwap =
false;
340 std::fstream m_PcapFile;
349 internal::LightPcapNgHandle* m_LightPcapNg;
419 return m_LightPcapNg !=
nullptr;
426 bool getNextPacketInternal(
RawPacket& rawPacket, std::string* packetComment);
437 internal::LightPcapNgHandle* m_LightPcapNg;
438 int m_CompressionLevel;
503 bool open(
bool appendMode)
override;
518 bool open(
const std::string& os,
const std::string& hardware,
const std::string& captureApp,
519 const std::string& fileComment);
524 return m_LightPcapNg !=
nullptr;
537 struct PcapNgMetadata
542 std::string hardware;
544 std::string captureApplication;
549 bool openWrite(PcapNgMetadata
const* metadata =
nullptr);
563 uint64_t identification_pattern;
564 uint32_t version_number;
565 uint32_t datalink_type;
566 } snoop_file_header_t;
571 uint32_t original_length;
572 uint32_t included_length;
573 uint32_t packet_record_length;
574 uint32_t ndrops_cumulative;
577 } snoop_packet_header_t;
581 std::ifstream m_SnoopFile;
582 std::vector<uint8_t> m_ReadBuffer;
584 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
585 uint32_t& capturedLength, uint32_t& frameLength);
604 return m_PcapLinkLayerType;
623 return m_SnoopFile.is_open();
Definition: PcapFilter.h:80
Definition: PcapFileDevice.h:37
bool doUpdateFilter(std::string const *filterAsString) override
Updates the filter on the device with a BPF string.
std::string getFileName() const
void reportPacketProcessed(uint64_t numPackets=1)
Report that packets were processed (read or written, depending on the device type).
Definition: PcapFileDevice.h:65
void reportPacketDropped(uint64_t numPackets=1)
Report that packets were dropped (not read or not written, depending on the device type).
Definition: PcapFileDevice.h:72
void getStatistics(PcapStats &stats) const override
Get the statistics for this device.
void resetStatisticCounters()
Reset the internal statistic counters to zero.
Definition: PcapFileDevice.h:89
int getNextPackets(RawPacketVector &packetVec, int numOfPacketsToRead=-1)
static std::unique_ptr< IFileReaderDevice > createReader(const std::string &fileName)
Creates an instance of the reader best fit to read the file.
uint64_t getFileSize() const
static IFileReaderDevice * getReader(const std::string &fileName)
~IFileReaderDevice() override=default
A destructor for this class.
IFileReaderDevice(const std::string &fileName)
static std::unique_ptr< IFileReaderDevice > tryCreateReader(const std::string &fileName)
Tries to create an instance of the reader best fit to read the file.
Definition: PcapFileDevice.h:149
~IFileWriterDevice() override=default
A destructor for this class.
An interface for providing Pcap-based device statistics.
Definition: PcapDevice.h:25
Definition: PcapFileDevice.h:169
PcapFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:174
bool getNextPacket(RawPacket &rawPacket) override
void close() override
Close the pacp file.
bool isOpened() const override
Definition: PcapFileDevice.h:213
FileTimestampPrecision getTimestampPrecision() const
Definition: PcapFileDevice.h:190
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:184
~PcapFileReaderDevice() override=default
A destructor for this class.
uint32_t getSnapshotLength() const
Definition: PcapFileDevice.h:196
Definition: PcapFileDevice.h:250
bool open(bool appendMode) override
void flush()
Flush packets to disk.
void close() override
Flush and close the pacp file.
bool isOpened() const override
Definition: PcapFileDevice.h:322
PcapFileWriterDevice(const std::string &fileName, LinkLayerType linkLayerType=LINKTYPE_ETHERNET, bool nanosecondsPrecision=false)
bool writePacket(RawPacket const &packet) override
FileTimestampPrecision getTimestampPrecision() const
Definition: PcapFileDevice.h:286
bool writePackets(const RawPacketVector &packets) override
Definition: PcapFileDevice.h:347
std::string getOS() const
bool isOpened() const override
Definition: PcapFileDevice.h:417
std::string getCaptureApplication() const
static bool isZstdSupported()
A static method that checks if the device was built with zstd compression support.
bool getNextPacket(RawPacket &rawPacket, std::string &packetComment)
bool getNextPacket(RawPacket &rawPacket) override
~PcapNgFileReaderDevice() override
A destructor for this class.
Definition: PcapFileDevice.h:362
std::string getCaptureFileComment() const
PcapNgFileReaderDevice(const std::string &fileName)
std::string getHardware() const
void close() override
Close the pacp-ng file.
Definition: PcapFileDevice.h:435
bool open(const std::string &os, const std::string &hardware, const std::string &captureApp, const std::string &fileComment)
bool isOpened() const override
Definition: PcapFileDevice.h:522
PcapNgFileWriterDevice(const std::string &fileName, int compressionLevel=0)
bool writePacket(RawPacket const &packet) override
void close() override
Flush and close the pcap-ng file.
bool writePackets(const RawPacketVector &packets) override
static bool isZstdSupported()
A static method that checks if the device was built with zstd compression support.
~PcapNgFileWriterDevice() override
A destructor for this class.
Definition: PcapFileDevice.h:454
bool open(bool appendMode) override
bool writePacket(RawPacket const &packet, const std::string &comment)
void flush()
Flush packets to the pcap-ng file.
Definition: PointerVector.h:50
Definition: RawPacket.h:290
Definition: PcapFileDevice.h:557
void close() override
Close the snoop file.
bool getNextPacket(RawPacket &rawPacket) override
SnoopFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:591
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:602
~SnoopFileReaderDevice() override
A destructor for this class.
bool isOpened() const override
Definition: PcapFileDevice.h:621
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
FileTimestampPrecision
Definition: PcapFileDevice.h:25
@ Microseconds
Precision is in microseconds.
@ Unknown
Precision is unknown or not set/determined.
@ Nanoseconds
Precision is in nanoseconds.
LinkLayerType
An enum describing all known link layer type. Taken from: http://www.tcpdump.org/linktypes....
Definition: RawPacket.h:22
@ LINKTYPE_ETHERNET
IEEE 802.3 Ethernet.
Definition: RawPacket.h:26
Definition: PcapDevice.h:14