PcapPlusPlus
pcpp::TcpReassembly Class Reference

#include <TcpReassembly.h>

Public Types

enum  ConnectionEndReason { TcpReassemblyConnectionClosedByFIN_RST, TcpReassemblyConnectionClosedManually }
 
typedef void(* OnTcpMessageReady) (int side, TcpStreamData tcpData, void *userCookie)
 
typedef void(* OnTcpConnectionStart) (ConnectionData connectionData, void *userCookie)
 
typedef void(* OnTcpConnectionEnd) (ConnectionData connectionData, ConnectionEndReason reason, void *userCookie)
 

Public Member Functions

 TcpReassembly (OnTcpMessageReady onMessageReadyCallback, void *userCookie=NULL, OnTcpConnectionStart onConnectionStartCallback=NULL, OnTcpConnectionEnd onConnectionEndCallback=NULL)
 
 ~TcpReassembly ()
 
void ReassemblePacket (Packet &tcpData)
 
void ReassemblePacket (RawPacket *tcpRawData)
 
void closeConnection (uint32_t flowKey)
 
void closeAllConnections ()
 
const std::vector< ConnectionData > & getConnectionInformation () const
 
int isConnectionOpen (const ConnectionData &connection)
 

Detailed Description

A class containing the TCP reassembly logic. Please refer to the documentation at the top of TcpReassembly.h for understanding how to use this class

Member Typedef Documentation

pcpp::TcpReassembly::OnTcpConnectionEnd

A callback invoked when a TCP connection is terminated, either by a FIN or RST packet or manually by the user

Parameters
[in]connectionDataConnection information
[in]reasonThe reason for connection termination: FIN/RST packet or manually by the user
[in]userCookieA pointer to the cookie provided by the user in TcpReassembly c'tor (or NULL if no cookie provided)
pcpp::TcpReassembly::OnTcpConnectionStart

A callback invoked when a new TCP connection is identified (whether it begins with a SYN packet or not)

Parameters
[in]connectionDataConnection information
[in]userCookieA pointer to the cookie provided by the user in TcpReassembly c'tor (or NULL if no cookie provided)
pcpp::TcpReassembly::OnTcpMessageReady

A callback invoked when new data arrives on a connection

Parameters
[in]sideThe side this data belongs to (MachineA->MachineB or vice versa). The value is 0 or 1 where 0 is the first side seen in the connection and 1 is the second side seen
[in]tcpDataThe TCP data itself + connection information
[in]userCookieA pointer to the cookie provided by the user in TcpReassembly c'tor (or NULL if no cookie provided)

Member Enumeration Documentation

An enum for connection end reasons

Enumerator
TcpReassemblyConnectionClosedByFIN_RST 

Connection ended because of FIN or RST packet

TcpReassemblyConnectionClosedManually 

Connection ended manually by the user

Constructor & Destructor Documentation

pcpp::TcpReassembly::TcpReassembly ( OnTcpMessageReady  onMessageReadyCallback,
void *  userCookie = NULL,
OnTcpConnectionStart  onConnectionStartCallback = NULL,
OnTcpConnectionEnd  onConnectionEndCallback = NULL 
)

A c'tor for this class

Parameters
[in]onMessageReadyCallbackThe callback to be invoked when new data arrives
[in]userCookieA pointer to an object provided by the user. This pointer will be returned when invoking the various callbacks. This parameter is optional, default cookie is NULL
[in]onConnectionStartCallbackThe callback to be invoked when a new connection is identified. This parameter is optional
[in]onConnectionEndCallbackThe callback to be invoked when a new connection is terminated (either by a FIN/RST packet or manually by the user). This parameter is optional
pcpp::TcpReassembly::~TcpReassembly ( )

A d'tor for this class. Frees all internal structures. Notice that if the d'tor is called while connections are still open, all data is lost and TcpReassembly::OnTcpConnectionEnd won't be called for those connections

Member Function Documentation

void pcpp::TcpReassembly::closeAllConnections ( )

Close all open connections manually. This method will cause the TcpReassembly::OnTcpConnectionEnd to be invoked for each connection with a reason of TcpReassembly::TcpReassemblyConnectionClosedManually

void pcpp::TcpReassembly::closeConnection ( uint32_t  flowKey)

Close a connection manually. If the connection doesn't exist or already closed an error log is printed. This method will cause the TcpReassembly::OnTcpConnectionEnd to be invoked with a reason of TcpReassembly::TcpReassemblyConnectionClosedManually

Parameters
[in]flowKeyA 4-byte hash key representing the connection. Can be taken from a ConnectionData instance
const std::vector<ConnectionData>& pcpp::TcpReassembly::getConnectionInformation ( ) const

Get a list of all connections managed by this TcpReassembly instance (both connections that are open and those that are already closed)

Returns
A list of all connections managed. Notice this list is constant and cannot be changed by the user
int pcpp::TcpReassembly::isConnectionOpen ( const ConnectionData connection)

Check if a certain connection managed by this TcpReassembly instance is currently opened or closed

Parameters
[in]connectionThe connection to check
Returns
A positive number (> 0) if connection is opened, zero (0) if connection is closed, and a negative number (< 0) if this connection isn't managed by this TcpReassembly instance
void pcpp::TcpReassembly::ReassemblePacket ( Packet tcpData)

The most important method of this class which gets a packet from the user and processes it. If this packet opens a new connection, ends a connection or contains new data on an existing connection, the relevant callback will be called (TcpReassembly::OnTcpMessageReady, TcpReassembly::OnTcpConnectionStart, TcpReassembly::OnTcpConnectionEnd)

Parameters
[in]tcpDataA reference to the packet to process
void pcpp::TcpReassembly::ReassemblePacket ( RawPacket tcpRawData)

The most important method of this class which gets a raw packet from the user and processes it. If this packet opens a new connection, ends a connection or contains new data on an existing connection, the relevant callback will be invoked (TcpReassembly::OnTcpMessageReady, TcpReassembly::OnTcpConnectionStart, TcpReassembly::OnTcpConnectionEnd)

Parameters
[in]tcpRawDataA reference to the raw packet to process