PcapPlusPlus  23.09
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  inline arphdr* getArpHeader() const { return (arphdr*)m_Data; }
87 
92  inline MacAddress getSenderMacAddress() const { return MacAddress(getArpHeader()->senderMacAddr); }
93 
98  inline MacAddress getTargetMacAddress() const { return MacAddress(getArpHeader()->targetMacAddr); }
99 
104  inline IPv4Address getSenderIpAddr() const { return getArpHeader()->senderIpAddr; }
105 
110  inline IPv4Address getTargetIpAddr() const { return getArpHeader()->targetIpAddr; }
111 
112  // implement abstract methods
113 
117  void parseNextLayer() {}
118 
122  size_t getHeaderLen() const { return sizeof(arphdr); }
123 
132  void computeCalculateFields();
133 
137  bool isRequest() const;
138 
142  bool isReply() const;
143 
144  std::string toString() const;
145 
147  };
148 
149 } // namespace pcpp
150 #endif /* PACKETPP_ARP_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
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:146
Definition: ProtocolType.h:340
uint16_t hardwareType
Definition: ArpLayer.h:25
Definition: IpAddress.h:42
IPv4Address getSenderIpAddr() const
Definition: ArpLayer.h:104
uint8_t senderMacAddr[6]
Definition: ArpLayer.h:35
size_t getHeaderLen() const
Definition: ArpLayer.h:122
uint16_t protocolType
Definition: ArpLayer.h:27
ARP reply (response)
Definition: ArpLayer.h:51
void parseNextLayer()
Definition: ArpLayer.h:117
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