PcapPlusPlus  Next
pcpp::ArpLayer Class Reference

#include <ArpLayer.h>

Inheritance diagram for pcpp::ArpLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 ArpLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 ArpLayer (ArpOpcode opCode, const MacAddress &senderMacAddr, const IPv4Address &senderIpAddr, const MacAddress &targetMacAddr, const IPv4Address &targetIpAddr)
 A constructor that creates an ARP header. More...
 
 ArpLayer (ArpOpcode opCode, const MacAddress &senderMacAddr, const MacAddress &targetMacAddr, const IPv4Address &senderIpAddr, const IPv4Address &targetIpAddr)
 
 ArpLayer (ArpRequest const &arpRequest)
 A constructor that creates an ARP request header. More...
 
 ArpLayer (ArpReply const &arpReply)
 A constructor that creates an ARP reply header. More...
 
 ArpLayer (GratuitousArpRequest const &gratuitousArpRequest)
 A constructor that creates a gratuitous ARP request header. More...
 
 ArpLayer (GratuitousArpReply const &gratuitousArpReply)
 A constructor that creates a gratuitous ARP reply header. More...
 
arphdrgetArpHeader () const
 
ArpOpcode getOpcode () const
 
MacAddress getSenderMacAddress () const
 
MacAddress getTargetMacAddress () const
 
IPv4Address getSenderIpAddr () const
 
IPv4Address getTargetIpAddr () const
 
void parseNextLayer () override
 Does nothing for this layer (ArpLayer is always last)
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 
ArpMessageType getMessageType () const
 Attempts to determine the ARP message type based on the header signature. More...
 
bool isRequest () const
 Is this packet an ARP request?
 
bool isReply () const
 Is this packet an ARP reply?
 
std::string toString () const override
 
OsiModelLayer getOsiModelLayer () const override
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) 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 override
 

Detailed Description

Represents an ARP protocol layer. Currently only IPv4 ARP messages are supported

Constructor & Destructor Documentation

◆ ArpLayer() [1/7]

pcpp::ArpLayer::ArpLayer ( 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 arphdr)
[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

◆ ArpLayer() [2/7]

pcpp::ArpLayer::ArpLayer ( ArpOpcode  opCode,
const MacAddress senderMacAddr,
const IPv4Address senderIpAddr,
const MacAddress targetMacAddr,
const IPv4Address targetIpAddr 
)

A constructor that creates an ARP header.

Parameters
[in]opCodeARP message type (ARP request or ARP reply)
[in]senderMacAddrThe sender MAC address (will be put in arphdr::senderMacAddr)
[in]senderIpAddrThe sender IP address (will be put in arphdr::senderIpAddr)
[in]targetMacAddrThe target MAC address (will be put in arphdr::targetMacAddr)
[in]targetIpAddrThe target IP address (will be put in arphdr::targetIpAddr)
Remarks
No validation is done on the input parameters. The caller must ensure that the input creates a valid header.

◆ ArpLayer() [3/7]

pcpp::ArpLayer::ArpLayer ( ArpOpcode  opCode,
const MacAddress senderMacAddr,
const MacAddress targetMacAddr,
const IPv4Address senderIpAddr,
const IPv4Address targetIpAddr 
)

A constructor that allocates a new ARP header

Parameters
[in]opCodeARP message type (ARP request or ARP reply)
[in]senderMacAddrThe sender MAC address (will be put in arphdr::senderMacAddr)
[in]targetMacAddrThe target MAC address (will be put in arphdr::targetMacAddr)
[in]senderIpAddrThe sender IP address (will be put in arphdr::senderIpAddr)
[in]targetIpAddrThe target IP address (will be put in arphdr::targetIpAddr)
Deprecated:
This constructor has been deprecated. Please use one of the other overloads.
Remarks
This constructor zeroes the target MAC address for ARP requests to keep backward compatibility.

◆ ArpLayer() [4/7]

pcpp::ArpLayer::ArpLayer ( ArpRequest const &  arpRequest)
explicit

A constructor that creates an ARP request header.

Parameters
arpRequestThe ARP request data

◆ ArpLayer() [5/7]

pcpp::ArpLayer::ArpLayer ( ArpReply const &  arpReply)
explicit

A constructor that creates an ARP reply header.

Parameters
arpReplyThe ARP reply data

◆ ArpLayer() [6/7]

pcpp::ArpLayer::ArpLayer ( GratuitousArpRequest const &  gratuitousArpRequest)
explicit

A constructor that creates a gratuitous ARP request header.

Parameters
gratuitousArpRequestThe gratuitous ARP request data

◆ ArpLayer() [7/7]

pcpp::ArpLayer::ArpLayer ( GratuitousArpReply const &  gratuitousArpReply)
explicit

A constructor that creates a gratuitous ARP reply header.

Parameters
gratuitousArpReplyThe gratuitous ARP reply data

Member Function Documentation

◆ computeCalculateFields()

void pcpp::ArpLayer::computeCalculateFields ( )
overridevirtual

Calculate the following fields:

Implements pcpp::Layer.

◆ getArpHeader()

arphdr* pcpp::ArpLayer::getArpHeader ( ) const
inline

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

Returns
A pointer to the arphdr

◆ getHeaderLen()

size_t pcpp::ArpLayer::getHeaderLen ( ) const
inlineoverridevirtual
Returns
The size of arphdr

Implements pcpp::Layer.

◆ getMessageType()

ArpMessageType pcpp::ArpLayer::getMessageType ( ) const

Attempts to determine the ARP message type based on the header signature.

Returns
An ArpMessageType representing the ARP message type.

◆ getOpcode()

ArpOpcode pcpp::ArpLayer::getOpcode ( ) const

Get the ARP opcode

Returns
The ARP opcode
Remarks
The opcode may not be one of the values in ArpOpcode

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getSenderIpAddr()

IPv4Address pcpp::ArpLayer::getSenderIpAddr ( ) const
inline

Get the sender protocol address (SPA) in the form of IPv4Address

Returns
An IPv4Address containing the sender protocol address (SPA)

◆ getSenderMacAddress()

MacAddress pcpp::ArpLayer::getSenderMacAddress ( ) const
inline

Get the sender hardware address (SHA) in the form of MacAddress

Returns
A MacAddress containing the sender hardware address (SHA)

◆ getTargetIpAddr()

IPv4Address pcpp::ArpLayer::getTargetIpAddr ( ) const
inline

Get the target protocol address (TPA) in the form of IPv4Address

Returns
An IPv4Address containing the target protocol address (TPA)

◆ getTargetMacAddress()

MacAddress pcpp::ArpLayer::getTargetMacAddress ( ) const
inline

Get the target hardware address (THA) in the form of MacAddress

Returns
A MacAddress containing the target hardware address (THA)

◆ toString()

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

Implements pcpp::Layer.