PcapPlusPlus
VlanLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_VLAN_LAYER
2 #define PACKETPP_VLAN_LAYER
3 
4 #include "Layer.h"
5 #include "EthLayer.h"
6 #if defined(WIN32) || defined(WINx64)
7 #include <winsock2.h>
8 #endif
9 
11 
16 namespace pcpp
17 {
18 
23 #pragma pack(push, 1)
24  struct vlan_header {
25 #if (BYTE_ORDER == LITTLE_ENDIAN)
26 
27  uint16_t priority:3,
29  cfi:1,
31  vlanID:12;
32 #else
33  uint16_t vlanID:12,
34  cfi:1,
35  priority:3;
36 #endif
37 
38  uint16_t etherType;
39  };
40 #pragma pack(pop)
41 
42 
47  class VlanLayer : public Layer
48  {
49  public:
56  VlanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = VLAN; }
57 
65  VlanLayer(const uint16_t vlanID, bool cfi, uint8_t priority, uint16_t etherType);
66 
67  ~VlanLayer() {}
68 
73  inline vlan_header* getVlanHeader() { return (vlan_header*)m_Data; }
74 
81  inline uint16_t getVlanID() { return getVlanHeader()->vlanID >> 4; }
82 
87  inline uint8_t getCFI() { return getVlanHeader()->vlanID & 0x1; }
88 
93  inline uint8_t getPriority() { return (getVlanHeader()->vlanID & 0xF) >> 1; }
94 
101  inline void setVlanID(uint16_t id) { getVlanHeader()->vlanID = ((id << 4) & 0xff0) | (id >> 8); }
102 
108  inline void setCFI(bool cfi) { getVlanHeader()->vlanID |= cfi; }
109 
115  inline void setPriority(uint8_t priority) { getVlanHeader()->vlanID |= ((priority & 0x7) << 1); }
116 
117  // implement abstract methods
118 
122  void parseNextLayer();
123 
127  inline size_t getHeaderLen() { return sizeof(vlan_header); }
128 
133 
134  std::string toString();
135 
137  };
138 
139 } // namespace pcpp
140 
141 #endif /* PACKETPP_VLAN_LAYER */
void setCFI(bool cfi)
Definition: VlanLayer.h:108
uint16_t getVlanID()
Definition: VlanLayer.h:81
Definition: VlanLayer.h:24
void setVlanID(uint16_t id)
Definition: VlanLayer.h:101
vlan_header * getVlanHeader()
Definition: VlanLayer.h:73
Definition: Packet.h:26
The main namespace for the PcapPlusPlus lib.
Definition: ProtocolType.h:213
uint16_t vlanID
Definition: VlanLayer.h:27
void parseNextLayer()
Definition: VlanLayer.h:47
uint16_t cfi
Definition: VlanLayer.h:27
uint8_t getPriority()
Definition: VlanLayer.h:93
OsiModelLayer
Definition: ProtocolType.h:208
void computeCalculateFields()
Definition: VlanLayer.h:132
void setPriority(uint8_t priority)
Definition: VlanLayer.h:115
std::string toString()
size_t getHeaderLen()
Definition: VlanLayer.h:127
Definition: Layer.h:70
uint16_t etherType
Definition: VlanLayer.h:38
OsiModelLayer getOsiModelLayer()
Definition: VlanLayer.h:136
uint16_t priority
Definition: VlanLayer.h:27
VlanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: VlanLayer.h:56
uint8_t getCFI()
Definition: VlanLayer.h:87
Definition: ProtocolType.h:76