0

Packet with Comment

i have to add packet comment using c++ code.

i am using Enhanced Packet Block to store packet data.

strucure: SHB---IPB----EPB---EPB----EPB ......

i have used PCAPPlusPlus Library to add comment for every packet.

my code to add comment using pcapplusplus lib->

#include <iostream>
#include "stdlib.h"
#include "PcapFileDevice.h"
/**
* main method of the application
*/
int main(int argc, char* argv[])
{
    pcpp::IFileReaderDevice* reader = pcpp::IFileReaderDevice::getReader("sri.pcapng");

    // verify that a reader interface was indeed created
    if (reader == NULL)
    {
        std::cerr << "Cannot determine reader for file type" << std::endl;
        return 1;
    } 
    if (!reader->open())
    {
        std::cerr << "Cannot open input.pcap for reading" << std::endl;
        return 1;
    } 
    pcpp::PcapNgFileWriterDevice pcapNgWriter("final.pcapng");

    // try to open the file for writing
    if (!pcapNgWriter.open())
    {
        std::cerr << "Cannot open output.pcapng for writing" << std::endl;
        return 1;
    } 
    pcpp::RawPacket rawPacket;

    // a while loop that will continue as long as there are packets in the input file
    // matching the BPF filter
    int count = 0;
    while (reader->getNextPacket(rawPacket))
    { 
        // write each packet to both writers
       // pcapWriter.writePacket(rawPacket);
        
       pcapNgWriter.writePacket(rawPacket, "Info: GPORT msisdn from tcap map:INTL 
       DN=421903652077^M  SCCP : gport service selected  GPORT : MNP no Error ^ "); 
    }
    reader->close();

    // close writers
    pcapNgWriter.close();

    // free reader memory because it was created by pcpp::IFileReaderDevice::getReader()
    delete reader;
}  

i want the code in c++ or ways to add comment in packet without using pcappluplus lib.

Adriaan
  • 17,741
  • 7
  • 42
  • 75

0 Answers0