PcapPlusPlus  Next
Device.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "PointerVector.h"
6 #include "RawPacket.h"
7 #include "PcapFilter.h"
8 
11 namespace pcpp
12 {
15 
19  class IDevice
20  {
21  protected:
22  // c'tor should not be public
23  IDevice() = default;
24 
25  public:
26  virtual ~IDevice() = default;
27 
30  virtual bool open() = 0;
31 
33  virtual void close() = 0;
34 
36  virtual bool isOpened() const = 0;
37  };
38 
43  class IFilterableDevice : public IDevice
44  {
45  protected:
46  // c'tor should not be public
47  IFilterableDevice() = default;
48 
49  public:
50  virtual ~IFilterableDevice() = default;
51 
56  bool setFilter(GeneralFilter& filter)
57  {
58  std::string filterAsString;
59  filter.parseToString(filterAsString);
60  return doUpdateFilter(&filterAsString);
61  }
62 
68  bool setFilter(std::string const& filterAsString)
69  {
70  return doUpdateFilter(&filterAsString);
71  }
72 
75  bool clearFilter()
76  {
77  return doUpdateFilter(nullptr);
78  }
79 
80  protected:
89  virtual bool doUpdateFilter(std::string const* filterAsString) = 0;
90  };
91 } // namespace pcpp
Definition: PcapFilter.h:158
virtual void parseToString(std::string &result) const =0
Definition: Device.h:20
virtual bool isOpened() const =0
virtual void close()=0
Close the device.
virtual bool open()=0
Definition: Device.h:44
virtual bool doUpdateFilter(std::string const *filterAsString)=0
Updates the filter on the device with a BPF string.
bool setFilter(std::string const &filterAsString)
Definition: Device.h:68
bool clearFilter()
Definition: Device.h:75
bool setFilter(GeneralFilter &filter)
Definition: Device.h:56
Definition: PointerVector.h:50
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19