Coverage Report

Created: 2026-10-17 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/header/CiscoHdlcLayer.h
Line
Count
Source
1
#pragma once
2
3
#include "Layer.h"
4
5
namespace pcpp
6
{
7
  /// @class CiscoHdlcLayer
8
  /// Represents a Cisco HDLC protocol layer
9
  class CiscoHdlcLayer : public Layer
10
  {
11
  public:
12
    /// @enum AddressType
13
    /// Represents Cisco HDLC address types
14
    enum class AddressType
15
    {
16
      /// Unicast
17
      Unicast = 0x0f,
18
      /// Multicast
19
      Multicast = 0x8f,
20
      /// Unknown address type
21
      Unknown
22
    };
23
24
    /// A constructor that creates the layer from an existing packet raw data
25
    /// @param[in] data A pointer to the raw data
26
    /// @param[in] dataLen Size of the data in bytes
27
    /// @param[in] packet A pointer to the Packet instance where layer will be stored
28
531
    CiscoHdlcLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet, CiscoHDLC)
29
531
    {}
30
31
    /// A constructor that creates a new Cisco HDLC layer
32
    /// @param[in] address The address field value
33
    explicit CiscoHdlcLayer(AddressType address);
34
35
    /// Default destructor for this layer
36
    ~CiscoHdlcLayer() override = default;
37
38
    /// @return The address field enum value
39
    AddressType getAddress() const;
40
41
    /// @return The address field raw value
42
    uint8_t getAddressValue() const;
43
44
    /// Set the address field enum value
45
    /// @param[in] address The address enum value to set
46
    void setAddress(AddressType address);
47
48
    /// Set the address field value
49
    /// @param[in] address The address value to set
50
    void setAddressValue(uint8_t address);
51
52
    /// @return The protocol type value
53
    uint16_t getNextProtocol() const;
54
55
    /// A static method that validates the input data
56
    /// @param[in] data The pointer to the beginning of a byte stream of a Cisco HDLC packet
57
    /// @param[in] dataLen The length of the byte stream
58
    /// @return True if the data is valid and can represent a Cisco HDLC packet
59
    static bool isDataValid(const uint8_t* data, size_t dataLen)
60
691
    {
61
691
      return data && dataLen >= sizeof(cisco_hdlc_header);
62
691
    }
63
64
    // Overridden methods
65
66
    /// @return The size of the HDLC header which is 4 bytes
67
    size_t getHeaderLen() const override
68
166
    {
69
166
      return sizeof(cisco_hdlc_header);
70
166
    }
71
72
    /// Calculate the Next Protocol when possible
73
    void computeCalculateFields() override;
74
75
    /// Parses the next layer. Currently, supports IPv4 and IPv6
76
    void parseNextLayer() override;
77
78
    std::string toString() const override;
79
80
    OsiModelLayer getOsiModelLayer() const override
81
166
    {
82
166
      return OsiModelDataLinkLayer;
83
166
    }
84
85
    /// @struct SerializedFields
86
    /// Fields written by CiscoHdlcLayer's serializeLayer(), in addition to
87
    /// Layer::SerializedFields.
88
    struct SerializedFields : Layer::SerializedFields
89
    {
90
      /// @return All field descriptors for CiscoHdlcLayer
91
      static std::vector<FieldDescriptor> all()
92
0
      {
93
0
        auto result = Layer::SerializedFields::all();
94
0
        std::initializer_list<FieldDescriptor> extra{ Address, NextProtocol };
95
0
        std::copy(extra.begin(), extra.end(), std::back_inserter(result));
96
0
        return result;
97
0
      }
98
99
      /// @brief Field descriptor for the address field, written as a string (see CiscoHdlcLayer::AddressType).
100
      static const FieldDescriptor Address;
101
102
      /// @brief Field descriptor for the protocol type of the encapsulated payload, written as a number.
103
      static const FieldDescriptor NextProtocol;
104
    };
105
106
  protected:
107
    void serializeLayer(ObjectScope& serializer) const override;
108
109
  private:
110
#pragma pack(push, 1)
111
    struct cisco_hdlc_header
112
    {
113
      uint8_t address;
114
      uint8_t control;
115
      uint16_t protocol;
116
    };
117
#pragma pack(pop)
118
    static_assert(sizeof(cisco_hdlc_header) == 4, "cisco_hdlc_header size is not 4 bytes");
119
120
    cisco_hdlc_header* getCiscoHdlcHeader() const
121
563
    {
122
563
      return reinterpret_cast<cisco_hdlc_header*>(m_Data);
123
563
    }
124
125
    void setNextProtocol(uint16_t protocol);
126
  };
127
128
}  // namespace pcpp