PcapPlusPlus  20.08
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 () const
 
MacAddress getSourceMac () const
 
void setSourceMac (const MacAddress &sourceMac)
 
MacAddress getDestMac () const
 
void setDestMac (const MacAddress &destMac)
 
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 an Ethernet II 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 ( ) const
inline

Get the destination MAC address

Returns
The destination MAC address

◆ getEthHeader()

ether_header* pcpp::EthLayer::getEthHeader ( ) const
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 ( ) const
inlinevirtual
Returns
Size of ether_header

Implements pcpp::Layer.

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getSourceMac()

MacAddress pcpp::EthLayer::getSourceMac ( ) const
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 ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.