PcapPlusPlus  19.12
ArpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_ARP_LAYER
2 #define PACKETPP_ARP_LAYER
3 
4 #include "Layer.h"
5 #include "IpAddress.h"
6 #include "MacAddress.h"
7 
9 
14 namespace pcpp
15 {
16 
21 #pragma pack(push, 1)
22  struct arphdr {
24  uint16_t hardwareType;
26  uint16_t protocolType;
28  uint8_t hardwareSize;
30  uint8_t protocolSize;
32  uint16_t opcode;
34  uint8_t senderMacAddr[6];
36  uint32_t senderIpAddr;
38  uint8_t targetMacAddr[6];
40  uint32_t targetIpAddr;
41  };
42 #pragma pack(pop)
43 
47  enum ArpOpcode
48  {
49  ARP_REQUEST = 0x0001,
50  ARP_REPLY = 0x0002
51  };
52 
57  class ArpLayer : public Layer
58  {
59  public:
67  ArpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = ARP; m_DataLen = sizeof(arphdr); }
68 
77  ArpLayer(ArpOpcode opCode, const MacAddress& senderMacAddr, const MacAddress& targetMacAddr, const IPv4Address senderIpAddr, const IPv4Address& targetIpAddr);
78 
79  ~ArpLayer() {}
80 
85  arphdr* getArpHeader() const { return (arphdr*)m_Data; }
86 
91  MacAddress getSenderMacAddress() const { return MacAddress(getArpHeader()->senderMacAddr); }
92 
97  MacAddress getTargetMacAddress() const { return MacAddress(getArpHeader()->targetMacAddr); }
98 
103  IPv4Address getSenderIpAddr() const { return IPv4Address(getArpHeader()->senderIpAddr); }
104 
109  IPv4Address getTargetIpAddr() const { return IPv4Address(getArpHeader()->targetIpAddr); }
110 
111 
112  // implement abstract methods
113 
117  void parseNextLayer() {}
118 
122  size_t getHeaderLen() const { return sizeof(arphdr); }
123 
132  void computeCalculateFields();
133 
134  std::string toString() const;
135 
137  };
138 
139 } // namespace pcpp
140 #endif /* PACKETPP_ARP_LAYER */
pcpp::ArpLayer::parseNextLayer
void parseNextLayer()
Definition: ArpLayer.h:117
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::ArpLayer::getSenderIpAddr
IPv4Address getSenderIpAddr() const
Definition: ArpLayer.h:103
pcpp::IPv4Address
Definition: IpAddress.h:119
pcpp::Packet
Definition: Packet.h:26
Layer.h
pcpp::arphdr::senderMacAddr
uint8_t senderMacAddr[6]
Definition: ArpLayer.h:34
pcpp::ArpOpcode
ArpOpcode
Definition: ArpLayer.h:47
pcpp::arphdr::hardwareSize
uint8_t hardwareSize
Definition: ArpLayer.h:28
MacAddress.h
pcpp::ARP
Definition: ProtocolType.h:71
pcpp::ARP_REQUEST
ARP request.
Definition: ArpLayer.h:49
pcpp::ArpLayer::getTargetIpAddr
IPv4Address getTargetIpAddr() const
Definition: ArpLayer.h:109
pcpp::OsiModelNetworkLayer
Definition: ProtocolType.h:231
pcpp::ArpLayer::toString
std::string toString() const
pcpp::arphdr::protocolSize
uint8_t protocolSize
Definition: ArpLayer.h:30
pcpp::MacAddress
Definition: MacAddress.h:27
pcpp::arphdr::targetIpAddr
uint32_t targetIpAddr
Definition: ArpLayer.h:40
pcpp::ArpLayer
Definition: ArpLayer.h:57
pcpp::ArpLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: ArpLayer.h:136
pcpp::arphdr::opcode
uint16_t opcode
Definition: ArpLayer.h:32
pcpp::ArpLayer::getTargetMacAddress
MacAddress getTargetMacAddress() const
Definition: ArpLayer.h:97
pcpp::ArpLayer::getSenderMacAddress
MacAddress getSenderMacAddress() const
Definition: ArpLayer.h:91
pcpp::ArpLayer::computeCalculateFields
void computeCalculateFields()
pcpp::arphdr::hardwareType
uint16_t hardwareType
Definition: ArpLayer.h:24
IpAddress.h
pcpp::arphdr::senderIpAddr
uint32_t senderIpAddr
Definition: ArpLayer.h:36
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::arphdr::protocolType
uint16_t protocolType
Definition: ArpLayer.h:26
pcpp::Layer
Definition: Layer.h:70
pcpp::arphdr
Definition: ArpLayer.h:22
pcpp::ARP_REPLY
ARP reply (response)
Definition: ArpLayer.h:50
pcpp::ArpLayer::getArpHeader
arphdr * getArpHeader() const
Definition: ArpLayer.h:85
pcpp::arphdr::targetMacAddr
uint8_t targetMacAddr[6]
Definition: ArpLayer.h:38
pcpp::ArpLayer::getHeaderLen
size_t getHeaderLen() const
Definition: ArpLayer.h:122
pcpp::ArpLayer::ArpLayer
ArpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: ArpLayer.h:67