PcapPlusPlus  Next
VlanLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "EthLayer.h"
5 
7 
12 namespace pcpp
13 {
14 
19 #pragma pack(push, 1)
20  struct vlan_header
21  {
31  uint16_t vlan;
33  uint16_t etherType;
34  };
35 #pragma pack(pop)
36 
41  class VlanLayer : public Layer
42  {
43  public:
50  VlanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
51  : Layer(data, dataLen, prevLayer, packet, VLAN)
52  {}
53 
62  VlanLayer(const uint16_t vlanID, bool cfi, uint8_t priority, uint16_t etherType = 0);
63 
64  ~VlanLayer() override = default;
65 
72  {
73  return reinterpret_cast<vlan_header*>(m_Data);
74  }
75 
82  uint16_t getVlanID() const;
83 
88  uint8_t getCFI() const;
89 
94  uint8_t getPriority() const;
95 
102  void setVlanID(uint16_t id);
103 
109  void setCFI(bool cfi);
110 
116  void setPriority(uint8_t priority);
117 
118  // implement abstract methods
119 
124  void parseNextLayer() override;
125 
129  size_t getHeaderLen() const override
130  {
131  return sizeof(vlan_header);
132  }
133 
137  void computeCalculateFields() override;
138 
139  std::string toString() const override;
140 
142  {
143  return OsiModelDataLinkLayer;
144  }
145  };
146 
147 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: VlanLayer.h:42
uint8_t getCFI() const
std::string toString() const override
uint16_t getVlanID() const
VlanLayer(const uint16_t vlanID, bool cfi, uint8_t priority, uint16_t etherType=0)
void parseNextLayer() override
uint8_t getPriority() const
VlanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: VlanLayer.h:50
vlan_header * getVlanHeader() const
Definition: VlanLayer.h:71
void setPriority(uint8_t priority)
OsiModelLayer getOsiModelLayer() const override
Definition: VlanLayer.h:141
size_t getHeaderLen() const override
Definition: VlanLayer.h:129
void computeCalculateFields() override
void setCFI(bool cfi)
void setVlanID(uint16_t id)
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:368
const ProtocolType VLAN
Definition: ProtocolType.h:83
Definition: VlanLayer.h:21
uint16_t etherType
Definition: VlanLayer.h:33
uint16_t vlan
Definition: VlanLayer.h:31