PcapPlusPlus  24.09
ArpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "IpAddress.h"
5 #include "MacAddress.h"
6 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
21  struct arphdr
22  {
24  uint16_t hardwareType;
26  uint16_t protocolType;
28  uint8_t hardwareSize;
31  uint8_t protocolSize;
34  uint16_t opcode;
36  uint8_t senderMacAddr[6];
38  uint32_t senderIpAddr;
40  uint8_t targetMacAddr[6];
42  uint32_t targetIpAddr;
43  };
44 #pragma pack(pop)
45 
49  enum ArpOpcode
50  {
51  ARP_REQUEST = 0x0001,
52  ARP_REPLY = 0x0002
53  };
54 
59  class ArpLayer : public Layer
60  {
61  public:
69  ArpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
70  : Layer(data, dataLen, prevLayer, packet, ARP)
71  {
72  m_DataLen = sizeof(arphdr);
73  }
74 
83  ArpLayer(ArpOpcode opCode, const MacAddress& senderMacAddr, const MacAddress& targetMacAddr,
84  const IPv4Address& senderIpAddr, const IPv4Address& targetIpAddr);
85 
86  ~ArpLayer()
87  {}
88 
94  inline arphdr* getArpHeader() const
95  {
96  return (arphdr*)m_Data;
97  }
98 
104  {
105  return MacAddress(getArpHeader()->senderMacAddr);
106  }
107 
113  {
114  return MacAddress(getArpHeader()->targetMacAddr);
115  }
116 
122  {
123  return getArpHeader()->senderIpAddr;
124  }
125 
131  {
132  return getArpHeader()->targetIpAddr;
133  }
134 
135  // implement abstract methods
136 
141  {}
142 
146  size_t getHeaderLen() const
147  {
148  return sizeof(arphdr);
149  }
150 
160 
164  bool isRequest() const;
165 
169  bool isReply() const;
170 
171  std::string toString() const;
172 
174  {
175  return OsiModelNetworkLayer;
176  }
177  };
178 
179 } // namespace pcpp
Definition: ArpLayer.h:60
ArpLayer(ArpOpcode opCode, const MacAddress &senderMacAddr, const MacAddress &targetMacAddr, const IPv4Address &senderIpAddr, const IPv4Address &targetIpAddr)
size_t getHeaderLen() const
Definition: ArpLayer.h:146
OsiModelLayer getOsiModelLayer() const
Definition: ArpLayer.h:173
arphdr * getArpHeader() const
Definition: ArpLayer.h:94
IPv4Address getTargetIpAddr() const
Definition: ArpLayer.h:130
bool isReply() const
std::string toString() const
MacAddress getTargetMacAddress() const
Definition: ArpLayer.h:112
void parseNextLayer()
Definition: ArpLayer.h:140
bool isRequest() const
IPv4Address getSenderIpAddr() const
Definition: ArpLayer.h:121
ArpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: ArpLayer.h:69
void computeCalculateFields()
MacAddress getSenderMacAddress() const
Definition: ArpLayer.h:103
Definition: IpAddress.h:32
Definition: Layer.h:70
Definition: MacAddress.h:25
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
ArpOpcode
Definition: ArpLayer.h:50
@ ARP_REQUEST
ARP request.
Definition: ArpLayer.h:51
@ ARP_REPLY
ARP reply (response)
Definition: ArpLayer.h:52
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelNetworkLayer
Definition: ProtocolType.h:360
const ProtocolType ARP
Definition: ProtocolType.h:78
Definition: ArpLayer.h:22
uint32_t targetIpAddr
Definition: ArpLayer.h:42
uint8_t protocolSize
Definition: ArpLayer.h:31
uint16_t opcode
Definition: ArpLayer.h:34
uint16_t hardwareType
Definition: ArpLayer.h:24
uint8_t targetMacAddr[6]
Definition: ArpLayer.h:40
uint32_t senderIpAddr
Definition: ArpLayer.h:38
uint8_t hardwareSize
Definition: ArpLayer.h:28
uint8_t senderMacAddr[6]
Definition: ArpLayer.h:36
uint16_t protocolType
Definition: ArpLayer.h:26