34 #include <tins/macros.h> 36 #include <tins/endianness.h> 37 #include <tins/hw_address.h> 38 #include <tins/ip_address.h> 42 class NetworkInterface;
81 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
97 ARP(ipaddress_type target_ip = ipaddress_type(),
98 ipaddress_type sender_ip = ipaddress_type(),
99 const hwaddress_type& target_hw = hwaddress_type(),
100 const hwaddress_type& sender_hw = hwaddress_type());
114 ARP(
const uint8_t* buffer, uint32_t total_sz);
123 return header_.sender_hw_address;
132 return ipaddress_type(header_.sender_ip_address);
141 return header_.target_hw_address;
150 return ipaddress_type(header_.target_ip_address);
159 return Endian::be_to_host(header_.hw_address_format);
168 return Endian::be_to_host(header_.proto_address_format);
177 return header_.hw_address_length;
186 return header_.proto_address_length;
195 return Endian::be_to_host(header_.opcode);
203 uint32_t header_size()
const;
212 void sender_hw_addr(
const hwaddress_type& address);
219 void sender_ip_addr(ipaddress_type address);
226 void target_hw_addr(
const hwaddress_type& address);
233 void target_ip_addr(ipaddress_type address);
240 void hw_addr_format(uint16_t format);
247 void prot_addr_format(uint16_t format);
254 void hw_addr_length(uint8_t length);
261 void prot_addr_length(uint8_t length);
268 void opcode(
Flags code);
287 static EthernetII make_arp_request(ipaddress_type target,
288 ipaddress_type sender,
289 const hwaddress_type& hw_snd = hwaddress_type());
303 static EthernetII make_arp_reply(ipaddress_type target,
304 ipaddress_type sender,
305 const hwaddress_type& hw_tgt = hwaddress_type(),
306 const hwaddress_type& hw_snd = hwaddress_type());
315 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
321 return new ARP(*
this);
326 uint16_t hw_address_format;
327 uint16_t proto_address_format;
328 uint8_t hw_address_length;
329 uint8_t proto_address_length;
331 uint8_t sender_hw_address[hwaddress_type::address_size];
332 uint32_t sender_ip_address;
333 uint8_t target_hw_address[hwaddress_type::address_size];
334 uint32_t target_ip_address;
337 void write_serialization(uint8_t* buffer, uint32_t total_sz);
Flags
Enum which indicates the type of ARP packet.
Definition: arp.h:70
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
uint16_t prot_addr_format() const
Getter for the protocol address format field.
Definition: arp.h:167
ARP * clone() const
Definition: arp.h:320
uint8_t prot_addr_length() const
Getter for the protocol address length field.
Definition: arp.h:185
uint8_t hw_addr_length() const
Getter for the hardware address length field.
Definition: arp.h:176
Represents an ARP PDU.
Definition: arp.h:50
HWAddress< 6 > hwaddress_type
Definition: arp.h:55
ipaddress_type target_ip_addr() const
Getter for the target's IP address.
Definition: arp.h:149
hwaddress_type sender_hw_addr() const
Getter for the sender's hardware address.
Definition: arp.h:122
uint16_t opcode() const
Getter for the ARP opcode field.
Definition: arp.h:194
The Tins namespace.
Definition: address_range.h:38
Represents an Ethernet II PDU.
Definition: ethernetII.h:46
Abstraction of an IPv4 address.
Definition: ip_address.h:45
uint16_t hw_addr_format() const
Getter for the hardware address format field.
Definition: arp.h:158
ipaddress_type sender_ip_addr() const
Getter for the sender's IP address.
Definition: arp.h:131
IPv4Address ipaddress_type
Definition: arp.h:60
hwaddress_type target_hw_addr() const
Getter for the target's hardware address.
Definition: arp.h:140
Base class for protocol data units.
Definition: pdu.h:107
PDUType pdu_type() const
Getter for the PDU's type.
Definition: arp.h:274