Examples/TcpReassembly/main.cpp
/**
 * The method responsible for TCP reassembly on live traffic
 */
The method responsible for TCP reassembly on live traffic
The method responsible for TCP reassembly on live traffic
void doTcpReassemblyOnLiveTraffic(pcpp::PcapLiveDevice* dev, pcpp::TcpReassembly& tcpReassembly, std::string bpfFilter = "")
{
	if (!dev->open())
		EXIT_WITH_ERROR("Cannot open interface");
	if (!bpfFilter.empty())
	{
		if (!dev->setFilter(bpfFilter))
			EXIT_WITH_ERROR("Cannot set BPF filter to interface");
	}
	std::cout << "Starting packet capture on '" << dev->getIPv4Address() << "'..." << std::endl;
	dev->startCapture(onPacketArrives, &tcpReassembly);
	bool shouldStop = false;
	pcpp::ApplicationEventHandler::getInstance().onApplicationInterrupted(onApplicationInterrupted, &shouldStop);
	while(!shouldStop)
		pcpp::multiPlatformSleep(1);
	dev->stopCapture();
	dev->close();
	tcpReassembly.closeAllConnections();
	std::cout << "Done! processed " << tcpReassembly.getConnectionInformation().size() << " connections" << std::endl;
}
void doTcpReassemblyOnLiveTraffic ( pcpp :: PcapLiveDevice * dev , pcpp :: TcpReassembly & tcpReassembly , std :: string bpfFilter = " " ) { if ( ! dev -> open ( ) ) EXIT_WITH_ERROR ( " " ) ; if ( ! bpfFilter . empty ( ) ) { if ( ! dev -> setFilter ( bpfFilter ) ) EXIT_WITH_ERROR ( " " ) ; } std :: cout << " " << dev -> getIPv4Address ( ) << " " << std :: endl ; dev -> startCapture ( onPacketArrives , & tcpReassembly ) ; bool shouldStop = false ; pcpp :: ApplicationEventHandler :: getInstance ( ) . onApplicationInterrupted ( onApplicationInterrupted , & shouldStop ) ; while ( ! shouldStop ) pcpp :: multiPlatformSleep ( 1 ) ; dev -> stopCapture ( ) ; dev -> close ( ) ; tcpReassembly . closeAllConnections ( ) ; std :: cout << " " << tcpReassembly . getConnectionInformation ( ) . size ( ) << " " << std :: endl ; }
The method responsible for TCP reassembly on live traffic
The method responsible for TCP reassembly on live traffic
// try to open device
 // set BPF filter if set by the user
 // start capturing packets. Each packet arrived will be handled by onPacketArrives method
 // register the on app close event to print summary stats on app termination
 // run in an endless loop until the user presses ctrl+c
 // stop capturing and close the live device
 // close all connections which are still opened
