Examples/PcapPrinter/main.cpp
/**
* print all requested packets in a pcap-ng file
*/
print all requested packets in a pcap-ng file
print all requested packets in a pcap - ng file
int printPcapNgPackets(pcpp::PcapNgFileReaderDevice* reader, std::ostream* out, int packetCount)
{
	int packetCountSoFar = 0;
	pcpp::RawPacket rawPacket;
	std::string packetComment = "";
	while (reader->getNextPacket(rawPacket, packetComment) && packetCountSoFar != packetCount)
	{
		if (packetComment != "")
			(*out) << "Packet Comment: " << packetComment << std::endl;
		pcpp::Packet parsedPacket(&rawPacket);
		(*out) << "Link layer type: " << linkLayerToString(rawPacket.getLinkLayerType()) << std::endl;
		(*out) << parsedPacket.toString() << std::endl;
		packetCountSoFar++;
	}
	return packetCountSoFar;
}
int printPcapNgPackets ( pcpp :: PcapNgFileReaderDevice * reader , std :: ostream * out , int packetCount ) { int packetCountSoFar = 0 ; pcpp :: RawPacket rawPacket ; std :: string packetComment = " " ; while ( reader -> getNextPacket ( rawPacket , packetComment ) && packetCountSoFar != packetCount ) { if ( packetComment != " " ) ( * out ) << " " << packetComment << std :: endl ; pcpp :: Packet parsedPacket ( & rawPacket ) ; ( * out ) << " " << linkLayerToString ( rawPacket . getLinkLayerType ( ) ) << std :: endl ; ( * out ) << parsedPacket . toString ( ) << std :: endl ; packetCountSoFar ++ ; } return packetCountSoFar ; }
print all requested packets in a pcap-ng file
print all requested packets in a pcap - ng file
// read packets from the file until end-of-file or until reached user requested packet count
 // print packet comment if exists
 // parse the raw packet into a parsed packet
 // print packet to string
 // return the number of packets that were printed
