Sponge
CS144's user-space TCP library
|
IPv4 Internet datagram header More...
#include <ipv4_header.hh>
Public Member Functions | |
ParseResult | parse (NetParser &p) |
Parse the IP fields from the provided NetParser. More... | |
uint16_t | payload_length () const |
Length of the payload. More... | |
uint32_t | pseudo_cksum () const |
pseudo-header's contribution to the TCP checksum More... | |
std::string | serialize () const |
Serialize the IP fields. More... | |
std::string | summary () const |
Return a string containing a human-readable summary of the header. More... | |
std::string | to_string () const |
Return a string containing a header in human-readable format. More... | |
Public Attributes | |
IPv4 Header fields | |
uint8_t | ver = 4 |
IP version. More... | |
uint8_t | hlen = LENGTH / 4 |
header length (multiples of 32 bits) More... | |
uint8_t | tos = 0 |
type of service More... | |
uint16_t | len = 0 |
total length of packet More... | |
uint16_t | id = 0 |
identification number More... | |
bool | df = true |
don't fragment flag More... | |
bool | mf = false |
more fragments flag More... | |
uint16_t | offset = 0 |
fragment offset field More... | |
uint8_t | ttl = DEFAULT_TTL |
time to live field More... | |
uint8_t | proto = PROTO_TCP |
protocol field More... | |
uint16_t | cksum = 0 |
checksum field More... | |
uint32_t | src = 0 |
src address More... | |
uint32_t | dst = 0 |
Static Public Attributes | |
static constexpr uint8_t | DEFAULT_TTL = 128 |
A reasonable default TTL value. More... | |
static constexpr size_t | LENGTH = 20 |
IPv4 header length, not including options More... | |
static constexpr uint8_t | PROTO_TCP = 6 |
Protocol number for tcp. More... | |
IPv4 Internet datagram header
This struct can be used to parse an existing IP header or to create a new one.
Definition at line 8 of file ipv4_header.hh.
ParseResult IPv4Header::parse | ( | NetParser & | p | ) |
Parse the IP fields from the provided NetParser.
[in,out] | p | is a NetParser from which the IP fields will be extracted |
It is important to check for (at least) the following potential errors (but note that NetParser inherently checks for certain errors; use that fact to your advantage!):
hlen
field is shorter than the minimum alloweddoff
field claimslen
field claimsDefinition at line 23 of file ipv4_header.cc.
uint16_t IPv4Header::payload_length | ( | ) | const |
Length of the payload.
Definition at line 112 of file ipv4_header.cc.
uint32_t IPv4Header::pseudo_cksum | ( | ) | const |
pseudo-header's contribution to the TCP checksum
This value is needed when computing the checksum of an encapsulated TCP segment.
Definition at line 125 of file ipv4_header.cc.
string IPv4Header::serialize | ( | ) | const |
Serialize the IP fields.
Serialize the IPv4Header to a string (does not recompute the checksum)
Definition at line 78 of file ipv4_header.cc.
std::string IPv4Header::summary | ( | ) | const |
Return a string containing a human-readable summary of the header.
Definition at line 151 of file ipv4_header.cc.
std::string IPv4Header::to_string | ( | ) | const |
Return a string containing a header in human-readable format.
Definition at line 134 of file ipv4_header.cc.
uint16_t IPv4Header::cksum = 0 |
checksum field
Definition at line 44 of file ipv4_header.hh.
|
staticconstexpr |
A reasonable default TTL value.
Definition at line 10 of file ipv4_header.hh.
bool IPv4Header::df = true |
don't fragment flag
Definition at line 39 of file ipv4_header.hh.
uint32_t IPv4Header::dst = 0 |
dst address
Definition at line 46 of file ipv4_header.hh.
uint8_t IPv4Header::hlen = LENGTH / 4 |
header length (multiples of 32 bits)
Definition at line 35 of file ipv4_header.hh.
uint16_t IPv4Header::id = 0 |
identification number
Definition at line 38 of file ipv4_header.hh.
uint16_t IPv4Header::len = 0 |
total length of packet
Definition at line 37 of file ipv4_header.hh.
|
staticconstexpr |
IPv4 header length, not including options
Definition at line 9 of file ipv4_header.hh.
bool IPv4Header::mf = false |
more fragments flag
Definition at line 40 of file ipv4_header.hh.
uint16_t IPv4Header::offset = 0 |
fragment offset field
Definition at line 41 of file ipv4_header.hh.
uint8_t IPv4Header::proto = PROTO_TCP |
protocol field
Definition at line 43 of file ipv4_header.hh.
|
staticconstexpr |
Protocol number for tcp.
Definition at line 11 of file ipv4_header.hh.
uint32_t IPv4Header::src = 0 |
src address
Definition at line 45 of file ipv4_header.hh.
uint8_t IPv4Header::tos = 0 |
type of service
Definition at line 36 of file ipv4_header.hh.
uint8_t IPv4Header::ttl = DEFAULT_TTL |
time to live field
Definition at line 42 of file ipv4_header.hh.
uint8_t IPv4Header::ver = 4 |
IP version.
Definition at line 34 of file ipv4_header.hh.