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;
132 virtual bool writePacket(
RawPacket const& packet) = 0;
137 virtual bool open(
bool appendMode) = 0;
161 return m_PcapLinkLayerType;
173 return m_SnapshotLength;
179 PCPP_DEPRECATED(
"Nanosecond precision is now natively supported by the internal parser and always returns true")
190 return m_PcapFile.is_open();
210 std::ifstream m_PcapFile;
211 bool m_NeedsSwap =
false;
212 uint32_t m_SnapshotLength = 0;
213 std::vector<uint8_t> m_ReadBuffer;
215 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
216 uint32_t& capturedLength, uint32_t& frameLength);
238 bool nanosecondsPrecision =
false);
269 PCPP_DEPRECATED(
"Nanosecond precision is now natively supported by the internal parser and always returns true")
277 return m_PcapLinkLayerType;
294 bool open(
bool appendMode)
override;
299 return m_PcapFile.is_open();
313 bool m_NeedsSwap =
false;
315 std::fstream m_PcapFile;
324 internal::LightPcapNgHandle* m_LightPcapNg;
394 return m_LightPcapNg !=
nullptr;
401 bool getNextPacketInternal(
RawPacket& rawPacket, std::string* packetComment);
412 internal::LightPcapNgHandle* m_LightPcapNg;
413 int m_CompressionLevel;
478 bool open(
bool appendMode)
override;
493 bool open(
const std::string& os,
const std::string& hardware,
const std::string& captureApp,
494 const std::string& fileComment);
499 return m_LightPcapNg !=
nullptr;
512 struct PcapNgMetadata
517 std::string hardware;
519 std::string captureApplication;
524 bool openWrite(PcapNgMetadata
const* metadata =
nullptr);
538 uint64_t identification_pattern;
539 uint32_t version_number;
540 uint32_t datalink_type;
541 } snoop_file_header_t;
546 uint32_t original_length;
547 uint32_t included_length;
548 uint32_t packet_record_length;
549 uint32_t ndrops_cumulative;
552 } snoop_packet_header_t;
556 std::ifstream m_SnoopFile;
557 std::vector<uint8_t> m_ReadBuffer;
559 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
560 uint32_t& capturedLength, uint32_t& frameLength);
579 return m_PcapLinkLayerType;
598 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)
uint64_t getFileSize() const
static IFileReaderDevice * getReader(const std::string &fileName)
~IFileReaderDevice() override=default
A destructor for this class.
IFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:124
~IFileWriterDevice() override=default
A destructor for this class.
An interface for providing Pcap-based device statistics.
Definition: PcapDevice.h:25
Definition: PcapFileDevice.h:144
PcapFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:149
bool getNextPacket(RawPacket &rawPacket) override
void close() override
Close the pacp file.
static bool isNanoSecondPrecisionSupported()
Definition: PcapFileDevice.h:180
bool isOpened() const override
Definition: PcapFileDevice.h:188
FileTimestampPrecision getTimestampPrecision() const
Definition: PcapFileDevice.h:165
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:159
~PcapFileReaderDevice() override=default
A destructor for this class.
uint32_t getSnapshotLength() const
Definition: PcapFileDevice.h:171
Definition: PcapFileDevice.h:225
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:297
PcapFileWriterDevice(const std::string &fileName, LinkLayerType linkLayerType=LINKTYPE_ETHERNET, bool nanosecondsPrecision=false)
bool writePacket(RawPacket const &packet) override
static bool isNanoSecondPrecisionSupported()
Definition: PcapFileDevice.h:270
FileTimestampPrecision getTimestampPrecision() const
Definition: PcapFileDevice.h:261
bool writePackets(const RawPacketVector &packets) override
Definition: PcapFileDevice.h:322
std::string getOS() const
bool isOpened() const override
Definition: PcapFileDevice.h:392
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:337
std::string getCaptureFileComment() const
PcapNgFileReaderDevice(const std::string &fileName)
std::string getHardware() const
void close() override
Close the pacp-ng file.
Definition: PcapFileDevice.h:410
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:497
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:429
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:532
void close() override
Close the snoop file.
bool getNextPacket(RawPacket &rawPacket) override
SnoopFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:566
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:577
~SnoopFileReaderDevice() override
A destructor for this class.
bool isOpened() const override
Definition: PcapFileDevice.h:596
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