libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | List of all members
Tins::TCPIP::Stream Class Reference

Represents a TCP stream. More...

#include <stream.h>

Public Types

typedef Flow::payload_type payload_type
 
typedef std::chrono::microseconds timestamp_type
 
typedef std::function< void(Stream &)> stream_callback_type
 
typedef std::function< void(Stream
&, uint32_t, const
payload_type &)> 
stream_packet_callback_type
 
typedef HWAddress< 6 > hwaddress_type
 

Public Member Functions

 Stream (PDU &initial_packet, const timestamp_type &ts=timestamp_type())
 Constructs a TCP stream using the provided packet. More...
 
void process_packet (PDU &packet, const timestamp_type &ts)
 Processes this packet. More...
 
void process_packet (PDU &packet)
 Processes this packet. More...
 
Flowclient_flow ()
 
const Flowclient_flow () const
 
Flowserver_flow ()
 
const Flowserver_flow () const
 
bool is_finished () const
 Indicates whether this stream is finished. More...
 
bool is_v6 () const
 
IPv4Address client_addr_v4 () const
 Retrieves the client's IPv4 address. More...
 
IPv6Address client_addr_v6 () const
 Retrieves the client's IPv6 address. More...
 
const hwaddress_typeclient_hw_addr () const
 Retrieves the client's hardware address. More...
 
const hwaddress_typeserver_hw_addr () const
 Retrieves the server's hardware address. More...
 
IPv4Address server_addr_v4 () const
 Retrieves the server's IPv4 address. More...
 
IPv6Address server_addr_v6 () const
 Retrieves the server's IPv6 address. More...
 
uint16_t client_port () const
 
uint16_t server_port () const
 
const payload_typeclient_payload () const
 
payload_typeclient_payload ()
 
const payload_typeserver_payload () const
 
payload_typeserver_payload ()
 
const timestamp_typecreate_time () const
 
const timestamp_typelast_seen () const
 
void stream_closed_callback (const stream_callback_type &callback)
 Sets the callback to be executed when the stream is closed. More...
 
void client_data_callback (const stream_callback_type &callback)
 Sets the callback to be executed when there's client data. More...
 
void server_data_callback (const stream_callback_type &callback)
 Sets the callback to be executed when there's server data. More...
 
void client_out_of_order_callback (const stream_packet_callback_type &callback)
 Sets the callback to be executed when there's new buffered client data. More...
 
void server_out_of_order_callback (const stream_packet_callback_type &callback)
 Sets the callback to be executed when there's new buffered client data. More...
 
void ignore_client_data ()
 Indicates that the data packets sent by the client should be ignored. More...
 
void ignore_server_data ()
 Indicates that the data packets sent by the server should be ignored. More...
 
void setup_flows_callbacks ()
 Sets the internal callbacks. More...
 
void auto_cleanup_payloads (bool value)
 Indicates whether each flow's payloads should be automatically erased. More...
 
void auto_cleanup_client_data (bool value)
 Indicates whether the client flow's payloads should be automatically erased. More...
 
void auto_cleanup_server_data (bool value)
 Indicates whether the server flow's payloads should be automatically erased. More...
 
void enable_ack_tracking ()
 
bool ack_tracking_enabled () const
 Indicates whether ACK number tracking is enabled for this stream.
 

Detailed Description

Represents a TCP stream.

A TCP stream is made out of 2 Flows, one in each direction, plus some other attributes and callbacks.

This class works using callbacks. Whenever the stream is created, you should set at least the client/server callbacks so you are notified whenever the client/server has sent data. Note that setting these is not mandatory, so you can subscribe to just the callbacks you need.

See Also
Stream::auto_cleanup_payloads

Member Typedef Documentation

The type used to store hardware addresses

The type used to store payloads

typedef std::function<void(Stream&)> Tins::TCPIP::Stream::stream_callback_type

The type used for callbacks

typedef std::function<void(Stream&, uint32_t, const payload_type&)> Tins::TCPIP::Stream::stream_packet_callback_type

The type used for packet-triggered callbacks

/sa Flow::buffering_callback

typedef std::chrono::microseconds Tins::TCPIP::Stream::timestamp_type

The type used to represent timestamps

Constructor & Destructor Documentation

Tins::TCPIP::Stream::Stream ( PDU initial_packet,
const timestamp_type ts = timestamp_type() 
)

Constructs a TCP stream using the provided packet.

Parameters
initial_packetThe first packet of the stream
tsThe first packet's timestamp

Member Function Documentation

void Tins::TCPIP::Stream::auto_cleanup_client_data ( bool  value)

Indicates whether the client flow's payloads should be automatically erased.

See Also
auto_cleanup_payloads
void Tins::TCPIP::Stream::auto_cleanup_payloads ( bool  value)

Indicates whether each flow's payloads should be automatically erased.

If this property is true, then whenever there's new data for a stream, the appropriate callback will be executed and then the payload will be erased.

If this property is false, then the payload will not be erased and the user is responsible for clearing the payload vector.

Setting this property to false is useful if it's desired to hold all of the data sent on the stream before processing it. Note that this can lead to the memory growing a lot.

This property is true by default.

Parameters
valueThe value to be set for this property
void Tins::TCPIP::Stream::auto_cleanup_server_data ( bool  value)

