PcapPlusPlus  21.11
PcapDevice.h
Go to the documentation of this file.
1 #ifndef PCAPPP_PCAP_DEVICE
2 #define PCAPPP_PCAP_DEVICE
3 
4 #include "Device.h"
5 
14 #if defined(PCAPPP_MINGW_ENV) && !defined(WIN32)
15 # define WIN32
16 #endif
17 
18 // forward decleration for the pcap descriptor defined in pcap.h
19 struct pcap;
20 typedef pcap pcap_t;
21 struct pcap_pkthdr;
22 
24 
29 namespace pcpp
30 {
31  //Forward Declaration - required for IPcapDevice::matchPacketWithFilter
32  class GeneralFilter;
33 
39  class IPcapDevice : public IDevice, public IFilterableDevice
40  {
41  protected:
42  pcap_t* m_PcapDescriptor;
43 
44  // c'tor should not be public
45  IPcapDevice() : IDevice() { m_PcapDescriptor = NULL; }
46 
47  public:
48 
53  struct PcapStats
54  {
56  uint64_t packetsRecv;
58  uint64_t packetsDrop;
61  };
62 
63 
64  virtual ~IPcapDevice();
65 
71  virtual void getStatistics(PcapStats& stats) const = 0;
72 
78  static std::string getPcapLibVersionInfo();
79 
85 #if __cplusplus > 201402L || _MSC_VER >= 1900
86  [[deprecated("Prefer building a BPFStringFilter class and calling verifyFilter on it to check if a filter string is valid see PcapFilter.h")]]
87 #endif
88  static bool verifyFilter(std::string filterAsString);
89 
97 #if __cplusplus > 201402L || _MSC_VER >= 1900
98  [[deprecated("Prefer building a GeneralFilter class and calling matchPacketWithFilter using the constructed filter. See PcapFilter.h")]]
99 #endif
100  static bool matchPacketWithFilter(std::string filterAsString, RawPacket* rawPacket);
101 
109  static bool matchPacketWithFilter(GeneralFilter& filter, RawPacket* rawPacket);
110 
111 
112  // implement abstract methods
113 
115 
123  virtual bool setFilter(std::string filterAsString);
124 
129  bool clearFilter();
130  };
131 
132 } // namespace pcpp
133 
134 #endif // PCAPPP_PCAP_DEVICE
The main namespace for the PcapPlusPlus lib.
static bool matchPacketWithFilter(std::string filterAsString, RawPacket *rawPacket)
uint64_t packetsDropByInterface
Definition: PcapDevice.h:60
Definition: PcapDevice.h:39
Definition: PcapFilter.h:136
Definition: RawPacket.h:252
Definition: Device.h:24
uint64_t packetsDrop
Definition: PcapDevice.h:58
Definition: Device.h:61
uint64_t packetsRecv
Definition: PcapDevice.h:56
static std::string getPcapLibVersionInfo()
static bool verifyFilter(std::string filterAsString)
virtual void getStatistics(PcapStats &stats) const =0
virtual bool setFilter(std::string filterAsString)
virtual bool setFilter(GeneralFilter &filter)
Definition: Device.h:77
Definition: PcapDevice.h:53