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;
214 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
215 uint32_t& capturedLength, uint32_t& frameLength);
237 bool nanosecondsPrecision =
false);
268 PCPP_DEPRECATED(
"Nanosecond precision is now natively supported by the internal parser and always returns true")
276 return m_PcapLinkLayerType;
293 bool open(
bool appendMode)
override;
298 return m_PcapFile.is_open();
309 bool m_NeedsSwap =
false;
311 std::fstream m_PcapFile;
313 struct CheckHeaderResult
324 bool needsSwap =
false;
326 static CheckHeaderResult fromOk(
bool needsSwap)
328 return { Result::HeaderOk,
"", needsSwap };
331 static CheckHeaderResult fromError(
const std::string& error)
333 return { Result::HeaderError, error };
336 static CheckHeaderResult fromHeaderNeeded()
338 return { Result::HeaderNeeded };
354 internal::LightPcapNgHandle* m_LightPcapNg;
420 return m_LightPcapNg !=
nullptr;
427 bool getNextPacketInternal(
RawPacket& rawPacket, std::string* packetComment);
438 internal::LightPcapNgHandle* m_LightPcapNg;
439 int m_CompressionLevel;
500 bool open(
bool appendMode)
override;
515 bool open(
const std::string& os,
const std::string& hardware,
const std::string& captureApp,
516 const std::string& fileComment);
521 return m_LightPcapNg !=
nullptr;
534 struct PcapNgMetadata
539 std::string hardware;
541 std::string captureApplication;
546 bool openWrite(PcapNgMetadata
const* metadata =
nullptr);
560 uint64_t identification_pattern;
561 uint32_t version_number;
562 uint32_t datalink_type;
563 } snoop_file_header_t;
568 uint32_t original_length;
569 uint32_t included_length;
570 uint32_t packet_record_length;
571 uint32_t ndrops_cumulative;
574 } snoop_packet_header_t;
578 std::ifstream m_SnoopFile;
580 bool readNextPacket(timespec& packetTimestamp, uint8_t* packetData, uint32_t packetDataLen,
581 uint32_t& capturedLength, uint32_t& frameLength);
600 return m_PcapLinkLayerType;
619 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:224
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:296
PcapFileWriterDevice(const std::string &fileName, LinkLayerType linkLayerType=LINKTYPE_ETHERNET, bool nanosecondsPrecision=false)
bool writePacket(RawPacket const &packet) override
static bool isNanoSecondPrecisionSupported()
Definition: PcapFileDevice.h:269
FileTimestampPrecision getTimestampPrecision() const
Definition: PcapFileDevice.h:260
bool writePackets(const RawPacketVector &packets) override
Definition: PcapFileDevice.h:352
std::string getOS() const
bool isOpened() const override
Definition: PcapFileDevice.h:418
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:363
std::string getCaptureFileComment() const
PcapNgFileReaderDevice(const std::string &fileName)
std::string getHardware() const
void close() override
Close the pacp-ng file.
Definition: PcapFileDevice.h:436
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:519
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:451
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:261
Definition: PcapFileDevice.h:554
void close() override
Close the snoop file.
bool getNextPacket(RawPacket &rawPacket) override
SnoopFileReaderDevice(const std::string &fileName)
Definition: PcapFileDevice.h:587
LinkLayerType getLinkLayerType() const
Definition: PcapFileDevice.h:598
~SnoopFileReaderDevice() override
A destructor for this class.
bool isOpened() const override
Definition: PcapFileDevice.h:617
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