diff --git a/src/capture.c b/src/capture.c index f30a982..1e4fa3c 100644 --- a/src/capture.c +++ b/src/capture.c @@ -104,7 +104,7 @@ capture_deinit() } int -capture_online(const char *dev, const char *outfile) +capture_online(const char *dev) { capture_info_t *capinfo; @@ -177,20 +177,11 @@ capture_online(const char *dev, const char *outfile) // Add this capture information as packet source capture_add_source(capinfo); - // If requested store packets in a dump file - if (outfile && !capture_cfg.pd) { - if ((capture_cfg.pd = dump_open(outfile)) == NULL) { - fprintf(stderr, "Couldn't open output dump file %s: %s\n", outfile, - pcap_geterr(capinfo->handle)); - return 2; - } - } - return 0; } int -capture_offline(const char *infile, const char *outfile) +capture_offline(const char *infile) { capture_info_t *capinfo; FILE *fstdin; @@ -242,15 +233,6 @@ capture_offline(const char *infile, const char *outfile) // Add this capture information as packet source capture_add_source(capinfo); - // If requested store packets in a dump file - if (outfile && !capture_cfg.pd) { - if ((capture_cfg.pd = dump_open(outfile)) == NULL) { - fprintf(stderr, "Couldn't open output dump file %s: %s\n", outfile, - pcap_geterr(capinfo->handle)); - return 2; - } - } - return 0; } @@ -1208,6 +1190,18 @@ capture_packet_time_sorter(vector_t *vector, void *item) vector_insert(vector, item, 0); } +void +capture_set_dumper(pcap_dumper_t *dumper) +{ + capture_cfg.pd = dumper; +} + +void +capture_dump_packet(packet_t *packet) +{ + dump_packet(capture_cfg.pd, packet); +} + int8_t datalink_size(int datalink) diff --git a/src/capture.h b/src/capture.h index 008fa32..fefecca 100644 --- a/src/capture.h +++ b/src/capture.h @@ -199,12 +199,11 @@ capture_deinit(); * @brief Online capture function * * @param device Device to start capture from - * @param outfile Dumpfile for captured packets * * @return 0 on spawn success, 1 otherwise */ int -capture_online(const char *dev, const char *outfile); +capture_online(const char *dev); /** * @brief Read from pcap file and fill sngrep sctuctures @@ -217,7 +216,7 @@ capture_online(const char *dev, const char *outfile); * @return 0 if load has been successfull, 1 otherwise */ int -capture_offline(const char *infile, const char *outfile); +capture_offline(const char *infile); /** * @brief Read the next package and parse SIP messages @@ -464,6 +463,18 @@ capture_packet_time_sorter(vector_t *vector, void *item); void capture_close(); +/** + * @brief Set general capture dumper + */ +void +capture_set_dumper(pcap_dumper_t *dumper); + +/** + * @brief Store a packet in dumper file + */ +void +capture_dump_packet(packet_t *packet); + /** * @brief Get datalink header size * diff --git a/src/capture_eep.c b/src/capture_eep.c index 8a3d1f0..6d4224b 100644 --- a/src/capture_eep.c +++ b/src/capture_eep.c @@ -674,6 +674,9 @@ capture_eep_receive_v2() packet_set_type(pkt, PACKET_SIP_UDP); packet_set_payload(pkt, payload, header.caplen); + // Store this packets in output file + capture_dump_packet(pkt); + /* FREE */ sng_free(payload); return pkt; @@ -853,6 +856,9 @@ capture_eep_receive_v3(const u_char *pkt, uint32_t size) packet_set_type(pkt_new, PACKET_SIP_UDP); packet_set_payload(pkt_new, payload, header.caplen); + // Store this packets in output file + capture_dump_packet(pkt_new); + /* FREE */ sng_free(payload); return pkt_new; diff --git a/src/main.c b/src/main.c index d8a2e1d..e8b91f6 100644 --- a/src/main.c +++ b/src/main.c @@ -370,17 +370,21 @@ main(int argc, char* argv[]) // If we have an input file, load it for (i = 0; i < vector_count(infiles); i++) { // Try to load file - if (capture_offline(vector_item(infiles, i), outfile) != 0) + if (capture_offline(vector_item(infiles, i)) != 0) return 1; } // If we have an input device, load it for (i = 0; i < vector_count(indevices); i++) { // Check if all capture data is valid - if (capture_online(vector_item(indevices, i), outfile) != 0) + if (capture_online(vector_item(indevices, i)) != 0) return 1; } + if (outfile) { + capture_set_dumper(dump_open(outfile)); + } + // Remove Input files vector vector_destroy(infiles);