Sponge
CS144's user-space TCP library
ethernet_header.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_ETHERNET_HEADER_HH
2 #define SPONGE_LIBSPONGE_ETHERNET_HEADER_HH
3 
4 #include "parser.hh"
5 
6 #include <array>
7 
10 
12 constexpr EthernetAddress ETHERNET_BROADCAST = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
13 
16 
19  static constexpr size_t LENGTH = 14;
20  static constexpr uint16_t TYPE_IPv4 = 0x800;
21  static constexpr uint16_t TYPE_ARP = 0x806;
22 
27  uint16_t type;
29 
32 
34  std::string serialize() const;
35 
37  std::string to_string() const;
38 };
39 
42 
43 #endif // SPONGE_LIBSPONGE_ETHERNET_HEADER_HH
EthernetHeader::src
EthernetAddress src
Definition: ethernet_header.hh:26
EthernetHeader::parse
ParseResult parse(NetParser &p)
Parse the Ethernet fields from the provided NetParser.
Definition: ethernet_header.cc:10
std::string
EthernetHeader::dst
EthernetAddress dst
Definition: ethernet_header.hh:25
ETHERNET_BROADCAST
constexpr EthernetAddress ETHERNET_BROADCAST
Ethernet broadcast address (ff:ff:ff:ff:ff:ff)
Definition: ethernet_header.hh:12
EthernetHeader::serialize
std::string serialize() const
Serialize the Ethernet fields to a string.
Definition: ethernet_header.cc:31
EthernetHeader::to_string
std::string to_string() const
Return a string containing a header in human-readable format.
Definition: ethernet_header.cc:65
EthernetHeader
Ethernet frame header.
Definition: ethernet_header.hh:18
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
to_string
std::string to_string(const EthernetAddress address)
Printable representation of an EthernetAddress.
Definition: ethernet_header.cc:52
NetParser
Definition: parser.hh:25
EthernetHeader::LENGTH
static constexpr size_t LENGTH
Ethernet header length in bytes.
Definition: ethernet_header.hh:19
EthernetHeader::type
uint16_t type
Definition: ethernet_header.hh:27
EthernetHeader::TYPE_ARP
static constexpr uint16_t TYPE_ARP
Type number for ARP.
Definition: ethernet_header.hh:21
parser.hh