PcapPlusPlus  21.11
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
23  {
25  uint16_t hardwareType;
27  uint16_t protocolType;
29  uint8_t hardwareSize;
31  uint8_t protocolSize;
33  uint16_t opcode;
35  uint8_t senderMacAddr[6];
37  uint32_t senderIpAddr;
39  uint8_t targetMacAddr[6];
41  uint32_t targetIpAddr;
42  };
43 #pragma pack(pop)
44 
48  enum ArpOpcode
49  {
50  ARP_REQUEST = 0x0001,
51  ARP_REPLY = 0x0002
52  };
53 
58  class ArpLayer : public Layer
59  {
60  public:
68  ArpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = ARP; m_DataLen = sizeof(arphdr); }
69 
79 
80  ~ArpLayer() {}
81 
86  arphdr* getArpHeader() const { return (arphdr*)m_Data; }
87 
92  MacAddress getSenderMacAddress() const { return MacAddress(getArpHeader()->senderMacAddr); }
93 
98  MacAddress getTargetMacAddress() const { return MacAddress(getArpHeader()->targetMacAddr); }
99 
104  IPv4Address getSenderIpAddr() const { return getArpHeader()->senderIpAddr; }
105 
110  IPv4Address getTargetIpAddr() const { return getArpHeader()->targetIpAddr; }
111 
112 
113  // implement abstract methods
114 
118  void parseNextLayer() {}
119 
123  size_t getHeaderLen() const { return sizeof(arphdr); }
124 
133  void computeCalculateFields();
134 
135  std::string toString() const;
136 
138  };
139 
140 } // namespace pcpp
141 #endif /* PACKETPP_ARP_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:258
IPv4Address getTargetIpAddr() const
Definition: ArpLayer.h:110
uint32_t senderIpAddr
Definition: ArpLayer.h:37
uint8_t targetMacAddr[6]
Definition: ArpLayer.h:39
Definition: Layer.h:70
ARP request.
Definition: ArpLayer.h:50
Definition: Packet.h:26
Definition: ArpLayer.h:58
uint16_t opcode
Definition: ArpLayer.h:33
ArpOpcode
Definition: ArpLayer.h:48
uint32_t targetIpAddr
Definition: ArpLayer.h:41
uint8_t hardwareSize
Definition: ArpLayer.h:29
OsiModelLayer getOsiModelLayer() const
Definition: ArpLayer.h:137
Definition: ProtocolType.h:265
uint16_t hardwareType
Definition: ArpLayer.h:25
Definition: IpAddress.h:27
IPv4Address getSenderIpAddr() const
Definition: ArpLayer.h:104
uint8_t senderMacAddr[6]
Definition: ArpLayer.h:35
size_t getHeaderLen() const
Definition: ArpLayer.h:123
uint16_t protocolType
Definition: ArpLayer.h:27
ARP reply (response)
Definition: ArpLayer.h:51
void parseNextLayer()
Definition: ArpLayer.h:118
ArpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: ArpLayer.h:68
Definition: ArpLayer.h:22
MacAddress getSenderMacAddress() const
Definition: ArpLayer.h:92
Definition: MacAddress.h:28
const ProtocolType ARP
Definition: ProtocolType.h:73
arphdr * getArpHeader() const
Definition: ArpLayer.h:86
uint8_t protocolSize
Definition: ArpLayer.h:31
MacAddress getTargetMacAddress() const
Definition: ArpLayer.h:98