PcapPlusPlus
pcpp::IPcapDevice Class Referenceabstract

#include <PcapDevice.h>

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

Public Member Functions

virtual bool open ()=0
 
virtual void close ()=0
 
bool isOpened ()
 
virtual void getStatistics (pcap_stat &stats)=0
 
bool setFilter (GeneralFilter &filter)
 
virtual bool setFilter (std::string filterAsString)
 
void clearFilter ()
 

Static Public Member Functions

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

Detailed Description

An abstract class representing all possible packet capturing devices: files, libPcap, WinPcap, RemoteCapture, PF_RING, etc. This class cannot obviously be instantiated

Member Function Documentation

void pcpp::IPcapDevice::clearFilter ( )

Clear the filter currently set on device

virtual void pcpp::IPcapDevice::close ( )
pure virtual
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::DpdkDevice, pcpp::PcapNgFileWriterDevice, pcpp::PcapLiveDevice, pcpp::PcapFileWriterDevice, pcpp::PfRingDevice, pcpp::PcapNgFileReaderDevice, pcpp::PcapRemoteDevice, and pcpp::PcapFileReaderDevice.

bool pcpp::IPcapDevice::isOpened ( )
inline
Returns
True if the file is opened, false otherwise
static bool pcpp::IPcapDevice::matchPakcetWithFilter ( 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
virtual bool pcpp::IPcapDevice::open ( )
pure virtual
bool pcpp::IPcapDevice::setFilter ( GeneralFilter filter)

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

Parameters
[in]filterThe filter to be set in PcapPlusPlus' GeneralFilter format
Returns
True if filter set successfully, false otherwise
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

Reimplemented in pcpp::DpdkDevice, pcpp::PfRingDevice, and pcpp::PcapNgFileReaderDevice.

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