aboutsummaryrefslogtreecommitdiffstats
path: root/reordercap.c
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-11 15:49:12 +0100
committerPeter Wu <peter@lekensteyn.nl>2018-11-12 23:00:44 +0000
commit1e76e1355ab2cafba517a1ba556450ded397d885 (patch)
tree3a5f314fe1170be611080700655a7aab9f42fa17 /reordercap.c
parent791a9a9b8e1ad1c5f2ac31fd5fb830f6b4d30135 (diff)
wiretap: refactor common parameters for pcapng dump routines
Four variants of wtap_dump_open_ng exists, each of them take the same three parameters for the SHB, IDB and NRB blocks that has to be written before packets are even written. Similarly, a lot of tools always create these arguments based on an existing capture file session (wth). Address the former duplication by creating a new data structure to hold the arguments. Address the second issue by creating new helper functions to initialize the parameters based on a wth. This refactoring should make it easier to add the new Decryption Secrets Block (DSB). No functional change intended. Change-Id: I42c019dc1d48a476773459212ca213de91a55684 Reviewed-on: https://code.wireshark.org/review/30578 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'reordercap.c')
-rw-r--r--reordercap.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/reordercap.c b/reordercap.c
index b9a9711e89..466579a171 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -177,9 +177,7 @@ main(int argc, char *argv[])
guint wrong_order_count = 0;
gboolean write_output_regardless = TRUE;
guint i;
- GArray *shb_hdrs = NULL;
- wtapng_iface_descriptions_t *idb_inf = NULL;
- GArray *nrb_hdrs = NULL;
+ wtapng_dump_params ng_params;
int ret = EXIT_SUCCESS;
GPtrArray *frames;
@@ -285,26 +283,23 @@ main(int argc, char *argv[])
}
DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth));
- shb_hdrs = wtap_file_get_shb_for_new_file(wth);
- idb_inf = wtap_file_get_idb_info(wth);
- nrb_hdrs = wtap_file_get_nrb_for_new_file(wth);
+ wtap_dump_params_init(&ng_params, wth);
/* Open outfile (same filetype/encap as input file) */
if (strcmp(outfile, "-") == 0) {
pdh = wtap_dump_open_stdout_ng(wtap_file_type_subtype(wth), wtap_file_encap(wth),
- wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ wtap_snapshot_length(wth), FALSE, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
- wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ wtap_snapshot_length(wth), FALSE, &ng_params, &err);
}
- g_free(idb_inf);
- idb_inf = NULL;
+ g_free(ng_params.idb_inf);
+ ng_params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_message("reordercap", outfile, err,
wtap_file_type_subtype(wth));
- wtap_block_array_free(shb_hdrs);
- wtap_block_array_free(nrb_hdrs);
+ wtap_dump_params_cleanup(&ng_params);
ret = OUTPUT_FILE_ERROR;
goto clean_exit;
}
@@ -371,13 +366,11 @@ main(int argc, char *argv[])
/* Close outfile */
if (!wtap_dump_close(pdh, &err)) {
cfile_close_failure_message(outfile, err);
- wtap_block_array_free(shb_hdrs);
- wtap_block_array_free(nrb_hdrs);
+ wtap_dump_params_cleanup(&ng_params);
ret = OUTPUT_FILE_ERROR;
goto clean_exit;
}
- wtap_block_array_free(shb_hdrs);
- wtap_block_array_free(nrb_hdrs);
+ wtap_dump_params_cleanup(&ng_params);
/* Finally, close infile and release resources. */
wtap_close(wth);