Examples/TcpReassembly/main.cpp
/**
 * The method responsible for TCP reassembly on pcap/pcapng files
 */
The method responsible for TCP reassembly on pcap/pcapng files
The method responsible for TCP reassembly on pcap / pcapng files
void doTcpReassemblyOnPcapFile(std::string fileName, pcpp::TcpReassembly& tcpReassembly, std::string bpfFilter = "")
{
	pcpp::IFileReaderDevice* reader = pcpp::IFileReaderDevice::getReader(fileName);
	if (!reader->open())
		EXIT_WITH_ERROR("Cannot open pcap/pcapng file");
	if (!bpfFilter.empty())
	{
		if (!reader->setFilter(bpfFilter))
			EXIT_WITH_ERROR("Cannot set BPF filter to pcap file");
	}
	std::cout << "Starting reading '" << fileName << "'..." << std::endl;
	pcpp::RawPacket rawPacket;
	while (reader->getNextPacket(rawPacket))
	{
		tcpReassembly.reassemblePacket(&rawPacket);
	}
	size_t numOfConnectionsProcessed = tcpReassembly.getConnectionInformation().size();
	tcpReassembly.closeAllConnections();
	reader->close();
	delete reader;
	std::cout << "Done! processed " << numOfConnectionsProcessed << " connections" << std::endl;
}
void doTcpReassemblyOnPcapFile ( std :: string fileName , pcpp :: TcpReassembly & tcpReassembly , std :: string bpfFilter = " " ) { pcpp :: IFileReaderDevice * reader = pcpp :: IFileReaderDevice :: getReader ( fileName ) ; if ( ! reader -> open ( ) ) EXIT_WITH_ERROR ( " " ) ; if ( ! bpfFilter . empty ( ) ) { if ( ! reader -> setFilter ( bpfFilter ) ) EXIT_WITH_ERROR ( " " ) ; } std :: cout << " " << fileName << " " << std :: endl ; pcpp :: RawPacket rawPacket ; while ( reader -> getNextPacket ( rawPacket ) ) { tcpReassembly . reassemblePacket ( & rawPacket ) ; } size_t numOfConnectionsProcessed = tcpReassembly . getConnectionInformation ( ) . size ( ) ; tcpReassembly . closeAllConnections ( ) ; reader -> close ( ) ; delete reader ; std :: cout << " " << numOfConnectionsProcessed << " " << std :: endl ; }
The method responsible for TCP reassembly on pcap/pcapng files
The method responsible for TCP reassembly on pcap / pcapng files
// open input file (pcap or pcapng file)
 // try to open the file device
 // set BPF filter if set by the user
 // run in a loop that reads one packet from the file in each iteration and feeds it to the TCP reassembly instance
 // extract number of connections before closing all of them
 // after all packets have been read - close the connections which are still opened
 // close the reader and free its memory
