Coverage Report

Created: 2023-01-17 06:15

/src/PcapPlusPlus/Pcap++/header/Device.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef PCAPPP_DEVICE
2
#define PCAPPP_DEVICE
3
4
/// @file
5
6
#include "PointerVector.h"
7
#include "RawPacket.h"
8
#include "PcapFilter.h"
9
10
/**
11
* \namespace pcpp
12
* \brief The main namespace for the PcapPlusPlus lib
13
*/
14
namespace pcpp
15
{
16
  /** A vector of pointers to RawPacket */
17
  typedef PointerVector<RawPacket> RawPacketVector;
18
19
  /**
20
   * @class IDevice
21
   * An abstract interface representing all packet processing devices. It stands as the root class for all devices.
22
   * This is an abstract class that cannot be instantiated
23
   */
24
  class IDevice
25
  {
26
  protected:
27
    bool m_DeviceOpened;
28
29
    // c'tor should not be public
30
17.6k
    IDevice() : m_DeviceOpened(false) {}
31
32
  public:
33
34
17.6k
    virtual ~IDevice() {}
35
36
    /**
37
     * Open the device
38
     * @return True if device was opened successfully, false otherwise
39
     */
40
    virtual bool open() = 0;
41
42
    /**
43
     * Close the device
44
     * @return No return value
45
     */
46
    virtual void close() = 0;
47
48
    /**
49
     * @return True if the file is opened, false otherwise
50
     */
51
    inline bool isOpened() { return m_DeviceOpened; }
52
  };
53
54
55
  /**
56
   * @class IFilterableDevice
57
   * An abstract interface representing all devices that have BPF (Berkeley Packet Filter) filtering capabilities,
58
   * meaning devices that can filter packets based on the BPF filtering syntax.
59
   * This is an abstract class that cannot be instantiated
60
   */
61
  class IFilterableDevice
62
  {
63
  protected:
64
65
    // c'tor should not be public
66
17.6k
    IFilterableDevice() {}
67
68
  public:
69
70
17.6k
    virtual ~IFilterableDevice() {}
71
72
    /**
73
     * Set a filter for the device. When implemented by the device, only packets that match the filter will be received
74
     * @param[in] filter The filter to be set in PcapPlusPlus' GeneralFilter format
75
     * @return True if filter set successfully, false otherwise
76
     */
77
    virtual bool setFilter(GeneralFilter& filter)
78
0
    {
79
0
      std::string filterAsString;
80
0
      filter.parseToString(filterAsString);
81
0
      return setFilter(filterAsString);
82
0
    }
83
84
    /**
85
     * Set a filter for the device. When implemented by the device, only packets that match the filter will be received
86
     * @param[in] filterAsString The filter to be set in Berkeley Packet Filter (BPF) syntax (http://biot.com/capstats/bpf.html)
87
     * @return True if filter set successfully, false otherwise
88
     */
89
    virtual bool setFilter(std::string filterAsString) = 0;
90
91
    /**
92
     * Clear the filter currently set on the device
93
     * @return True if filter was removed successfully or if no filter was set, false otherwise
94
     */
95
    virtual bool clearFilter() = 0;
96
  };
97
}
98
99
#endif // PCAPPP_DEVICE