Sponge
CS144's user-space TCP library
tcp_header.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_TCP_HEADER_HH
2 #define SPONGE_LIBSPONGE_TCP_HEADER_HH
3 
4 #include "parser.hh"
5 #include "wrapping_integers.hh"
6 
9 struct TCPHeader {
10  static constexpr size_t LENGTH = 20;
11 
34 
37  uint16_t sport = 0;
38  uint16_t dport = 0;
41  uint8_t doff = LENGTH / 4;
42  bool urg = false;
43  bool ack = false;
44  bool psh = false;
45  bool rst = false;
46  bool syn = false;
47  bool fin = false;
48  uint16_t win = 0;
49  uint16_t cksum = 0;
50  uint16_t uptr = 0;
51 
55 
57  std::string serialize() const;
58 
60  std::string to_string() const;
61 
63  std::string summary() const;
64 
65  bool operator==(const TCPHeader &other) const;
66 };
67 
68 #endif // SPONGE_LIBSPONGE_TCP_HEADER_HH
TCPHeader::operator==
bool operator==(const TCPHeader &other) const
Definition: tcp_header.cc:103
std::string
TCPHeader::win
uint16_t win
window size
Definition: tcp_header.hh:48
TCPHeader::LENGTH
static constexpr size_t LENGTH
TCP header length, not including options
Definition: tcp_header.hh:10
TCPHeader::summary
std::string summary() const
Return a string containing a human-readable summary of the header.
Definition: tcp_header.cc:96
WrappingInt32
A 32-bit integer, expressed relative to an arbitrary initial sequence number (ISN)
Definition: wrapping_integers.hh:9
TCPHeader::rst
bool rst
rst flag
Definition: tcp_header.hh:45
TCPHeader::serialize
std::string serialize() const
Serialize the TCP fields.
Definition: tcp_header.cc:51
TCPHeader::uptr
uint16_t uptr
Definition: tcp_header.hh:50
TCPHeader::dport
uint16_t dport
destination port
Definition: tcp_header.hh:38
TCPHeader::syn
bool syn
syn flag
Definition: tcp_header.hh:46
TCPHeader::ack
bool ack
ack flag
Definition: tcp_header.hh:43
TCPHeader::fin
bool fin
fin flag
Definition: tcp_header.hh:47
wrapping_integers.hh
ParseResult
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
Definition: parser.hh:12
TCPHeader::cksum
uint16_t cksum
checksum
Definition: tcp_header.hh:49
TCPHeader::psh
bool psh
push flag
Definition: tcp_header.hh:44
TCPHeader::sport
uint16_t sport
source port
Definition: tcp_header.hh:37
TCPHeader::to_string
std::string to_string() const
Return a string containing a header in human-readable format.
Definition: tcp_header.cc:81
TCPHeader::doff
uint8_t doff
data offset
Definition: tcp_header.hh:41
NetParser
Definition: parser.hh:25
TCPHeader::seqno
WrappingInt32 seqno
sequence number
Definition: tcp_header.hh:39
TCPHeader::urg
bool urg
urgent flag
Definition: tcp_header.hh:42
TCPHeader::ackno
WrappingInt32 ackno
ack number
Definition: tcp_header.hh:40
TCPHeader
TCP segment header
Definition: tcp_header.hh:9
TCPHeader::parse
ParseResult parse(NetParser &p)
Parse the TCP fields from the provided NetParser.
Definition: tcp_header.cc:17
parser.hh