37 #include <tins/macros.h> 38 #include <tins/endianness.h> 39 #include <tins/small_uint.h> 40 #include <tins/pdu_option.h> 41 #include <tins/cxxstd.h> 45 class OutputMemoryStream;
113 RFC_EXPERIMENT_1 = 253,
114 RFC_EXPERIMENT_2 = 254
147 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
158 TCP(uint16_t dport = 0, uint16_t sport = 0);
172 TCP(
const uint8_t* buffer, uint32_t total_sz);
180 return Endian::be_to_host(header_.dport);
189 return Endian::be_to_host(header_.sport);
198 return Endian::be_to_host(header_.seq);
207 return Endian::be_to_host(header_.ack_seq);
216 return Endian::be_to_host(header_.window);
225 return Endian::be_to_host(header_.check);
234 return Endian::be_to_host(header_.urg_ptr);
243 return this->header_.doff;
306 void dport(uint16_t new_dport);
313 void sport(uint16_t new_sport);
320 void seq(uint32_t new_seq);
327 void ack_seq(uint32_t new_ack_seq);
334 void window(uint16_t new_window);
341 void urg_ptr(uint16_t new_urg_ptr);
357 void mss(uint16_t value);
364 uint16_t mss()
const;
371 void winscale(uint8_t value);
378 uint8_t winscale()
const;
383 void sack_permitted();
389 bool has_sack_permitted()
const;
396 void sack(
const sack_type& edges);
403 sack_type sack()
const;
411 void timestamp(uint32_t value, uint32_t reply);
419 std::pair<uint32_t, uint32_t> timestamp()
const;
469 void add_option(
const option& opt);
480 options_.push_back(std::move(opt));
491 template <
typename... Args>
493 options_.emplace_back(std::forward<Args>(args)...);
516 uint32_t header_size()
const;
525 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
541 const option* search_option(
OptionTypes type)
const;
547 return new TCP(*
this);
550 #if TINS_IS_LITTLE_ENDIAN 582 #if TINS_IS_LITTLE_ENDIAN 598 static const uint16_t DEFAULT_WINDOW;
600 template <
typename T>
602 const option* opt = search_option(opt_type);
609 void write_serialization(uint8_t* buffer, uint32_t total_sz);
610 void checksum(uint16_t new_check);
611 uint32_t calculate_options_size()
const;
612 uint32_t pad_options_size(uint32_t size)
const;
613 options_type::const_iterator search_option_iterator(
OptionTypes type)
const;
614 options_type::iterator search_option_iterator(
OptionTypes type);
616 void write_option(
const option& opt, Memory::OutputMemoryStream& stream);
618 options_type options_;
uint16_t sport() const
Getter for the source port field.
Definition: tcp.h:188
Represents a TCP PDU.
Definition: tcp.h:76
OptionTypes
TCP options enum.
Definition: tcp.h:104
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
uint32_t seq() const
Getter for the sequence number field.
Definition: tcp.h:197
small_uint< 4 > data_offset() const
Getter for the data offset field.
Definition: tcp.h:242
uint16_t checksum() const
Getter for the checksum field.
Definition: tcp.h:224
std::vector< option > options_type
Definition: tcp.h:134
Represents a PDU option field.
Definition: pdu_option.h:201
void add_option(option &&opt)
Adds a TCP option.
Definition: tcp.h:479
PDUOption< uint8_t, TCP > option
Definition: tcp.h:129
TCP * clone() const
Definition: tcp.h:546
std::vector< uint32_t > sack_type
Definition: tcp.h:139
void add_option(Args &&...args)
Adds a TCP option using the provided arguments.
Definition: tcp.h:492
The Tins namespace.
Definition: address_range.h:38
T to() const
Constructs a T from this PDUOption.
Definition: pdu_option.h:389
uint32_t ack_seq() const
Getter for the acknowledge number field.
Definition: tcp.h:206
uint16_t urg_ptr() const
Getter for the urgent pointer field.
Definition: tcp.h:233
Flags
TCP flags enum.
Definition: tcp.h:88
uint16_t dport() const
Getter for the destination port field.
Definition: tcp.h:179
const options_type & options() const
Getter for the option list.
Definition: tcp.h:251
uint16_t window() const
Getter for the window size field.
Definition: tcp.h:215
AltChecksums
Alternate checksum enum.
Definition: tcp.h:120
Base class for protocol data units.
Definition: pdu.h:107
Exception thrown when an option is not found.
Definition: exceptions.h:56
PDUType pdu_type() const
Getter for the PDU's type.
Definition: tcp.h:532