Indicates whether the server flow's payloads should be automatically erased.

See Also
auto_cleanup_payloads
IPv4Address Tins::TCPIP::Stream::client_addr_v4 ( ) const

Retrieves the client's IPv4 address.

Note that it's only valid to call this method if is_v6() == false

IPv6Address Tins::TCPIP::Stream::client_addr_v6 ( ) const

Retrieves the client's IPv6 address.

Note that it's only valid to call this method if is_v6() == true

void Tins::TCPIP::Stream::client_data_callback ( const stream_callback_type callback)

Sets the callback to be executed when there's client data.

See Also
Flow::data_callback
Parameters
callbackThe callback to be set
Flow & Tins::TCPIP::Stream::client_flow ( )

Getter for the client flow

const Flow & Tins::TCPIP::Stream::client_flow ( ) const

Getter for the client flow (const)

const Stream::hwaddress_type & Tins::TCPIP::Stream::client_hw_addr ( ) const

Retrieves the client's hardware address.

Note that this is not the actual hardware address of the client, but just the address seen from packets coming from it. If the client is on another network, then this will be the address of the last device (switch, route, etc) the packet went through.

void Tins::TCPIP::Stream::client_out_of_order_callback ( const stream_packet_callback_type callback)

Sets the callback to be executed when there's new buffered client data.

See Also
Flow::buffering_callback
Parameters
callbackThe callback to be set
const Stream::payload_type & Tins::TCPIP::Stream::client_payload ( ) const

Getter for the client's payload (const)

Stream::payload_type & Tins::TCPIP::Stream::client_payload ( )

Getter for the client's payload

uint16_t Tins::TCPIP::Stream::client_port ( ) const

Getter for the client's port

const Stream::timestamp_type & Tins::TCPIP::Stream::create_time ( ) const

Getter for the creation time of this stream

void Tins::TCPIP::Stream::enable_ack_tracking ( )

Enables tracking of acknowledged segments

See Also
Flow::enable_ack_tracking
void Tins::TCPIP::Stream::ignore_client_data ( )

Indicates that the data packets sent by the client should be ignored.

See Also
Flow::ignore_data_packets
void Tins::TCPIP::Stream::ignore_server_data ( )

Indicates that the data packets sent by the server should be ignored.

See Also
Flow::ignore_data_packets
bool Tins::TCPIP::Stream::is_finished ( ) const

Indicates whether this stream is finished.

This stream is finished if either peer sent a packet with the RST flag on, or both peers sent a FIN.

bool Tins::TCPIP::Stream::is_v6 ( ) const

Indicates whether this packet uses IPv6 addresses

const Stream::timestamp_type & Tins::TCPIP::Stream::last_seen ( ) const

Getter for the last seen time of this stream

void Tins::TCPIP::Stream::process_packet ( PDU packet,
const timestamp_type ts 
)

Processes this packet.

This will forward the packet appropriately to the client or server flow.

Parameters
packetThe packet to be processed
tsThe packet's timestamp
void Tins::TCPIP::Stream::process_packet ( PDU packet)

Processes this packet.

This will forward the packet appropriately to the client or server flow.

Parameters
packetThe packet to be processed
IPv4Address Tins::TCPIP::Stream::server_addr_v4 ( ) const

Retrieves the server's IPv4 address.

Note that it's only valid to call this method if is_v6() == false

IPv6Address Tins::TCPIP::Stream::server_addr_v6 ( ) const

Retrieves the server's IPv6 address.

Note that it's only valid to call this method if is_v6() == true

void Tins::TCPIP::Stream::server_data_callback ( const stream_callback_type callback)

Sets the callback to be executed when there's server data.

See Also
Flow::data_callback
Parameters
callbackThe callback to be set
Flow & Tins::TCPIP::Stream::server_flow ( )

Getter for the server flow

const Flow & Tins::TCPIP::Stream::server_flow ( ) const

Getter for the server flow (const)

const Stream::hwaddress_type & Tins::TCPIP::Stream::server_hw_addr ( ) const

Retrieves the server's hardware address.

Note that this is not the actual hardware address of the server, but just the address seen from packets coming from it. If the server is on another network, then this will be the address of the last device (switch, route, etc) the packet went through.

void Tins::TCPIP::Stream::server_out_of_order_callback ( const stream_packet_callback_type callback)

Sets the callback to be executed when there's new buffered client data.

See Also
Flow::buffering_callback
Parameters
callbackThe callback to be set
const Stream::payload_type & Tins::TCPIP::Stream::server_payload ( ) const

Getter for the server's payload (const)

Stream::payload_type & Tins::TCPIP::Stream::server_payload ( )

Getter for the server's payload

uint16_t Tins::TCPIP::Stream::server_port ( ) const

Getter for the server's port

void Tins::TCPIP::Stream::setup_flows_callbacks ( )

Sets the internal callbacks.

This shouldn't normally need to be called except if you're constructing this object and then moving it around before persisting it somewhere.

void Tins::TCPIP::Stream::stream_closed_callback ( const stream_callback_type callback)

Sets the callback to be executed when the stream is closed.

Parameters
callbackThe callback to be set

The documentation for this class was generated from the following files: