c++ - Append Packet to Current PCAP file -



c++ - Append Packet to Current PCAP file -

i wrote next code capture packets; but, save lastly packet.

class="lang-c prettyprint-override"> process_packet(const struct pcap_pkthdr *header, const u_char * packet) { file* pfile = null; pfile = fopen ("myfile.pcap" , "wb"); // open 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 write code collect packets , append new packet previous ones. should fopen("...", "ab") corrupts file , doesn't work.

pcap_dump_fopen writes initialization headers, should called 1 time on empty file. after file headers created can pass file* instance opened in append mode pcap_dump straight casted unsigned char *. not safe approach - improve @ to the lowest degree write required fields (it's 10 lines anyway) since function implementation may alter in future , file format not. , don't understand why reopen file on every packet dumped. if want ensure info written can phone call fflush.

c++ pcap libpcap tcpdump packet-sniffers

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -