Examples/TcpReassembly/main.cpp
/**
 * The callback being called by the TCP reassembly module whenever a connection is ending. This method removes the connection from the connection manager and writes the metadata file if requested
 * by the user
 */
The callback being called by the TCP reassembly module whenever a connection is ending. This method removes the connection from the connection manager and writes the metadata file if requested
by the user
The callback being called by the TCP reassembly module whenever a connection is ending . This method removes the connection from the connection manager and writes the metadata file if requested by the user
static void tcpReassemblyConnectionEndCallback(const pcpp::ConnectionData& connectionData, pcpp::TcpReassembly::ConnectionEndReason reason, void* userCookie)
{
	TcpReassemblyConnMgr* connMgr = (TcpReassemblyConnMgr*)userCookie;
	TcpReassemblyConnMgrIter iter = connMgr->find(connectionData.flowKey);
	if (iter == connMgr->end())
		return;
	if (GlobalConfig::getInstance().writeMetadata)
	{
		std::string fileName = GlobalConfig::getInstance().getFileName(connectionData, 0, false) + "-metadata.txt";
		std::ofstream metadataFile(fileName.c_str());
		metadataFile << "Number of data packets in side 0:  " << iter->second.numOfDataPackets[0] << std::endl;
		metadataFile << "Number of data packets in side 1:  " << iter->second.numOfDataPackets[1] << std::endl;
		metadataFile << "Total number of data packets:      " << (iter->second.numOfDataPackets[0] + iter->second.numOfDataPackets[1]) << std::endl;
		metadataFile << std::endl;
		metadataFile << "Number of bytes in side 0:         " << iter->second.bytesFromSide[0] << std::endl;
		metadataFile << "Number of bytes in side 1:         " << iter->second.bytesFromSide[1] << std::endl;
		metadataFile << "Total number of bytes:             " << (iter->second.bytesFromSide[0] + iter->second.bytesFromSide[1]) << std::endl;
		metadataFile << std::endl;
		metadataFile << "Number of messages in side 0:      " << iter->second.numOfMessagesFromSide[0] << std::endl;
		metadataFile << "Number of messages in side 1:      " << iter->second.numOfMessagesFromSide[1] << std::endl;
		metadataFile.close();
	}
	connMgr->erase(iter);
}
static void tcpReassemblyConnectionEndCallback ( const pcpp :: ConnectionData & connectionData , pcpp :: TcpReassembly :: ConnectionEndReason reason , void * userCookie ) { TcpReassemblyConnMgr * connMgr = ( TcpReassemblyConnMgr * ) userCookie ; TcpReassemblyConnMgrIter iter = connMgr -> find ( connectionData . flowKey ) ; if ( iter == connMgr -> end ( ) ) return ; if ( GlobalConfig :: getInstance ( ) . writeMetadata ) { std :: string fileName = GlobalConfig :: getInstance ( ) . getFileName ( connectionData , 0 , false ) + " " ; std :: ofstream metadataFile ( fileName . c_str ( ) ) ; metadataFile << " " << iter -> second . numOfDataPackets [ 0 ] << std :: endl ; metadataFile << " " << iter -> second . numOfDataPackets [ 1 ] << std :: endl ; metadataFile << " " << ( iter -> second . numOfDataPackets [ 0 ] + iter -> second . numOfDataPackets [ 1 ] ) << std :: endl ; metadataFile << std :: endl ; metadataFile << " " << iter -> second . bytesFromSide [ 0 ] << std :: endl ; metadataFile << " " << iter -> second . bytesFromSide [ 1 ] << std :: endl ; metadataFile << " " << ( iter -> second . bytesFromSide [ 0 ] + iter -> second . bytesFromSide [ 1 ] ) << std :: endl ; metadataFile << std :: endl ; metadataFile << " " << iter -> second . numOfMessagesFromSide [ 0 ] << std :: endl ; metadataFile << " " << iter -> second . numOfMessagesFromSide [ 1 ] << std :: endl ; metadataFile . close ( ) ; } connMgr -> erase ( iter ) ; }
The callback being called by the TCP reassembly module whenever a connection is ending.
The callback being called by the TCP reassembly module whenever a connection is ending .
// get a pointer to the connection manager
 // find the connection in the connection manager by the flow key
 // connection wasn't found - shouldn't get here
 // write a metadata file if required by the user
 // remove the connection from the connection manager
