Examples/PcapPrinter/main.cpp
/**
* print file summary based on the reader type
*/
print file summary based on the reader type
print file summary based on the reader type
std::string printFileSummary(pcpp::IFileReaderDevice* reader)
{
	std::ostringstream stream;
	stream << "File summary:" << std::endl;
	stream << "~~~~~~~~~~~~~" << std::endl;
	stream << "   File name: " << reader->getFileName() << std::endl;
	stream << "   File size: " << reader->getFileSize() << " bytes" << std::endl;
	if (dynamic_cast<pcpp::PcapFileReaderDevice*>(reader) != NULL)
	{
		pcpp::PcapFileReaderDevice* pcapReader = dynamic_cast<pcpp::PcapFileReaderDevice*>(reader);
		pcpp::LinkLayerType linkLayer = pcapReader->getLinkLayerType();
		stream << "   Link layer type: " << linkLayerToString(linkLayer) << std::endl;
	}
	else if (dynamic_cast<pcpp::PcapNgFileReaderDevice*>(reader) != NULL)
	{
		pcpp::PcapNgFileReaderDevice* pcapNgReader = dynamic_cast<pcpp::PcapNgFileReaderDevice*>(reader);
		if (pcapNgReader->getOS() != "")
			stream << "   OS: " << pcapNgReader->getOS() << std::endl;
		if (pcapNgReader->getCaptureApplication() != "")
			stream << "   Capture application: " << pcapNgReader->getCaptureApplication() << std::endl;
		if (pcapNgReader->getCaptureFileComment() != "")
			stream << "   File comment: " << pcapNgReader->getCaptureFileComment() << std::endl;
		if (pcapNgReader->getHardware() != "")
			stream << "   Capture hardware: " << pcapNgReader->getHardware() << std::endl;
	}
	stream << std::endl;
	return stream.str();
}
std :: string printFileSummary ( pcpp :: IFileReaderDevice * reader ) { std :: ostringstream stream ; stream << " " << std :: endl ; stream << " " << std :: endl ; stream << " " << reader -> getFileName ( ) << std :: endl ; stream << " " << reader -> getFileSize ( ) << " " << std :: endl ; if ( dynamic_cast < pcpp :: PcapFileReaderDevice * > ( reader ) != NULL ) { pcpp :: PcapFileReaderDevice * pcapReader = dynamic_cast < pcpp :: PcapFileReaderDevice * > ( reader ) ; pcpp :: LinkLayerType linkLayer = pcapReader -> getLinkLayerType ( ) ; stream << " " << linkLayerToString ( linkLayer ) << std :: endl ; } else if ( dynamic_cast < pcpp :: PcapNgFileReaderDevice * > ( reader ) != NULL ) { pcpp :: PcapNgFileReaderDevice * pcapNgReader = dynamic_cast < pcpp :: PcapNgFileReaderDevice * > ( reader ) ; if ( pcapNgReader -> getOS ( ) != " " ) stream << " " << pcapNgReader -> getOS ( ) << std :: endl ; if ( pcapNgReader -> getCaptureApplication ( ) != " " ) stream << " " << pcapNgReader -> getCaptureApplication ( ) << std :: endl ; if ( pcapNgReader -> getCaptureFileComment ( ) != " " ) stream << " " << pcapNgReader -> getCaptureFileComment ( ) << std :: endl ; if ( pcapNgReader -> getHardware ( ) != " " ) stream << " " << pcapNgReader -> getHardware ( ) << std :: endl ; } stream << std :: endl ; return stream . str ( ) ; }
print file summary based on the reader type
print file summary based on the reader type