diff options
-rw-r--r-- | editcap.c | 59 | ||||
-rw-r--r-- | epan/dissectors/packet-snort.c | 7 | ||||
-rw-r--r-- | epan/wslua/wslua_dumper.c | 13 | ||||
-rw-r--r-- | extcap/androiddump.c | 7 | ||||
-rw-r--r-- | file.c | 42 | ||||
-rw-r--r-- | randpkt_core/randpkt_core.c | 10 | ||||
-rw-r--r-- | reordercap.c | 20 | ||||
-rw-r--r-- | tshark.c | 54 | ||||
-rw-r--r-- | ui/qt/import_text_dialog.cpp | 6 | ||||
-rw-r--r-- | ui/tap_export_pdu.c | 10 | ||||
-rw-r--r-- | wiretap/file_access.c | 51 | ||||
-rw-r--r-- | wiretap/merge.c | 56 | ||||
-rw-r--r-- | wiretap/nettrace_3gpp_32_423.c | 8 | ||||
-rw-r--r-- | wiretap/wtap.c | 7 | ||||
-rw-r--r-- | wiretap/wtap.h | 65 |
15 files changed, 194 insertions, 221 deletions
@@ -935,21 +935,20 @@ failure_message_cont(const char *msg_format, va_list ap) } static wtap_dumper * -editcap_dump_open(const char *filename, guint32 snaplen, - const wtapng_dump_params *ng_params, +editcap_dump_open(const char *filename, const wtap_dump_params *params, int *write_err) { wtap_dumper *pdh; if (strcmp(filename, "-") == 0) { /* Write to the standard output. */ - pdh = wtap_dump_open_stdout(out_file_type_subtype, out_frame_type, - snaplen, FALSE /* compressed */, - ng_params, write_err); + pdh = wtap_dump_open_stdout(out_file_type_subtype, + FALSE /* compressed */, + params, write_err); } else { - pdh = wtap_dump_open(filename, out_file_type_subtype, out_frame_type, - snaplen, FALSE /* compressed */, - ng_params, write_err); + pdh = wtap_dump_open(filename, out_file_type_subtype, + FALSE /* compressed */, + params, write_err); } return pdh; } @@ -997,7 +996,7 @@ real_main(int argc, char *argv[]) guint max_packet_number = 0; const wtap_rec *rec; wtap_rec temp_rec; - wtapng_dump_params ng_params = WTAPNG_DUMP_PARAMS_INIT; + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; char *shb_user_appl; gboolean do_mutation; guint32 caplen; @@ -1401,10 +1400,22 @@ real_main(int argc, char *argv[]) goto clean_exit; } - wtap_dump_params_init(&ng_params, wth); + wtap_dump_params_init(¶ms, wth); - if (out_frame_type == -2) - out_frame_type = wtap_file_encap(wth); + /* + * If an encapsulation type was specified, override the encapsulation + * type of the input file. + */ + if (out_frame_type != -2) + params.encap = out_frame_type; + + /* + * If a snapshot length was specified, and it's less than the snapshot + * length of the input file, override the snapshot length of the input + * file. + */ + if (snaplen != 0 && snaplen < wtap_snapshot_length(wth)) + params.snaplen = snaplen; /* * Now process the arguments following the input and output file @@ -1449,13 +1460,11 @@ real_main(int argc, char *argv[]) g_assert(filename); /* If we don't have an application name add Editcap */ - if (wtap_block_get_string_option_value(g_array_index(ng_params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) { - wtap_block_add_string_option_format(g_array_index(ng_params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "Editcap " VERSION); + if (wtap_block_get_string_option_value(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) { + wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "Editcap " VERSION); } - pdh = editcap_dump_open(filename, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - &ng_params, &write_err); + pdh = editcap_dump_open(filename, ¶ms, &write_err); if (pdh == NULL) { cfile_dump_open_failure_message("editcap", filename, @@ -1495,9 +1504,7 @@ real_main(int argc, char *argv[]) if (verbose) fprintf(stderr, "Continuing writing in file %s\n", filename); - pdh = editcap_dump_open(filename, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - &ng_params, &write_err); + pdh = editcap_dump_open(filename, ¶ms, &write_err); if (pdh == NULL) { cfile_dump_open_failure_message("editcap", filename, @@ -1526,9 +1533,7 @@ real_main(int argc, char *argv[]) if (verbose) fprintf(stderr, "Continuing writing in file %s\n", filename); - pdh = editcap_dump_open(filename, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), - &ng_params, &write_err); + pdh = editcap_dump_open(filename, ¶ms, &write_err); if (pdh == NULL) { cfile_dump_open_failure_message("editcap", filename, write_err, @@ -1898,9 +1903,7 @@ real_main(int argc, char *argv[]) g_free (filename); filename = g_strdup(argv[optind+1]); - pdh = editcap_dump_open(filename, - snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth), - &ng_params, &write_err); + pdh = editcap_dump_open(filename, ¶ms, &write_err); if (pdh == NULL) { cfile_dump_open_failure_message("editcap", filename, write_err, @@ -1934,8 +1937,8 @@ real_main(int argc, char *argv[]) } clean_exit: - g_free(ng_params.idb_inf); - wtap_dump_params_cleanup(&ng_params); + g_free(params.idb_inf); + wtap_dump_params_cleanup(¶ms); if (wth != NULL) wtap_close(wth); wtap_cleanup(); diff --git a/epan/dissectors/packet-snort.c b/epan/dissectors/packet-snort.c index 9e1d2ad88d..d868defec4 100644 --- a/epan/dissectors/packet-snort.c +++ b/epan/dissectors/packet-snort.c @@ -1144,13 +1144,13 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data else { /* We expect alerts from Snort. Pass frame into snort on first pass. */ if (!pinfo->fd->flags.visited && current_session.working) { - wtapng_dump_params params; int write_err = 0; gchar *err_info; wtap_rec rec; /* First time, open current_session.in to write to for dumping into snort with */ if (!current_session.pdh) { + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; int open_err; /* Older versions of Snort don't support capture file with several encapsulations (like pcapng), @@ -1164,11 +1164,10 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data * versions of Snort" wouldn't handle multiple encapsulation * types. */ - wtap_dump_params_init(¶ms, NULL); + params.encap = pinfo->rec->rec_header.packet_header.pkt_encap; + params.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD; current_session.pdh = wtap_dump_fdopen(current_session.in, WTAP_FILE_TYPE_SUBTYPE_PCAP, - pinfo->rec->rec_header.packet_header.pkt_encap, - WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, /* compressed */ ¶ms, &open_err); diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index ae947de796..2e738e4225 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -205,10 +205,10 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) { int encap = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_ENCAP,WTAP_ENCAP_ETHERNET); int err = 0; const char* filename = cross_plat_fname(fname); - wtapng_dump_params params; + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; - wtap_dump_params_init(¶ms, NULL); - d = wtap_dump_open(filename, filetype, encap, 0, FALSE, ¶ms, &err); + params.encap = encap; + d = wtap_dump_open(filename, filetype, FALSE, ¶ms, &err); if (! d ) { /* WSLUA_ERROR("Error while opening file for writing"); */ @@ -359,7 +359,7 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { int encap; int err = 0; const char* filename = cross_plat_fname(fname); - wtapng_dump_params params; + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; if (! lua_pinfo ) { WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector"); @@ -371,9 +371,8 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { } encap = lua_pinfo->rec->rec_header.packet_header.pkt_encap; - - wtap_dump_params_init(¶ms, NULL); - d = wtap_dump_open(filename, filetype, encap, 0, FALSE, ¶ms, &err); + params.encap = encap; + d = wtap_dump_open(filename, filetype, FALSE, ¶ms, &err); if (! d ) { switch (err) { diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 5acc404dee..e782908a27 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -443,13 +443,14 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) { g_warning("Write to %s failed: %s", g_strerror(errno)); } #else - wtapng_dump_params params; + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; int err = 0; wtap_init(FALSE); - wtap_dump_params_init(¶ms, NULL); - extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, encap, PACKET_LENGTH, FALSE, ¶ms, &err); + params.encap = encap; + params.snaplen = PACKET_LENGTH; + extcap_dumper.dumper.wtap = wtap_dump_open(fifo, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC, FALSE, ¶ms, &err); if (!extcap_dumper.dumper.wtap) { cfile_dump_open_failure_message("androiddump", fifo, err, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC); exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP); @@ -4448,14 +4448,18 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, or moving the capture file, we have to do it by writing the packets out in Wiretap. */ - wtapng_dump_params ng_params; + wtap_dump_params params; int encap; - /* XXX: what free's ng_params.shb_hdr? */ - wtap_dump_params_init(&ng_params, cf->provider.wth); + /* XXX: what free's params.shb_hdr? */ + wtap_dump_params_init(¶ms, cf->provider.wth); /* Determine what file encapsulation type we should use. */ encap = wtap_dump_file_encap_type(cf->linktypes); + params.encap = encap; + + /* Use the snaplen from cf (XXX - does wtap_dump_params_init handle that?) */ + params.snaplen = cf->snap; if (file_exists(fname)) { /* We're overwriting an existing file; write out to a new file, @@ -4466,15 +4470,13 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, encap, cf->snap, - compressed, &ng_params, &err); + pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); } else { - pdh = wtap_dump_open(fname, save_format, encap, cf->snap, - compressed, &ng_params, &err); + pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); } /* XXX idb_inf is documented to be used until wtap_dump_close. */ - g_free(ng_params.idb_inf); - ng_params.idb_inf = NULL; + g_free(params.idb_inf); + params.idb_inf = NULL; if (pdh == NULL) { cfile_dump_open_failure_alert_box(fname, err, save_format); @@ -4695,7 +4697,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname, int err; wtap_dumper *pdh; save_callback_args_t callback_args; - wtapng_dump_params ng_params; + wtap_dump_params params; int encap; packet_range_process_init(range); @@ -4705,11 +4707,15 @@ cf_export_specified_packets(capture_file *cf, const char *fname, written, don't special-case the operation - read each packet and then write it out if it's one of the specified ones. */ - /* XXX: what free's ng_params.shb_hdr? */ - wtap_dump_params_init(&ng_params, cf->provider.wth); + /* XXX: what free's params.shb_hdr? */ + wtap_dump_params_init(¶ms, cf->provider.wth); /* Determine what file encapsulation type we should use. */ encap = wtap_dump_file_encap_type(cf->linktypes); + params.encap = encap; + + /* Use the snaplen from cf (XXX - does wtap_dump_params_init handle that?) */ + params.snaplen = cf->snap; if (file_exists(fname)) { /* We're overwriting an existing file; write out to a new file, @@ -4720,15 +4726,13 @@ cf_export_specified_packets(capture_file *cf, const char *fname, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, encap, cf->snap, - compressed, &ng_params, &err); + pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); } else { - pdh = wtap_dump_open(fname, save_format, encap, cf->snap, - compressed, &ng_params, &err); + pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); } - /* XXX idb_inf is documented to be used until wtap_dump_close. */ - g_free(ng_params.idb_inf); - ng_params.idb_inf = NULL; + /* XXX idb_inf is documented to be used until wtap_dump_close. */ + g_free(params.idb_inf); + params.idb_inf = NULL; if (pdh == NULL) { cfile_dump_open_failure_alert_box(fname, err, save_format); diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c index aef4d29326..7b1822b76f 100644 --- a/randpkt_core/randpkt_core.c +++ b/randpkt_core/randpkt_core.c @@ -654,23 +654,25 @@ gboolean randpkt_example_close(randpkt_example* example) int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes) { - wtapng_dump_params params; int err; if (pkt_rand == NULL) { pkt_rand = g_rand_new(); } - wtap_dump_params_init(¶ms, NULL); + const wtap_dump_params params = { + .encap = example->sample_wtap_encap, + .snaplen = produce_max_bytes, + }; if (strcmp(produce_filename, "-") == 0) { /* Write to the standard output. */ example->dump = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAP, - example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, + FALSE /* compressed */, ¶ms, &err); example->filename = "the standard output"; } else { example->dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP, - example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, + FALSE /* compressed */, ¶ms, &err); example->filename = produce_filename; } diff --git a/reordercap.c b/reordercap.c index 8b5710d019..90c57f7ac1 100644 --- a/reordercap.c +++ b/reordercap.c @@ -177,7 +177,7 @@ main(int argc, char *argv[]) guint wrong_order_count = 0; gboolean write_output_regardless = TRUE; guint i; - wtapng_dump_params ng_params; + wtap_dump_params params; int ret = EXIT_SUCCESS; GPtrArray *frames; @@ -283,23 +283,21 @@ main(int argc, char *argv[]) } DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth)); - wtap_dump_params_init(&ng_params, wth); + wtap_dump_params_init(¶ms, wth); /* Open outfile (same filetype/encap as input file) */ if (strcmp(outfile, "-") == 0) { - pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), wtap_file_encap(wth), - wtap_snapshot_length(wth), FALSE, &ng_params, &err); + pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), FALSE, ¶ms, &err); } else { - pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth), - wtap_snapshot_length(wth), FALSE, &ng_params, &err); + pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), FALSE, ¶ms, &err); } - g_free(ng_params.idb_inf); - ng_params.idb_inf = NULL; + g_free(params.idb_inf); + params.idb_inf = NULL; if (pdh == NULL) { cfile_dump_open_failure_message("reordercap", outfile, err, wtap_file_type_subtype(wth)); - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); ret = OUTPUT_FILE_ERROR; goto clean_exit; } @@ -366,11 +364,11 @@ main(int argc, char *argv[]) /* Close outfile */ if (!wtap_dump_close(pdh, &err)) { cfile_close_failure_message(outfile, err); - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); ret = OUTPUT_FILE_ERROR; goto clean_exit; } - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); /* Finally, close infile and release resources. */ wtap_close(wth); @@ -3087,8 +3087,6 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, gboolean out_file_name_res, int max_packet_count, gint64 max_byte_count) { gboolean success = TRUE; - gint linktype; - int snapshot_length; wtap_dumper *pdh; guint32 framenum; int err = 0, err_pass1 = 0; @@ -3096,52 +3094,36 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, gint64 data_offset; gboolean filtering_tap_listeners; guint tap_flags; - wtapng_dump_params ng_params = WTAPNG_DUMP_PARAMS_INIT; + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; wtap_rec rec; Buffer buf; epan_dissect_t *edt = NULL; - char *shb_user_appl; + char *shb_user_appl; wtap_rec_init(&rec); if (save_file != NULL) { /* Set up to write to the capture file. */ - snapshot_length = wtap_snapshot_length(cf->provider.wth); - wtap_dump_params_init(&ng_params, cf->provider.wth); - linktype = wtap_file_encap(cf->provider.wth); + wtap_dump_params_init(¶ms, cf->provider.wth); /* If we don't have an application name add Tshark */ - if (wtap_block_get_string_option_value(g_array_index(ng_params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) { + if (wtap_block_get_string_option_value(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) { /* this is free'd by wtap_block_free() later */ - wtap_block_add_string_option_format(g_array_index(ng_params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info()); + wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info()); } - if (linktype != WTAP_ENCAP_PER_PACKET && - out_file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP) { - tshark_debug("tshark: writing PCAP format to %s", save_file); - if (strcmp(save_file, "-") == 0) { - /* Write to the standard output. */ - pdh = wtap_dump_open_stdout(out_file_type, linktype, - snapshot_length, FALSE /* compressed */, NULL, &err); - } else { - pdh = wtap_dump_open(save_file, out_file_type, linktype, - snapshot_length, FALSE /* compressed */, NULL, &err); - } - } - else { - tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file); - if (strcmp(save_file, "-") == 0) { - /* Write to the standard output. */ - pdh = wtap_dump_open_stdout(out_file_type, linktype, - snapshot_length, FALSE /* compressed */, &ng_params, &err); - } else { - pdh = wtap_dump_open(save_file, out_file_type, linktype, - snapshot_length, FALSE /* compressed */, &ng_params, &err); - } + tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file); + if (strcmp(save_file, "-") == 0) { + /* Write to the standard output. */ + pdh = wtap_dump_open_stdout(out_file_type, FALSE /* compressed */, + ¶ms, &err); + } else { + pdh = wtap_dump_open(save_file, out_file_type, FALSE /* compressed */, + ¶ms, &err); } - g_free(ng_params.idb_inf); - ng_params.idb_inf = NULL; + g_free(params.idb_inf); + params.idb_inf = NULL; if (pdh == NULL) { /* We couldn't set up to write to the capture file. */ @@ -3307,7 +3289,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, err, err_info, framenum, out_file_type); wtap_dump_close(pdh, &err); - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); exit(2); } } @@ -3392,7 +3374,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, cfile_write_failure_message("TShark", cf->filename, save_file, err, err_info, framenum, out_file_type); wtap_dump_close(pdh, &err); - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); exit(2); } } @@ -3481,7 +3463,7 @@ out: wtap_close(cf->provider.wth); cf->provider.wth = NULL; - wtap_dump_params_cleanup(&ng_params); + wtap_dump_params_cleanup(¶ms); return success; } diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp index c1ead47a88..46e158c167 100644 --- a/ui/qt/import_text_dialog.cpp +++ b/ui/qt/import_text_dialog.cpp @@ -118,12 +118,14 @@ QString &ImportTextDialog::capfileName() { void ImportTextDialog::convertTextFile() { char *tmpname; int err; - wtapng_dump_params params; + wtap_dump_params params; capfile_name_.clear(); wtap_dump_params_init(¶ms, NULL); + params.encap = import_info_.encapsulation; + params.snaplen = import_info_.max_frame_length; /* Use a random name for the temporary import buffer */ - import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, import_info_.encapsulation, import_info_.max_frame_length, FALSE, ¶ms, &err); + import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAP, FALSE, ¶ms, &err); capfile_name_.append(tmpname ? tmpname : "temporary file"); qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length; if (import_info_.wdh == NULL) { diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index 5b3788e615..5e6590b72d 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -140,18 +140,18 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment) exp_pdu_tap_data->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); g_array_append_val(exp_pdu_tap_data->shb_hdrs, shb_hdr); - const wtapng_dump_params ng_params = { + const wtap_dump_params params = { + .encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU, + .snaplen = WTAP_MAX_PACKET_SIZE_STANDARD, .shb_hdrs = exp_pdu_tap_data->shb_hdrs, .idb_inf = exp_pdu_tap_data->idb_inf, }; if (fd == 1) { exp_pdu_tap_data->wdh = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, - &ng_params, &err); + FALSE, ¶ms, &err); } else { exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, - WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, - &ng_params, &err); + FALSE, ¶ms, &err); } if (exp_pdu_tap_data->wdh == NULL) { g_assert(err != 0); diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 18480acc78..d0093600bb 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -2232,28 +2232,28 @@ static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd); static int wtap_dump_file_close(wtap_dumper *wdh); static wtap_dumper * -wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean compressed, - const wtapng_dump_params *ng_blocks, int *err) +wtap_dump_init_dumper(int file_type_subtype, gboolean compressed, + const wtap_dump_params *params, int *err) { wtap_dumper *wdh; wtap_block_t descr, file_int_data; wtapng_if_descr_mandatory_t *descr_mand, *file_int_data_mand; - GArray *interfaces = ng_blocks && ng_blocks->idb_inf ? ng_blocks->idb_inf->interface_data : NULL; + GArray *interfaces = params->idb_inf ? params->idb_inf->interface_data : NULL; /* Check whether we can open a capture file with that file type and that encapsulation. */ - if (!wtap_dump_open_check(file_type_subtype, encap, compressed, err)) + if (!wtap_dump_open_check(file_type_subtype, params->encap, compressed, err)) return NULL; /* Allocate a data structure for the output stream. */ - wdh = wtap_dump_alloc_wdh(file_type_subtype, encap, snaplen, compressed, err); + wdh = wtap_dump_alloc_wdh(file_type_subtype, params->encap, params->snaplen, compressed, err); if (wdh == NULL) return NULL; /* couldn't allocate it */ /* Set Section Header Block data */ - wdh->shb_hdrs = ng_blocks ? ng_blocks->shb_hdrs : NULL; + wdh->shb_hdrs = params->shb_hdrs; /* Set Name Resolution Block data */ - wdh->nrb_hdrs = ng_blocks ? ng_blocks->nrb_hdrs : NULL; + wdh->nrb_hdrs = params->nrb_hdrs; /* Set Interface Description Block data */ if (interfaces && interfaces->len) { guint itf_count; @@ -2265,18 +2265,21 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co file_int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(file_int_data); descr = wtap_block_create(WTAP_BLOCK_IF_DESCR); wtap_block_copy(descr, file_int_data); - if ((encap != WTAP_ENCAP_PER_PACKET) && (encap != file_int_data_mand->wtap_encap)) { + if ((params->encap != WTAP_ENCAP_PER_PACKET) && (params->encap != file_int_data_mand->wtap_encap)) { descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr); - descr_mand->wtap_encap = encap; + descr_mand->wtap_encap = params->encap; } g_array_append_val(wdh->interface_data, descr); } } else { + int snaplen; + // XXX IDBs should be optional. descr = wtap_block_create(WTAP_BLOCK_IF_DESCR); descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr); - descr_mand->wtap_encap = encap; + descr_mand->wtap_encap = params->encap; descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */ + snaplen = params->snaplen; if (snaplen == 0) { /* * No snapshot length was specified. Pick an @@ -2291,7 +2294,7 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co * to allocate an unnecessarily huge chunk of * memory for a packet buffer. */ - if (encap == WTAP_ENCAP_DBUS) + if (params->encap == WTAP_ENCAP_DBUS) snaplen = 128*1024*1024; else snaplen = WTAP_MAX_PACKET_SIZE_STANDARD; @@ -2305,14 +2308,14 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co } wtap_dumper * -wtap_dump_open(const char *filename, int file_type_subtype, int encap, - int snaplen, gboolean compressed, const wtapng_dump_params *ng_blocks, int *err) +wtap_dump_open(const char *filename, int file_type_subtype, + gboolean compressed, const wtap_dump_params *params, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, ng_blocks, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); if (wdh == NULL) return NULL; @@ -2340,10 +2343,8 @@ wtap_dump_open(const char *filename, int file_type_subtype, int encap, wtap_dumper * wtap_dump_open_tempfile(char **filenamep, const char *pfx, - int file_type_subtype, int encap, - int snaplen, gboolean compressed, - const wtapng_dump_params *ng_blocks, - int *err) + int file_type_subtype, gboolean compressed, + const wtap_dump_params *params, int *err) { int fd; char *tmpname; @@ -2354,7 +2355,7 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx, *filenamep = NULL; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, ng_blocks, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); if (wdh == NULL) return NULL; @@ -2391,14 +2392,14 @@ wtap_dump_open_tempfile(char **filenamep, const char *pfx, } wtap_dumper * -wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen, - gboolean compressed, const wtapng_dump_params *ng_blocks, int *err) +wtap_dump_fdopen(int fd, int file_type_subtype, gboolean compressed, + const wtap_dump_params *params, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ - wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, ng_blocks, err); + wdh = wtap_dump_init_dumper(file_type_subtype, compressed, params, err); if (wdh == NULL) return NULL; @@ -2422,8 +2423,8 @@ wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen, } wtap_dumper * -wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen, - gboolean compressed, const wtapng_dump_params *ng_blocks, int *err) +wtap_dump_open_stdout(int file_type_subtype, gboolean compressed, + const wtap_dump_params *params, int *err) { int new_fd; wtap_dumper *wdh; @@ -2454,7 +2455,7 @@ wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen, } #endif - wdh = wtap_dump_fdopen(new_fd, file_type_subtype, encap, snaplen, compressed, ng_blocks, err); + wdh = wtap_dump_fdopen(new_fd, file_type_subtype, compressed, params, err); if (wdh == NULL) { /* Failed; close the new FD */ ws_close(new_fd); diff --git a/wiretap/merge.c b/wiretap/merge.c index ed99904e62..0a5c69fb9a 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -1008,6 +1008,9 @@ merge_files(const gchar* out_filename, const int file_type, cb->callback_func(MERGE_EVENT_FRAME_TYPE_SELECTED, frame_type, in_files, in_file_count, cb->data); /* prepare the outfile */ + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; + params.encap = frame_type; + params.snaplen = snaplen; if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) { shb_hdrs = create_shb_header(in_files, in_file_count, app_name); merge_debug("merge_files: SHB created"); @@ -1016,18 +1019,11 @@ merge_files(const gchar* out_filename, const int file_type, merge_debug("merge_files: IDB merge operation complete, got %u IDBs", idb_inf ? idb_inf->interface_data->len : 0); /* XXX other blocks like NRB are now discarded. */ - const wtapng_dump_params ng_params = { - .shb_hdrs = shb_hdrs, - .idb_inf = idb_inf, - }; - pdh = wtap_dump_open(out_filename, file_type, frame_type, snaplen, - FALSE /* compressed */, &ng_params, err); + params.shb_hdrs = shb_hdrs; + params.idb_inf = idb_inf; } - else { - pdh = wtap_dump_open(out_filename, file_type, frame_type, snaplen, - FALSE /* compressed */, NULL, err); - } - + pdh = wtap_dump_open(out_filename, file_type, FALSE /* compressed */, + ¶ms, err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); @@ -1115,6 +1111,9 @@ merge_files_to_tempfile(gchar **out_filenamep, const char *pfx, cb->callback_func(MERGE_EVENT_FRAME_TYPE_SELECTED, frame_type, in_files, in_file_count, cb->data); /* prepare the outfile */ + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; + params.encap = frame_type; + params.snaplen = snaplen; if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) { shb_hdrs = create_shb_header(in_files, in_file_count, app_name); merge_debug("merge_files: SHB created"); @@ -1123,21 +1122,11 @@ merge_files_to_tempfile(gchar **out_filenamep, const char *pfx, merge_debug("merge_files: IDB merge operation complete, got %u IDBs", idb_inf ? idb_inf->interface_data->len : 0); /* XXX other blocks like NRB are now discarded. */ - const wtapng_dump_params ng_params = { - .shb_hdrs = shb_hdrs, - .idb_inf = idb_inf, - }; - pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type, - frame_type, snaplen, - FALSE /* compressed */, - &ng_params, err); - } - else { - pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type, frame_type, - snaplen, FALSE /* compressed */, - NULL, err); + params.shb_hdrs = shb_hdrs; + params.idb_inf = idb_inf; } - + pdh = wtap_dump_open_tempfile(out_filenamep, pfx, file_type, + FALSE /* compressed */, ¶ms, err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); @@ -1220,6 +1209,9 @@ merge_files_to_stdout(const int file_type, const char *const *in_filenames, cb->callback_func(MERGE_EVENT_FRAME_TYPE_SELECTED, frame_type, in_files, in_file_count, cb->data); /* prepare the outfile */ + wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; + params.encap = frame_type; + params.snaplen = snaplen; if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) { shb_hdrs = create_shb_header(in_files, in_file_count, app_name); merge_debug("merge_files: SHB created"); @@ -1228,18 +1220,10 @@ merge_files_to_stdout(const int file_type, const char *const *in_filenames, merge_debug("merge_files: IDB merge operation complete, got %u IDBs", idb_inf ? idb_inf->interface_data->len : 0); /* XXX other blocks like NRB are now discarded. */ - const wtapng_dump_params ng_params = { - .shb_hdrs = shb_hdrs, - .idb_inf = idb_inf, - }; - pdh = wtap_dump_open_stdout(file_type, frame_type, snaplen, - FALSE /* compressed */, &ng_params, err); - } - else { - pdh = wtap_dump_open_stdout(file_type, frame_type, snaplen, - FALSE /* compressed */, NULL, err); + params.shb_hdrs = shb_hdrs; + params.idb_inf = idb_inf; } - + pdh = wtap_dump_open_stdout(file_type, FALSE /* compressed */, ¶ms, err); if (pdh == NULL) { merge_close_in_files(in_file_count, in_files); g_free(in_files); diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 54b60afa57..7d19e0aed4 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -792,12 +792,14 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_ g_array_append_val(idb_inf->interface_data, int_data); - const wtapng_dump_params ng_params = { + const wtap_dump_params params = { + .encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU, + .snaplen = WTAP_MAX_PACKET_SIZE_STANDARD, .shb_hdrs = shb_hdrs, .idb_inf = idb_inf, }; - wdh_exp_pdu = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU, - WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, &ng_params, &exp_pdu_file_err); + wdh_exp_pdu = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, + FALSE, ¶ms, &exp_pdu_file_err); if (wdh_exp_pdu == NULL) { result = WTAP_OPEN_ERROR; goto end; diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 3b7ac5610d..4f73628393 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -316,20 +316,21 @@ wtap_file_get_nrb_for_new_file(wtap *wth) } void -wtap_dump_params_init(wtapng_dump_params *params, wtap *wth) +wtap_dump_params_init(wtap_dump_params *params, wtap *wth) { memset(params, 0, sizeof(*params)); - if (wth == NULL) return; + params->encap = wtap_file_encap(wth); + params->snaplen = wtap_snapshot_length(wth); params->shb_hdrs = wtap_file_get_shb_for_new_file(wth); params->idb_inf = wtap_file_get_idb_info(wth); params->nrb_hdrs = wtap_file_get_nrb_for_new_file(wth); } void -wtap_dump_params_cleanup(wtapng_dump_params *params) +wtap_dump_params_cleanup(wtap_dump_params *params) { wtap_block_array_free(params->shb_hdrs); /* params->idb_inf is currently expected to be freed by the caller. */ diff --git a/wiretap/wtap.h b/wiretap/wtap.h index ca30c2c3cd..374c1ad3ba 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1422,26 +1422,27 @@ typedef struct addrinfo_lists { } addrinfo_lists_t; /** - * Parameters for various wtap_dump_*_ng functions, controlling additional - * blocks to be written. The structure itself is no longer used after returning - * from wtap_dump_*_ng, but its fields must remain valid until wtap_dump_close - * is called. + * Parameters for various wtap_dump_* functions, specifying per-file + * information. The structure itself is no longer used after returning + * from wtap_dump_*, but its pointer fields must remain valid until + * wtap_dump_close is called. * * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until * wtap_dump_close() is called, but will not be free'd by the dumper. If * you created them, you must free them yourself after wtap_dump_close(). * - * @see wtapng_dump_params_init, wtapng_dump_params_cleanup. + * @see wtap_dump_params_init, wtap_dump_params_cleanup. */ -typedef struct wtapng_dump_params { +typedef struct wtap_dump_params { + int encap; /**< Per-file packet encapsulation, or WTAP_ENCAP_PER_PACKET */ + int snaplen; /**< Per-file snapshot length (what if it's per-interface?) */ GArray *shb_hdrs; /**< The section header block(s) information, or NULL. */ wtapng_iface_descriptions_t *idb_inf; /**< The interface description information, or NULL. */ GArray *nrb_hdrs; /**< The name resolution blocks(s) comment/custom_opts information, or NULL. */ -} wtapng_dump_params; - -/* Zero-initializer for wtapng_dump_params. */ -#define WTAPNG_DUMP_PARAMS_INIT {.idb_inf=0} +} wtap_dump_params; +/* Zero-initializer for wtap_dump_params. */ +#define WTAP_DUMP_PARAMS_INIT {.snaplen=0} struct wtap_dumper; @@ -1873,39 +1874,37 @@ WS_DLL_PUBLIC gboolean wtap_dump_supports_comment_types(int filetype, guint32 comment_types); /** - * Initialize the initial pcapng blocks based on an existing file. Its contents - * must be freed according to the requirements of wtapng_dump_params. + * Initialize the per-file information based on an existing file. Its + * contents must be freed according to the requirements of wtap_dump_params. * - * @param params The parameters for wtap_dump_*_ng to initialize. + * @param params The parameters for wtap_dump_* to initialize. * @param wth The wiretap session. */ WS_DLL_PUBLIC -void wtap_dump_params_init(wtapng_dump_params *params, wtap *wth); +void wtap_dump_params_init(wtap_dump_params *params, wtap *wth); /** - * Free memory associated with the wtapng_dump_params when it is no longer in + * Free memory associated with the wtap_dump_params when it is no longer in * use by wtap_dumper. * - * @param params The parameters as initialized by wtapng_dump_params_init. + * @param params The parameters as initialized by wtap_dump_params_init. */ WS_DLL_PUBLIC -void wtap_dump_params_cleanup(wtapng_dump_params *params); +void wtap_dump_params_cleanup(wtap_dump_params *params); /** * @brief Opens a new capture file for writing. * * @param filename The new file's name. * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) - * @param snaplen The maximum packet capture length. * @param compressed True if file should be compressed. - * @param ng_blocks The initial pcapng blocks to be written, or NULL for non-pcapng. + * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC -wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap, - int snaplen, gboolean compressed, const wtapng_dump_params *ng_blocks, int *err); +wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, + gboolean compressed, const wtap_dump_params *params, int *err); /** * @brief Creates a dumper for a temporary file. @@ -1914,33 +1913,29 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc * pathname of the temporary file; it's allocated with g_malloc() * @param pfx A string to be used as the prefix for the temporary file name * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) - * @param snaplen The maximum packet capture length. * @param compressed True if file should be compressed. - * @param ng_blocks The initial pcapng blocks to be written, or NULL for non-pcapng. + * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx, - int file_type_subtype, int encap, int snaplen, gboolean compressed, - const wtapng_dump_params *ng_blocks, int *err); + int file_type_subtype, gboolean compressed, + const wtap_dump_params *params, int *err); /** * @brief Creates a dumper for an existing file descriptor. * * @param fd The file descriptor for which the dumper should be created. * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. - * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) - * @param snaplen The maximum packet capture length. * @param compressed True if file should be compressed. - * @param ng_blocks The initial pcapng blocks to be written, or NULL for non-pcapng. + * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC -wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen, - gboolean compressed, const wtapng_dump_params *ng_blocks, int *err); +wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, + gboolean compressed, const wtap_dump_params *params, int *err); /** * @brief Creates a dumper for the standard output. @@ -1949,13 +1944,13 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) * @param snaplen The maximum packet capture length. * @param compressed True if file should be compressed. - * @param ng_blocks The initial pcapng blocks to be written, or NULL for non-pcapng. + * @param params The per-file information for this file. * @param[out] err Will be set to an error code on failure. * @return The newly created dumper object, or NULL on failure. */ WS_DLL_PUBLIC -wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen, - gboolean compressed, const wtapng_dump_params *ng_blocks, int *err); +wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, + gboolean compressed, const wtap_dump_params *params, int *err); WS_DLL_PUBLIC gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *, |