From 1e76e1355ab2cafba517a1ba556450ded397d885 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 11 Nov 2018 15:49:12 +0100 Subject: 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 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris Reviewed-by: Peter Wu --- ui/tap_export_pdu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ui/tap_export_pdu.c') diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index 05e017f5a0..a6eea7d924 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -140,14 +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 = { + .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_ng(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, - exp_pdu_tap_data->shb_hdrs, exp_pdu_tap_data->idb_inf, NULL, &err); + &ng_params, &err); } else { exp_pdu_tap_data->wdh = wtap_dump_fdopen_ng(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE, - exp_pdu_tap_data->shb_hdrs, exp_pdu_tap_data->idb_inf, NULL, &err); + &ng_params, &err); } if (exp_pdu_tap_data->wdh == NULL) { g_assert(err != 0); -- cgit v1.2.3