PcapPlusPlus  Next
pcpp::PcapFileReaderDevice Class Reference

#include <PcapFileDevice.h>

Inheritance diagram for pcpp::PcapFileReaderDevice:
pcpp::IFileReaderDevice pcpp::IFileDevice pcpp::IFilterableDevice pcpp::IPcapStatisticsProvider pcpp::IDevice

Public Member Functions

 PcapFileReaderDevice (const std::string &fileName)
 
 ~PcapFileReaderDevice () override=default
 A destructor for this class.
 
LinkLayerType getLinkLayerType () const
 
FileTimestampPrecision getTimestampPrecision () const
 
uint32_t getSnapshotLength () const
 
bool isOpened () const override
 
bool getNextPacket (RawPacket &rawPacket) override
 
bool open () override
 
void close () override
 Close the pacp file.
 
- Public Member Functions inherited from pcpp::IFileReaderDevice
 ~IFileReaderDevice () override=default
 A destructor for this class.
 
uint64_t getFileSize () const
 
int getNextPackets (RawPacketVector &packetVec, int numOfPacketsToRead=-1)
 
- Public Member Functions inherited from pcpp::IFileDevice
std::string getFileName () const
 
void getStatistics (PcapStats &stats) const override
 Get the statistics for this device. More...
 
- Public Member Functions inherited from pcpp::IFilterableDevice
bool setFilter (GeneralFilter &filter)
 
bool setFilter (std::string const &filterAsString)
 
bool clearFilter ()
 
- Public Member Functions inherited from pcpp::IPcapStatisticsProvider
PcapStats getStatistics () const
 Get statistics from the device. More...
 

Static Public Member Functions

static bool isNanoSecondPrecisionSupported ()
 
- Static Public Member Functions inherited from pcpp::IFileReaderDevice
static IFileReaderDevicegetReader (const std::string &fileName)
 

Additional Inherited Members

- Protected Member Functions inherited from pcpp::IFileReaderDevice
 IFileReaderDevice (const std::string &fileName)
 
- Protected Member Functions inherited from pcpp::IFileDevice
bool doUpdateFilter (std::string const *filterAsString) override
 Updates the filter on the device with a BPF string. More...
 
void reportPacketProcessed (uint64_t numPackets=1)
 Report that packets were processed (read or written, depending on the device type). More...
 
void reportPacketDropped (uint64_t numPackets=1)
 Report that packets were dropped (not read or not written, depending on the device type). More...
 
void resetStatisticCounters ()
 Reset the internal statistic counters to zero.
 

Detailed Description

A class for opening a pcap file in read-only mode. This class enable to open the file and read all packets, packet-by-packet

Constructor & Destructor Documentation

◆ PcapFileReaderDevice()

pcpp::PcapFileReaderDevice::PcapFileReaderDevice ( const std::string &  fileName)
inlineexplicit

A constructor for this class that gets the pcap full path file name to open. Notice that after calling this constructor the file isn't opened yet, so reading packets will fail. For opening the file call open()

Parameters
[in]fileNameThe full path of the file to read

Member Function Documentation

◆ getLinkLayerType()

LinkLayerType pcpp::PcapFileReaderDevice::getLinkLayerType ( ) const
inline
Returns
The link layer type of this file

◆ getNextPacket()

bool pcpp::PcapFileReaderDevice::getNextPacket ( RawPacket rawPacket)
overridevirtual

Read the next packet from the file. Before using this method please verify the file is opened using open()

Parameters
[out]rawPacketA reference for an empty RawPacket where the packet will be written
Returns
True if a packet was read successfully. False will be returned if the file isn't opened (also, an error log will be printed) or if reached end-of-file

Implements pcpp::IFileReaderDevice.

◆ getSnapshotLength()

uint32_t pcpp::PcapFileReaderDevice::getSnapshotLength ( ) const
inline
Returns
The file's snapshot length (snaplen)

◆ getTimestampPrecision()

FileTimestampPrecision pcpp::PcapFileReaderDevice::getTimestampPrecision ( ) const
inline
Returns
The precision of the timestamps in the file

◆ isNanoSecondPrecisionSupported()

static bool pcpp::PcapFileReaderDevice::isNanoSecondPrecisionSupported ( )
inlinestatic

A static method that checks if nano-second precision is supported in the current platform and environment

Returns
True if nano-second precision is supported, false otherwise
Deprecated:
Nanosecond precision is now natively supported by the internal parser and always returns true

◆ isOpened()

bool pcpp::PcapFileReaderDevice::isOpened ( ) const
inlineoverridevirtual
Returns
True if the file is opened, false otherwise

Implements pcpp::IDevice.

◆ open()

bool pcpp::PcapFileReaderDevice::open ( )
overridevirtual

Open the file name which path was specified in the constructor in a read-only mode

Returns
True if file was opened successfully or if file is already opened. False if opening the file failed for some reason (for example: file path does not exist)

Implements pcpp::IDevice.