Sponge
CS144's user-space TCP library
arp_message.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_ARP_MESSAGE_HH
2 #define SPONGE_LIBSPONGE_ARP_MESSAGE_HH
3 
4 #include "ethernet_header.hh"
5 #include "ipv4_header.hh"
6 
8 
10 struct ARPMessage {
11  static constexpr size_t LENGTH = 28;
12  static constexpr uint16_t TYPE_ETHERNET = 1;
13  static constexpr uint16_t OPCODE_REQUEST = 1;
14  static constexpr uint16_t OPCODE_REPLY = 2;
15 
22  uint16_t opcode{};
23 
25  uint32_t sender_ip_address{};
26 
28  uint32_t target_ip_address{};
30 
33 
35  std::string serialize() const;
36 
38  std::string to_string() const;
39 
41  bool supported() const;
42 };
43 
46 
47 #endif // SPONGE_LIBSPONGE_ETHERNET_HEADER_HH
ARPMessage::LENGTH
static constexpr size_t LENGTH
ARP message length in bytes.
Definition: arp_message.hh:11
EthernetHeader::src
EthernetAddress src
Definition: ethernet_header.hh:26
std::string
ARPMessage::opcode
uint16_t opcode
Request or reply.
Definition: arp_message.hh:22
ARPMessage::protocol_type
uint16_t protocol_type
Type of the Internet-layer protocol (generally IPv4)
Definition: arp_message.hh:19
ARPMessage::TYPE_ETHERNET
static constexpr uint16_t TYPE_ETHERNET
ARP type for Ethernet/Wi-Fi as link-layer protocol.
Definition: arp_message.hh:12
ipv4_header.hh
IPv4Header::src
uint32_t src
src address
Definition: ipv4_header.hh:45
ARPMessage::OPCODE_REPLY
static constexpr uint16_t OPCODE_REPLY
Definition: arp_message.hh:14
ARPMessage
ARP message
Definition: arp_message.hh:10
buffer
std::string buffer
Definition: parser_example.cc:7
ethernet_header.hh
ARPMessage::OPCODE_REQUEST
static constexpr uint16_t OPCODE_REQUEST
Definition: arp_message.hh:13
ARPMessage::target_ip_address
uint32_t target_ip_address
Definition: arp_message.hh:28
Buffer
A reference-counted read-only string that can discard bytes from the front.
Definition: buffer.hh:14
EthernetHeader::TYPE_IPv4
static constexpr uint16_t TYPE_IPv4
Type number for IPv4.
Definition: ethernet_header.hh:20
std::array
ParseResult
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
Definition: parser.hh:12
ARPMessage::serialize
std::string serialize() const
Serialize the ARP message to a string.
Definition: arp_message.cc:47
ARPMessage::supported
bool supported() const
Is this type of ARP message supported by the parser?
Definition: arp_message.cc:41
ARPMessage::hardware_type
uint16_t hardware_type
Type of the link-layer protocol (generally Ethernet/Wi-Fi)
Definition: arp_message.hh:18
ARPMessage::target_ethernet_address
EthernetAddress target_ethernet_address
Definition: arp_message.hh:27
ARPMessage::sender_ip_address
uint32_t sender_ip_address
Definition: arp_message.hh:25
ARPMessage::parse
ParseResult parse(const Buffer buffer)
Parse the ARP message from a string.
Definition: arp_message.cc:9
ARPMessage::hardware_address_size
uint8_t hardware_address_size
Definition: arp_message.hh:20
ARPMessage::protocol_address_size
uint8_t protocol_address_size
Definition: arp_message.hh:21
ARPMessage::sender_ethernet_address
EthernetAddress sender_ethernet_address
Definition: arp_message.hh:24
ARPMessage::to_string
std::string to_string() const
Return a string containing the ARP message in human-readable format.
Definition: arp_message.cc:75