PcapPlusPlus
pcpp::IPcapDevice Class Referenceabstract

#include <PcapDevice.h>

Inheritance diagram for pcpp::IPcapDevice:
pcpp::IDevice pcpp::IFilterableDevice pcpp::IFileDevice pcpp::PcapLiveDevice pcpp::IFileReaderDevice pcpp::IFileWriterDevice pcpp::PcapRemoteDevice pcpp::WinPcapLiveDevice pcpp::PcapFileReaderDevice pcpp::PcapNgFileReaderDevice pcpp::PcapFileWriterDevice pcpp::PcapNgFileWriterDevice

Public Member Functions

virtual void getStatistics (pcap_stat &stats)=0
 
virtual bool setFilter (std::string filterAsString)
 
bool clearFilter ()
 
- Public Member Functions inherited from pcpp::IDevice
virtual bool open ()=0
 
virtual void close ()=0
 
bool isOpened ()
 
- Public Member Functions inherited from pcpp::IFilterableDevice
virtual bool setFilter (GeneralFilter &filter)
 

Static Public Member Functions

static std::string getPcapLibVersionInfo ()
 
static bool verifyFilter (std::string filterAsString)
 
static bool matchPacketWithFilter (std::string filterAsString, RawPacket *rawPacket)
 

Detailed Description

An abstract class representing all libpcap-based packet capturing devices: files, libPcap, WinPcap and RemoteCapture. This class is abstract and cannot be instantiated

Member Function Documentation

◆ clearFilter()

bool pcpp::IPcapDevice::clearFilter ( )
virtual

Clear the filter currently set on device

Returns
True if filter was removed successfully or if no filter was set, false otherwise

Implements pcpp::IFilterableDevice.

◆ getPcapLibVersionInfo()

static std::string pcpp::IPcapDevice::getPcapLibVersionInfo ( )
static

A static method for retreiving pcap lib (libpcap/WinPcap/etc.) version information. This method is actually a wrapper for pcap_lib_version()

Returns
A string containing the pcap lib version information

◆ getStatistics()

virtual void pcpp::IPcapDevice::getStatistics ( pcap_stat &  stats)
pure virtual

Get statistics from device:

  • pcap_stat::ps_recv: number of packets received
  • pcap_stat::ps_drop: number of packets dropped
  • pcap_stat::ps_ifdorp: number of packets dropped by interface
    Parameters
    [out]statsThe stats struct where stats are returned

Implemented in pcpp::PcapNgFileWriterDevice, pcpp::PcapLiveDevice, pcpp::PcapFileWriterDevice, pcpp::PcapNgFileReaderDevice, pcpp::PcapFileReaderDevice, and pcpp::PcapRemoteDevice.

◆ matchPacketWithFilter()

static bool pcpp::IPcapDevice::matchPacketWithFilter ( std::string  filterAsString,
RawPacket rawPacket 
)
static

Match a raw packet with a given BPF filter. Notice this method is static which means you don't need any device instance in order to perform this match

Parameters
[in]filterAsStringThe BPF filter
[in]rawPacketA pointer to the raw packet to match the BPF filter with
Returns
True if raw packet matches the BPF filter or false otherwise

◆ setFilter()

virtual bool pcpp::IPcapDevice::setFilter ( std::string  filterAsString)
virtual

Set a filter for the device. When implemented by the device, only packets that match the filter will be received

Parameters
[in]filterAsStringThe filter to be set in Berkeley Packet Filter (BPF) syntax (http://biot.com/capstats/bpf.html)
Returns
True if filter set successfully, false otherwise

Implements pcpp::IFilterableDevice.

Reimplemented in pcpp::PcapNgFileWriterDevice, and pcpp::PcapNgFileReaderDevice.

◆ verifyFilter()

static bool pcpp::IPcapDevice::verifyFilter ( std::string  filterAsString)
static

Verify a filter is valid

Parameters
[in]filterAsStringThe filter in Berkeley Packet Filter (BPF) syntax (http://biot.com/capstats/bpf.html)
Returns
True if the filter is valid or false otherwise