PcapPlusPlus  Next
Sll2Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MacAddress.h"
4 #include "Layer.h"
5 
7 
12 namespace pcpp
13 {
18 #pragma pack(push, 1)
19  struct sll2_header
20  {
22  uint16_t protocol_type;
24  uint16_t reserved;
28  uint32_t interface_index;
30  uint16_t ARPHRD_type;
35  uint8_t packet_type;
41  uint8_t link_layer_addr[8];
42  };
43 #pragma pack(pop)
44 
49  class Sll2Layer : public Layer
50  {
51  public:
58  Sll2Layer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet, SLL2)
59  {}
60 
67  Sll2Layer(uint32_t interfaceIndex, uint16_t ARPHRDType, uint8_t packetType);
68 
69  ~Sll2Layer() override = default;
70 
77  {
78  return reinterpret_cast<sll2_header*>(m_Data);
79  }
80 
87  static bool isDataValid(const uint8_t* data, size_t dataLen);
88 
93  uint16_t getProtocolType() const;
94 
99  void setProtocolType(uint16_t protocolType);
100 
105  uint32_t getInterfaceIndex() const;
106 
111  void setInterfaceIndex(uint32_t interfaceIndex);
112 
117  uint16_t getArphrdType() const;
118 
123  void setArphrdType(uint16_t arphrdType);
124 
129  uint8_t getPacketType() const;
130 
135  void setPacketType(uint8_t packetType);
136 
141  uint8_t getLinkLayerAddrLen() const;
142 
147  const uint8_t* getLinkLayerAddr() const;
148 
155  bool setLinkLayerAddr(const uint8_t* addr, size_t addrLength);
156 
163 
169  bool setMacAddressAsLinkLayer(const MacAddress& macAddr);
170 
171  // implement abstract methods
172 
177  void parseNextLayer() override;
178 
182  void computeCalculateFields() override;
183 
187  size_t getHeaderLen() const override
188  {
189  return sizeof(sll2_header);
190  }
191 
192  std::string toString() const override;
193 
195  {
196  return OsiModelDataLinkLayer;
197  }
198  };
199 
200 } // namespace pcpp
Definition: Layer.h:69
Definition: MacAddress.h:25
Definition: Packet.h:27
Definition: Sll2Layer.h:50
uint8_t getLinkLayerAddrLen() const
const uint8_t * getLinkLayerAddr() const
void setArphrdType(uint16_t arphrdType)
bool setLinkLayerAddr(const uint8_t *addr, size_t addrLength)
uint8_t getPacketType() const
size_t getHeaderLen() const override
Definition: Sll2Layer.h:187
Sll2Layer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: Sll2Layer.h:58
void computeCalculateFields() override
uint16_t getProtocolType() const
bool setMacAddressAsLinkLayer(const MacAddress &macAddr)
void setProtocolType(uint16_t protocolType)
std::string toString() const override
OsiModelLayer getOsiModelLayer() const override
Definition: Sll2Layer.h:194
void setPacketType(uint8_t packetType)
uint16_t getArphrdType() const
MacAddress getLinkLayerAsMacAddress()
sll2_header * getSll2Header() const
Definition: Sll2Layer.h:76
void parseNextLayer() override
Sll2Layer(uint32_t interfaceIndex, uint16_t ARPHRDType, uint8_t packetType)
void setInterfaceIndex(uint32_t interfaceIndex)
uint32_t getInterfaceIndex() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:368
const ProtocolType SLL2
Definition: ProtocolType.h:333
Definition: Sll2Layer.h:20
uint16_t ARPHRD_type
Definition: Sll2Layer.h:30
uint16_t protocol_type
Definition: Sll2Layer.h:22
uint8_t link_layer_addr_len
Definition: Sll2Layer.h:37
uint16_t reserved
Definition: Sll2Layer.h:24
uint8_t link_layer_addr[8]
Definition: Sll2Layer.h:41
uint32_t interface_index
Definition: Sll2Layer.h:28
uint8_t packet_type
Definition: Sll2Layer.h:35