Coverage Report

Created: 2025-09-27 07:03

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