libtins
4.0
|
Represents a TCP PDU. More...
#include <tcp.h>
Public Types | |
enum | Flags { FIN = 1, SYN = 2, RST = 4, PSH = 8, ACK = 16, URG = 32, ECE = 64, CWR = 128 } |
TCP flags enum. More... | |
enum | OptionTypes { EOL = 0, NOP = 1, MSS = 2, WSCALE = 3, SACK_OK = 4, SACK = 5, TSOPT = 8, ALTCHK = 14, RFC_EXPERIMENT_1 = 253, RFC_EXPERIMENT_2 = 254 } |
TCP options enum. More... | |
enum | AltChecksums { CHK_TCP, CHK_8FLETCHER, CHK_16FLETCHER } |
Alternate checksum enum. | |
typedef PDUOption< uint8_t, TCP > | option |
typedef std::vector< option > | options_type |
typedef std::vector< uint32_t > | sack_type |
Public Types inherited from Tins::PDU | |
enum | endian_type { BE, LE } |
enum | PDUType { RAW, ETHERNET_II, IEEE802_3, DOT3 = IEEE802_3, RADIOTAP, DOT11, DOT11_ACK, DOT11_ASSOC_REQ, DOT11_ASSOC_RESP, DOT11_AUTH, DOT11_BEACON, DOT11_BLOCK_ACK, DOT11_BLOCK_ACK_REQ, DOT11_CF_END, DOT11_DATA, DOT11_CONTROL, DOT11_DEAUTH, DOT11_DIASSOC, DOT11_END_CF_ACK, DOT11_MANAGEMENT, DOT11_PROBE_REQ, DOT11_PROBE_RESP, DOT11_PS_POLL, DOT11_REASSOC_REQ, DOT11_REASSOC_RESP, DOT11_RTS, DOT11_QOS_DATA, LLC, SNAP, IP, ARP, TCP, UDP, ICMP, BOOTP, DHCP, EAPOL, RC4EAPOL, RSNEAPOL, DNS, LOOPBACK, IPv6, ICMPv6, SLL, DHCPv6, DOT1Q, PPPOE, STP, PPI, IPSEC_AH, IPSEC_ESP, PKTAP, MPLS, UNKNOWN = 999, USER_DEFINED_PDU = 1000 } |
Enum which identifies each type of PDU. More... | |
typedef byte_array | serialization_type |
Public Member Functions | |
TCP (uint16_t dport=0, uint16_t sport=0) | |
TCP constructor. More... | |
TCP (const uint8_t *buffer, uint32_t total_sz) | |
Constructs TCP object from a buffer. More... | |
uint16_t | dport () const |
Getter for the destination port field. More... | |
uint16_t | sport () const |
Getter for the source port field. More... | |
uint32_t | seq () const |
Getter for the sequence number field. More... | |
uint32_t | ack_seq () const |
Getter for the acknowledge number field. More... | |
uint16_t | window () const |
Getter for the window size field. More... | |
uint16_t | checksum () const |
Getter for the checksum field. More... | |
uint16_t | urg_ptr () const |
Getter for the urgent pointer field. More... | |
small_uint< 4 > | data_offset () const |
Getter for the data offset field. More... | |
const options_type & | options () const |
Getter for the option list. More... | |
small_uint< 1 > | get_flag (Flags tcp_flag) const |
Gets the value of a flag. More... | |
small_uint< 12 > | flags () const |
Gets the flags' values. More... | |
void | dport (uint16_t new_dport) |
Setter for the destination port field. More... | |
void | sport (uint16_t new_sport) |
Setter for the source port field. More... | |
void | seq (uint32_t new_seq) |
Setter for the sequence number. More... | |
void | ack_seq (uint32_t new_ack_seq) |
Setter for the acknowledge number. More... | |
void | window (uint16_t new_window) |
Setter for the window size. More... | |
void | urg_ptr (uint16_t new_urg_ptr) |
Setter for the urgent pointer field. More... | |
void | data_offset (small_uint< 4 > new_doff) |
Setter for the data offset pointer field. More... | |
void | mss (uint16_t value) |
Add a maximum segment size option. More... | |
uint16_t | mss () const |
Searchs for a maximum segment size option. More... | |
void | winscale (uint8_t value) |
Add a window scale option. More... | |
uint8_t | winscale () const |
Searchs for a window scale option. More... | |
void | sack_permitted () |
Add a sack permitted option. | |
bool | has_sack_permitted () const |
Searchs for a sack permitted option. More... | |
void | sack (const sack_type &edges) |
Add a sack option. More... | |
sack_type | sack () const |
Searchs for a sack option. More... | |
void | timestamp (uint32_t value, uint32_t reply) |
Add a timestamp option. More... | |
std::pair< uint32_t, uint32_t > | timestamp () const |
Searchs for a timestamp option. More... | |
void | altchecksum (AltChecksums value) |
Add a alternate checksum option. More... | |
AltChecksums | altchecksum () const |
Searchs for a alternate checksum option. More... | |
void | set_flag (Flags tcp_flag, small_uint< 1 > value) |
Set a TCP flag value. More... | |
void | flags (small_uint< 12 > value) |
Sets the value of the flag fields. More... | |
void | add_option (const option &opt) |
Adds a TCP option. More... | |
void | add_option (option &&opt) |
Adds a TCP option. More... | |
template<typename... Args> | |
void | add_option (Args &&...args) |
Adds a TCP option using the provided arguments. More... | |
bool | remove_option (OptionTypes type) |
Removes a TCP option. More... | |
uint32_t | header_size () const |
Returns the header size. More... | |
bool | matches_response (const uint8_t *ptr, uint32_t total_sz) const |
Check whether ptr points to a valid response for this PDU. More... | |
PDUType | pdu_type () const |
Getter for the PDU's type. More... | |
const option * | search_option (OptionTypes type) const |
Searchs for an option that matchs the given type. More... | |
TCP * | clone () const |
Public Member Functions inherited from Tins::PDU | |
PDU () | |
Default constructor. | |
PDU (PDU &&rhs) TINS_NOEXCEPT | |
Move constructor. More... | |
PDU & | operator= (PDU &&rhs) TINS_NOEXCEPT |
Move assignment operator. More... | |
virtual | ~PDU () |
PDU destructor. More... | |
virtual uint32_t | trailer_size () const |
Trailer's size. More... | |
uint32_t | size () const |
The whole chain of PDU's size, including this one. More... | |
PDU * | inner_pdu () const |
Getter for the inner PDU. More... | |
PDU * | parent_pdu () const |
PDU * | release_inner_pdu () |
Releases the inner PDU. More... | |
void | inner_pdu (PDU *next_pdu) |
Sets the child PDU. More... | |
void | inner_pdu (const PDU &next_pdu) |
Sets the child PDU. More... | |
serialization_type | serialize () |
Serializes the whole chain of PDU's, including this one. More... | |
template<typename T > | |
T * | find_pdu (PDUType type=T::pdu_flag) |
Finds and returns the first PDU that matches the given flag. More... | |
template<typename T > | |
const T * | find_pdu (PDUType type=T::pdu_flag) const |
Finds and returns the first PDU that matches the given flag. More... | |
template<typename T > | |
T & | rfind_pdu (PDUType type=T::pdu_flag) |
Finds and returns the first PDU that matches the given flag. More... | |
template<typename T > | |
const T & | rfind_pdu (PDUType type=T::pdu_flag) const |
Finds and returns the first PDU that matches the given flag. More... | |
virtual void | send (PacketSender &sender, const NetworkInterface &iface) |
Send the stack of PDUs through a PacketSender. More... | |
virtual PDU * | recv_response (PacketSender &sender, const NetworkInterface &iface) |
Receives a matching response for this packet. More... | |
virtual bool | matches_flag (PDUType flag) const |
Check whether this PDU matches the specified flag. More... | |
Static Public Member Functions | |
static metadata | extract_metadata (const uint8_t *buffer, uint32_t total_sz) |
Extracts metadata for this protocol based on the buffer provided. More... | |
Static Public Attributes | |
static const PDU::PDUType | pdu_flag = PDU::TCP |
Static Public Attributes inherited from Tins::PDU | |
static const endian_type | endianness = BE |
Additional Inherited Members | |
Protected Member Functions inherited from Tins::PDU | |
PDU (const PDU &other) | |
Copy constructor. | |
PDU & | operator= (const PDU &other) |
Copy assignment operator. | |
void | copy_inner_pdu (const PDU &pdu) |
Copy other PDU's inner PDU(if any). More... | |
virtual void | prepare_for_serialize () |
Prepares this PDU for serialization. More... | |
void | serialize (uint8_t *buffer, uint32_t total_sz) |
Serializes this PDU and propagates this action to child PDUs. More... | |
Represents a TCP PDU.
This class represents a TCP PDU.
When sending TCP PDUs, the checksum is calculated automatically every time you send the packet.
While sniffing, the payload sent in each packet will be wrapped in a RawPDU, which is set as the TCP object's inner_pdu. Therefore, if you are sniffing and want to see the TCP packet's payload, you need to do the following:
typedef PDUOption<uint8_t, TCP> Tins::TCP::option |
The type used to store TCP options.
typedef std::vector<option> Tins::TCP::options_type |
The type used to store the options.
typedef std::vector<uint32_t> Tins::TCP::sack_type |
The type used to store the sack option.
enum Tins::TCP::Flags |
Tins::TCP::TCP | ( | uint16_t | dport = 0 , |
uint16_t | sport = 0 |
||
) |
Tins::TCP::TCP | ( | const uint8_t * | buffer, |
uint32_t | total_sz | ||
) |
Constructs TCP object from a buffer.
If there is not enough size for a TCP header, or any of the TLV options are malformed, a malformed_packet exception is thrown.
Any extra data will be stored in a RawPDU.
buffer | The buffer from which this PDU will be constructed. |
total_sz | The total size of the buffer. |
|
inline |
Getter for the acknowledge number field.
void Tins::TCP::ack_seq | ( | uint32_t | new_ack_seq | ) |
Setter for the acknowledge number.
new_ack_seq | The new acknowledge number. |
void Tins::TCP::add_option | ( | const option & | opt | ) |
Adds a TCP option.
option | The option to be added. |
|
inline |
|
inline |
Adds a TCP option using the provided arguments.
The option is constructed from the provided parameters.
args | The arguments to be used in the option's constructor. |
void Tins::TCP::altchecksum | ( | AltChecksums | value | ) |
Add a alternate checksum option.
value | The new alternate checksum scale. |
TCP::AltChecksums Tins::TCP::altchecksum | ( | ) | const |
Searchs for a alternate checksum option.
value | A pointer in which the option's value will be stored. |
|
inline |
Getter for the checksum field.
|
inlinevirtual |
Implements Tins::PDU.
|
inline |
Getter for the data offset field.
void Tins::TCP::data_offset | ( | small_uint< 4 > | new_doff | ) |
Setter for the data offset pointer field.
new_doff | The new data offset pointer. |
|
inline |
Getter for the destination port field.
void Tins::TCP::dport | ( | uint16_t | new_dport | ) |
Setter for the destination port field.
new_dport | The new destination port. |
|
static |
Extracts metadata for this protocol based on the buffer provided.
buffer | Pointer to a buffer |
total_sz | Size of the buffer pointed by buffer |
small_uint< 12 > Tins::TCP::flags | ( | ) | const |
Gets the flags' values.
All of the set flags will be joined together into a 12 bit value. This way, you can check for multiple flags at the same time:
void Tins::TCP::flags | ( | small_uint< 12 > | value | ) |
Sets the value of the flag fields.
This method can be used to set several flags at the same time.
value | The new value of the flags. |
small_uint< 1 > Tins::TCP::get_flag | ( | Flags | tcp_flag | ) | const |
Gets the value of a flag.
This method gets the value of a specific flag. If you want to check for multiple flags at the same time, use TCP::flags.
If you want to check if this PDU has the SYN flag on, you can do it like this:
tcp_flag | The polled flag. |
bool Tins::TCP::has_sack_permitted | ( | ) | const |
Searchs for a sack permitted option.
|
virtual |
Returns the header size.
This method overrides PDU::header_size. This size includes the payload and options size.
Implements Tins::PDU.
|
virtual |
Check whether ptr points to a valid response for this PDU.
ptr | The pointer to the buffer. |
total_sz | The size of the buffer. |
Reimplemented from Tins::PDU.
void Tins::TCP::mss | ( | uint16_t | value | ) |
Add a maximum segment size option.
value | The new maximum segment size. |
uint16_t Tins::TCP::mss | ( | ) | const |
Searchs for a maximum segment size option.
value | A pointer in which the option's value will be stored. |
|
inline |
Getter for the option list.
|
inlinevirtual |
bool Tins::TCP::remove_option | ( | OptionTypes | type | ) |
Removes a TCP option.
If there are multiple options of the given type, only the first one will be removed.
type | The type of the option to be removed. |
void Tins::TCP::sack | ( | const sack_type & | edges | ) |
Add a sack option.
value | The new window scale. |
TCP::sack_type Tins::TCP::sack | ( | ) | const |
Searchs for a sack option.
value | A pointer in which the option's value will be stored. |
const TCP::option * Tins::TCP::search_option | ( | OptionTypes | type | ) | const |
Searchs for an option that matchs the given type.
type | The option type to be searched. |
|
inline |
Getter for the sequence number field.
void Tins::TCP::seq | ( | uint32_t | new_seq | ) |
Setter for the sequence number.
new_seq | The new sequence number. |
void Tins::TCP::set_flag | ( | Flags | tcp_flag, |
small_uint< 1 > | value | ||
) |
Set a TCP flag value.
tcp_flag | The flag to be set. |
value | The new value for this flag. Must be 0 or 1. |
|
inline |
Getter for the source port field.
void Tins::TCP::sport | ( | uint16_t | new_sport | ) |
Setter for the source port field.
new_sport | The new source port. |
void Tins::TCP::timestamp | ( | uint32_t | value, |
uint32_t | reply | ||
) |
Add a timestamp option.
value | The current value of the timestamp clock. |
reply | The echo reply field. |
pair< uint32_t, uint32_t > Tins::TCP::timestamp | ( | ) | const |
Searchs for a timestamp option.
value | A pointer in which the option's value will be stored. |
reply | A pointer in which the option's reply value will be stored. |
|
inline |
Getter for the urgent pointer field.
void Tins::TCP::urg_ptr | ( | uint16_t | new_urg_ptr | ) |
Setter for the urgent pointer field.
new_urg_ptr | The new urgent pointer. |
|
inline |
Getter for the window size field.
void Tins::TCP::window | ( | uint16_t | new_window | ) |
Setter for the window size.
new_window | The new window size. |
void Tins::TCP::winscale | ( | uint8_t | value | ) |
Add a window scale option.
value | The new window scale. |
uint8_t Tins::TCP::winscale | ( | ) | const |
Searchs for a window scale option.
value | A pointer in which the option's value will be stored. |
|
static |
This PDU's flag.