PcapPlusPlus  20.08+
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 
70  virtual void getStatistics(PcapStats& stats) const = 0;
71 
77  static std::string getPcapLibVersionInfo();
78 
84 #if __cplusplus > 201402L || _MSC_VER >= 1900
85  [[deprecated("Prefer building a BPFStringFilter class and calling verifyFilter on it to check if a filter string is valid see PcapFilter.h")]]
86 #endif
87  static bool verifyFilter(std::string filterAsString);
88 
96 #if __cplusplus > 201402L || _MSC_VER >= 1900
97  [[deprecated("Prefer building a GeneralFilter class and calling matchPacketWithFilter using the constructed filter. See PcapFilter.h")]]
98 #endif
99  static bool matchPacketWithFilter(std::string filterAsString, RawPacket* rawPacket);
100 
108  static bool matchPacketWithFilter(GeneralFilter& filter, RawPacket* rawPacket);
109 
110 
111  // implement abstract methods
112 
114 
122  virtual bool setFilter(std::string filterAsString);
123 
128  bool clearFilter();
129  };
130 
131 } // namespace pcpp
132 
133 #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:60
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:76
Definition: PcapDevice.h:53