/src/PcapPlusPlus/Packet++/header/CiscoHdlcLayer.h
Line | Count | Source (jump to first uncovered line) |
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 | 0 | CiscoHdlcLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet, CiscoHDLC) |
29 | 0 | {} |
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 | 0 | { |
61 | 0 | return data && dataLen >= sizeof(cisco_hdlc_header); |
62 | 0 | } |
63 | | |
64 | | // Overridden methods |
65 | | |
66 | | /// @return The size of the HDLC header which is 4 bytes |
67 | | size_t getHeaderLen() const override |
68 | 0 | { |
69 | 0 | return sizeof(cisco_hdlc_header); |
70 | 0 | } |
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 | 0 | { |
82 | 0 | return OsiModelDataLinkLayer; |
83 | 0 | } |
84 | | |
85 | | private: |
86 | | #pragma pack(push, 1) |
87 | | struct cisco_hdlc_header |
88 | | { |
89 | | uint8_t address; |
90 | | uint8_t control; |
91 | | uint16_t protocol; |
92 | | }; |
93 | | #pragma pack(pop) |
94 | | static_assert(sizeof(cisco_hdlc_header) == 4, "cisco_hdlc_header size is not 4 bytes"); |
95 | | |
96 | | cisco_hdlc_header* getCiscoHdlcHeader() const |
97 | 0 | { |
98 | 0 | return reinterpret_cast<cisco_hdlc_header*>(m_Data); |
99 | 0 | } |
100 | | |
101 | | void setNextProtocol(uint16_t protocol); |
102 | | }; |
103 | | |
104 | | } // namespace pcpp |