I wrote the following code to capture packets; but, it actually save the last packet.
process_Packet(const struct pcap_pkthdr *header,
const u_char * packet)
{
FILE* pFile = NULL;
pFile = fopen ("myfile.pcap" , "wb"); // open for writing in binary mode
pcap_dumper_t * dumpfile = pcap_dump_fopen(pcap_handle,pFile);
if (dumpfile == NULL)
{
printf("***NOOOO Dump!!!!!!!***");
}
else
{
pcap_dump((unsigned char *) dumpfile, header, packet);
printf("***Dumped!!!!!!!***");
}
pcap_dump_close(dumpfile);
}
I want to write a code that collect packets and append the new packet to previous ones.
I should say that fopen("...", "ab") corrupts the file and doesn't work.