PcapPlusPlus (original) (raw)

// parse the raw packet into a parsed packet
pcpp::Packet parsedPacket(&rawPacket);

// check if it's an IPv4 packet
if (parsedPacket.isPacketOfType(pcpp::IPv4)) {
// extract source and dest IPs
pcpp::IPv4Address srcIP = 
    parsedPacket.getLayerOfType()->getSrcIPv4Address();
pcpp::IPv4Address destIP = 
    parsedPacket.getLayerOfType()->getDstIPv4Address();

// print source and dest IPs
std::cout << 
    "Source IP is: " << srcIP << std::endl <<
    "Dest IP is: " << destIP << std::endl;

Super Fast!

PcapPlusPlus is designed to be efficient and lightweight. It enables amazingly fast packet processing with minimum overhead

View Benchmarks

Multi Platform Support

PcapPlusPlus is fully supported on Windows, MacOS, Linux, Android and FreeBSD. You can download pre-built binaries for each platform or build it from source. PcapPlusPlus is available in popular package managers such as Homebrew and Conan

View Installation Guide

Read and Write Packets to Files

PcapPlusPlus provides an easy-to-use interface for reading and writing network packets into files.It supports the most popular file formats which are PCAP and PCAPNG

Learn More

// create a pcap file reader
pcpp::PcapFileReaderDevice pcapReader("input.pcap");
pcapReader.open();

// create a pcapng file writer
pcpp::PcapNgFileWriterDevice pcapNgWriter("output.pcapng");
pcapNgWriter.open();

// raw packet object
pcpp::RawPacket rawPacket;

// read packets from pcap reader and write pcapng writer
while (pcapReader->getNextPacket(rawPacket)) {
  pcapNgWriter.writePacket(rawPacket);
}

Packet Reassembly

PcapPlusPlus contains unique implementation of packet reassembly techniques.

TCP Reassembly which supports TCP retransmission, out-of-order TCP packets and missing TCP data.

IP Fragmentation and Defragmentation to create and reassemble IPv4 and IPv6 fragments

Learn More