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;
390 return m_LightPcapNg !=
nullptr;
397 bool getNextPacketInternal(
RawPacket& rawPacket, std::string* packetComment);
408 internal::LightPcapNgHandle* m_LightPcapNg;
409 int m_CompressionLevel;
470 bool open(
bool appendMode)
override;
485 bool open(
const std::string& os,
const std::string& hardware,
const std::string& captureApp,
486 const std::string& fileComment);
491 return m_LightPcapNg !=
nullptr;
504 struct PcapNgMetadata
509 std::string hardware;
511 std::string captureApplication;
516 bool openWrite(PcapNgMetadata
const* metadata =
nullptr);
530 uint64_t identification_pattern;
531 uint32_t version_number;
532 uint32_t datalink_type;
533 } snoop_file_header_t;
538 uint32_t original_length;
539 uint32_t included_length;
540 uint32_t packet_record_length;
541 uint32_t ndrops_cumulative;
544 } snoop_packet_header_t;
548 std::ifstream m_SnoopFile;
549 std::vector<uint8_t> m_ReadBuffer;
551 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
552 uint32_t& capturedLength, uint32_t& frameLength);
571 return m_PcapLinkLayerType;
590 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:388
std::string getCaptureApplication() const
bool getNextPacket(RawPacket &rawPacket, std::string &packetComment)
bool getNextPacket(RawPacket &rawPacket) override
~PcapNgFileReaderDevice() override
A destructor for this class.
Definition: PcapFileDevice.h:333
std::string getCaptureFileComment() const
PcapNgFileReaderDevice(const std::string &fileName)
std::string getHardware() const
void close() override
Close the pacp-ng file.
Definition: PcapFileDevice.h:406
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:489
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
~PcapNgFileWriterDevice() override
A destructor for this class.
Definition: PcapFileDevice.h:421
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:524
void close() override
Close the snoop file.
bool getNextPacket(RawPacket &rawPacket) override
SnoopFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:558
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:569
~SnoopFileReaderDevice() override
A destructor for this class.
bool isOpened() const override
Definition: PcapFileDevice.h:588
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