PcapPlusPlus  22.11
pcpp::VlanLayer Class Reference

#include <VlanLayer.h>

Inheritance diagram for pcpp::VlanLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 VlanLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 VlanLayer (const uint16_t vlanID, bool cfi, uint8_t priority, uint16_t etherType=0)
 
vlan_headergetVlanHeader () const
 
uint16_t getVlanID () const
 
uint8_t getCFI () const
 
uint8_t getPriority () const
 
void setVlanID (uint16_t id)
 
void setCFI (bool cfi)
 
void setPriority (uint8_t priority)
 
void parseNextLayer ()
 
size_t getHeaderLen () const
 
void computeCalculateFields ()
 
std::string toString () const
 
OsiModelLayer getOsiModelLayer () const
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Detailed Description

Represents a VLAN tunnel layer

Constructor & Destructor Documentation

◆ VlanLayer() [1/2]

pcpp::VlanLayer::VlanLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
inline

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ VlanLayer() [2/2]

pcpp::VlanLayer::VlanLayer ( const uint16_t  vlanID,
bool  cfi,
uint8_t  priority,
uint16_t  etherType = 0 
)

A constructor that allocates a new VLAN header

Parameters
[in]vlanIDVLAN ID
[in]cfiCFI value
[in]priorityPriority value
[in]etherTypeProtocol EtherType of the next layer. It's an optional parameter, a value of 0 will be set if not provided

Member Function Documentation

◆ computeCalculateFields()

void pcpp::VlanLayer::computeCalculateFields ( )
virtual

Calculate the EtherType for known protocols: IPv4, IPv6, ARP, VLAN

Implements pcpp::Layer.

◆ getCFI()

uint8_t pcpp::VlanLayer::getCFI ( ) const
Returns
The CFI bit value

◆ getHeaderLen()

size_t pcpp::VlanLayer::getHeaderLen ( ) const
inlinevirtual
Returns
Size of vlan_header

Implements pcpp::Layer.

◆ getOsiModelLayer()

OsiModelLayer pcpp::VlanLayer::getOsiModelLayer ( ) const
inlinevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getPriority()

uint8_t pcpp::VlanLayer::getPriority ( ) const
Returns
The priority value

◆ getVlanHeader()

vlan_header* pcpp::VlanLayer::getVlanHeader ( ) const
inline

Get a pointer to the VLAN header. Notice this points directly to the data, so every change will change the actual packet data

Returns
A pointer to the vlan_header

◆ getVlanID()

uint16_t pcpp::VlanLayer::getVlanID ( ) const

Get the VLAN ID value. This method differs from vlan_header::vlanID because vlan_header::vlanID is 12 bits long in a 16 bit field. This methods extracts only the 12 bit relevant for the VLAN ID

Returns
VLAN ID value

◆ parseNextLayer()

void pcpp::VlanLayer::parseNextLayer ( )
virtual

Currently identifies the following next layers: IPv4Layer, IPv6Layer, ArpLayer, VlanLayer, MplsLayer. Otherwise sets PayloadLayer

Implements pcpp::Layer.

◆ setCFI()

void pcpp::VlanLayer::setCFI ( bool  cfi)

Set CFI bit

Parameters
[in]cfiThe CFI bit to set

◆ setPriority()

void pcpp::VlanLayer::setPriority ( uint8_t  priority)

Set priority value

Parameters
[in]priorityThe priority value to set

◆ setVlanID()

void pcpp::VlanLayer::setVlanID ( uint16_t  id)

Set VLAN ID. This method differs from setting vlan_header::vlanID because vlan_header::vlanID is 12 bits long in a 16 bit field. This methods sets only the 12 bit relevant for the VLAN ID

Parameters
[in]idThe VLAN ID to set

◆ toString()

std::string pcpp::VlanLayer::toString ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.