Sponge
CS144's user-space TCP library
ipv4_header.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_IPV4_HEADER_HH
2 #define SPONGE_LIBSPONGE_IPV4_HEADER_HH
3 
4 #include "parser.hh"
5 
8 struct IPv4Header {
9  static constexpr size_t LENGTH = 20;
10  static constexpr uint8_t DEFAULT_TTL = 128;
11  static constexpr uint8_t PROTO_TCP = 6;
12 
31 
34  uint8_t ver = 4;
35  uint8_t hlen = LENGTH / 4;
36  uint8_t tos = 0;
37  uint16_t len = 0;
38  uint16_t id = 0;
39  bool df = true;
40  bool mf = false;
41  uint16_t offset = 0;
42  uint8_t ttl = DEFAULT_TTL;
43  uint8_t proto = PROTO_TCP;
44  uint16_t cksum = 0;
45  uint32_t src = 0;
46  uint32_t dst = 0;
47 
51 
53  std::string serialize() const;
54 
56  uint16_t payload_length() const;
57 
59  uint32_t pseudo_cksum() const;
60 
62  std::string to_string() const;
63 
65  std::string summary() const;
66 };
67 
70 
71 #endif // SPONGE_LIBSPONGE_IPV4_HEADER_HH
IPv4Header::LENGTH
static constexpr size_t LENGTH
IPv4 header length, not including options
Definition: ipv4_header.hh:9
std::string
IPv4Header::summary
std::string summary() const
Return a string containing a human-readable summary of the header.
Definition: ipv4_header.cc:151
IPv4Header::src
uint32_t src
src address
Definition: ipv4_header.hh:45
IPv4Header::ver
uint8_t ver
IP version.
Definition: ipv4_header.hh:34
IPv4Header::cksum
uint16_t cksum
checksum field
Definition: ipv4_header.hh:44
IPv4Header::ttl
uint8_t ttl
time to live field
Definition: ipv4_header.hh:42
IPv4Header::dst
uint32_t dst
Definition: ipv4_header.hh:46
IPv4Header::to_string
std::string to_string() const
Return a string containing a header in human-readable format.
Definition: ipv4_header.cc:134
IPv4Header::PROTO_TCP
static constexpr uint8_t PROTO_TCP
Protocol number for tcp.
Definition: ipv4_header.hh:11
ParseResult
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
Definition: parser.hh:12
IPv4Header::offset
uint16_t offset
fragment offset field
Definition: ipv4_header.hh:41
IPv4Header::serialize
std::string serialize() const
Serialize the IP fields.
Definition: ipv4_header.cc:78
IPv4Header::pseudo_cksum
uint32_t pseudo_cksum() const
pseudo-header's contribution to the TCP checksum
Definition: ipv4_header.cc:125
IPv4Header::mf
bool mf
more fragments flag
Definition: ipv4_header.hh:40
IPv4Header::hlen
uint8_t hlen
header length (multiples of 32 bits)
Definition: ipv4_header.hh:35
NetParser
Definition: parser.hh:25
IPv4Header
IPv4 Internet datagram header
Definition: ipv4_header.hh:8
IPv4Header::parse
ParseResult parse(NetParser &p)
Parse the IP fields from the provided NetParser.
Definition: ipv4_header.cc:23
IPv4Header::len
uint16_t len
total length of packet
Definition: ipv4_header.hh:37
IPv4Header::tos
uint8_t tos
type of service
Definition: ipv4_header.hh:36
IPv4Header::proto
uint8_t proto
protocol field
Definition: ipv4_header.hh:43
IPv4Header::df
bool df
don't fragment flag
Definition: ipv4_header.hh:39
IPv4Header::payload_length
uint16_t payload_length() const
Length of the payload.
Definition: ipv4_header.cc:112
parser.hh
IPv4Header::DEFAULT_TTL
static constexpr uint8_t DEFAULT_TTL
A reasonable default TTL value.
Definition: ipv4_header.hh:10