PcapPlusPlus
pcpp::EthLayer Class Reference

#include <EthLayer.h>

Inheritance diagram for pcpp::EthLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 EthLayer (uint8_t *data, size_t dataLen, Packet *packet)
 
 EthLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 EthLayer (const MacAddress &sourceMac, const MacAddress &destMac, uint16_t etherType=0)
 
ether_headergetEthHeader ()
 
MacAddress getSourceMac ()
 
void setSourceMac (const MacAddress &sourceMac)
 
MacAddress getDestMac ()
 
void setDestMac (const MacAddress &destMac)
 
void parseNextLayer ()
 
size_t getHeaderLen ()
 
void computeCalculateFields ()
 
std::string toString ()
 
OsiModelLayer getOsiModelLayer ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer ()
 
LayergetPrevLayer ()
 
ProtocolType getProtocol ()
 
uint8_t * getData ()
 
size_t getDataLen ()
 
uint8_t * getLayerPayload ()
 
size_t getLayerPayloadSize ()
 
bool isAllocatedToPacket ()
 
void copyData (uint8_t *toArr)
 
uint8_t * getDataPtr (size_t offset=0)
 

Detailed Description

Represents an Ethernet protocol layer

Constructor & Destructor Documentation

◆ EthLayer() [1/3]

pcpp::EthLayer::EthLayer ( uint8_t *  data,
size_t  dataLen,
Packet packet 
)
inline

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

Parameters
[in]dataA pointer to the raw data (will be casted to ether_header)
[in]dataLenSize of the data in bytes
[in]packetA pointer to the Packet instance where layer will be stored in

◆ EthLayer() [2/3]

pcpp::EthLayer::EthLayer ( 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 (will be casted to ether_header)
[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

◆ EthLayer() [3/3]

pcpp::EthLayer::EthLayer ( const MacAddress sourceMac,
const MacAddress destMac,
uint16_t  etherType = 0 
)

A constructor that creates a new Ethernet header and allocates the data

Parameters
[in]sourceMacThe source MAC address
[in]destMacThe destination MAC address
[in]etherTypeThe EtherType to be used. It's an optional parameter, a value of 0 will be set if not provided

Member Function Documentation

◆ computeCalculateFields()

void pcpp::EthLayer::computeCalculateFields ( )
virtual

Calculate ether_header::etherType for known protocols: IPv4, IPv6, ARP, VLAN

Implements pcpp::Layer.

◆ getDestMac()

MacAddress pcpp::EthLayer::getDestMac ( )
inline

Get the destination MAC address

Returns
The destination MAC address

◆ getEthHeader()

ether_header* pcpp::EthLayer::getEthHeader ( )
inline

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

Returns
A pointer to the ether_header

◆ getHeaderLen()

size_t pcpp::EthLayer::getHeaderLen ( )
inlinevirtual
Returns
Size of ether_header

Implements pcpp::Layer.

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getSourceMac()

MacAddress pcpp::EthLayer::getSourceMac ( )
inline

Get the source MAC address

Returns
The source MAC address

◆ parseNextLayer()

void pcpp::EthLayer::parseNextLayer ( )
virtual

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

Implements pcpp::Layer.

◆ setDestMac()

void pcpp::EthLayer::setDestMac ( const MacAddress destMac)
inline

Set destination MAC address

Parameters
destMacDestination MAC to set

◆ setSourceMac()

void pcpp::EthLayer::setSourceMac ( const MacAddress sourceMac)
inline

Set source MAC address

Parameters
sourceMacSource MAC to set

◆ toString()

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

Implements pcpp::Layer.