PcapPlusPlus  Next
CiscoHdlcLayer.h
1 #pragma once
2 
3 #include "Layer.h"
4 
5 namespace pcpp
6 {
9  class CiscoHdlcLayer : public Layer
10  {
11  public:
14  enum class AddressType
15  {
17  Unicast = 0x0f,
19  Multicast = 0x8f,
21  Unknown
22  };
23 
28  CiscoHdlcLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet, CiscoHDLC)
29  {}
30 
33  explicit CiscoHdlcLayer(AddressType address);
34 
36  ~CiscoHdlcLayer() override = default;
37 
40 
42  uint8_t getAddressValue() const;
43 
46  void setAddress(AddressType address);
47 
50  void setAddressValue(uint8_t address);
51 
53  uint16_t getNextProtocol() const;
54 
59  static bool isDataValid(const uint8_t* data, size_t dataLen)
60  {
61  return data && dataLen >= sizeof(cisco_hdlc_header);
62  }
63 
64  // Overridden methods
65 
67  size_t getHeaderLen() const override
68  {
69  return sizeof(cisco_hdlc_header);
70  }
71 
73  void computeCalculateFields() override;
74 
76  void parseNextLayer() override;
77 
78  std::string toString() const override;
79 
81  {
82  return OsiModelDataLinkLayer;
83  }
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  {
98  return reinterpret_cast<cisco_hdlc_header*>(m_Data);
99  }
100 
101  void setNextProtocol(uint16_t protocol);
102  };
103 
104 } // namespace pcpp
Definition: CiscoHdlcLayer.h:10
size_t getHeaderLen() const override
Definition: CiscoHdlcLayer.h:67
AddressType
Definition: CiscoHdlcLayer.h:15
@ Unknown
Unknown address type.
void setAddressValue(uint8_t address)
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: CiscoHdlcLayer.h:59
OsiModelLayer getOsiModelLayer() const override
Definition: CiscoHdlcLayer.h:80
~CiscoHdlcLayer() override=default
Default destructor for this layer.
CiscoHdlcLayer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: CiscoHdlcLayer.h:28
void setAddress(AddressType address)
std::string toString() const override
CiscoHdlcLayer(AddressType address)
AddressType getAddress() const
uint16_t getNextProtocol() const
uint8_t getAddressValue() const
void computeCalculateFields() override
Calculate the Next Protocol when possible.
void parseNextLayer() override
Parses the next layer. Currently, supports IPv4 and IPv6.
Definition: Layer.h:60
Definition: Packet.h:22
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelDataLinkLayer
Data link layer (layer 2)
Definition: ProtocolType.h:229
const ProtocolType CiscoHDLC
Cisco HDLC protocol.
Definition: ProtocolType.h:221