aboutsummaryrefslogtreecommitdiffstats
path: root/file.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 /file.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 'file.c')
-rw-r--r--file.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/file.c b/file.c
index 299c0e3ae8..731934c973 100644
--- a/file.c
+++ b/file.c
@@ -4448,15 +4448,11 @@ 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. */
- GArray *shb_hdrs = NULL;
- wtapng_iface_descriptions_t *idb_inf = NULL;
- GArray *nrb_hdrs = NULL;
+ wtapng_dump_params ng_params;
int encap;
- /* XXX: what free's this shb_hdr? */
- shb_hdrs = wtap_file_get_shb_for_new_file(cf->provider.wth);
- idb_inf = wtap_file_get_idb_info(cf->provider.wth);
- nrb_hdrs = wtap_file_get_nrb_for_new_file(cf->provider.wth);
+ /* XXX: what free's ng_params.shb_hdr? */
+ wtap_dump_params_init(&ng_params, cf->provider.wth);
/* Determine what file encapsulation type we should use. */
encap = wtap_dump_file_encap_type(cf->linktypes);
@@ -4471,13 +4467,14 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
from which we're reading the packets that we're writing!) */
fname_new = g_strdup_printf("%s~", fname);
pdh = wtap_dump_open_ng(fname_new, save_format, encap, cf->snap,
- compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ compressed, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
- compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ compressed, &ng_params, &err);
}
- g_free(idb_inf);
- idb_inf = NULL;
+ /* XXX idb_inf is documented to be used until wtap_dump_close. */
+ g_free(ng_params.idb_inf);
+ ng_params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_alert_box(fname, err, save_format);
@@ -4698,9 +4695,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
int err;
wtap_dumper *pdh;
save_callback_args_t callback_args;
- GArray *shb_hdrs = NULL;
- wtapng_iface_descriptions_t *idb_inf = NULL;
- GArray *nrb_hdrs = NULL;
+ wtapng_dump_params ng_params;
int encap;
packet_range_process_init(range);
@@ -4710,10 +4705,8 @@ 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 this shb_hdr? */
- shb_hdrs = wtap_file_get_shb_for_new_file(cf->provider.wth);
- idb_inf = wtap_file_get_idb_info(cf->provider.wth);
- nrb_hdrs = wtap_file_get_nrb_for_new_file(cf->provider.wth);
+ /* XXX: what free's ng_params.shb_hdr? */
+ wtap_dump_params_init(&ng_params, cf->provider.wth);
/* Determine what file encapsulation type we should use. */
encap = wtap_dump_file_encap_type(cf->linktypes);
@@ -4728,13 +4721,14 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
from which we're reading the packets that we're writing!) */
fname_new = g_strdup_printf("%s~", fname);
pdh = wtap_dump_open_ng(fname_new, save_format, encap, cf->snap,
- compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ compressed, &ng_params, &err);
} else {
pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
- compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
+ compressed, &ng_params, &err);
}
- g_free(idb_inf);
- idb_inf = NULL;
+ /* XXX idb_inf is documented to be used until wtap_dump_close. */
+ g_free(ng_params.idb_inf);
+ ng_params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_alert_box(fname, err, save_format);