Coverage Report

Created: 2024-02-25 06:29

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