From 9bf838b2eabb888a6618e7213a9a37c6f3a32569 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 15 Mar 2021 14:52:12 -0700 Subject: [PATCH] tap_export_pdu: finish the job of reporting errors. Provide the pathname of the file, and the frame number, to the error routines. --- tshark.c | 2 +- ui/export_pdu_ui_utils.c | 4 ++-- ui/tap_export_pdu.c | 15 ++++++++++++--- ui/tap_export_pdu.h | 6 ++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tshark.c b/tshark.c index 10bf2249e73..6378afd8bad 100644 --- a/tshark.c +++ b/tshark.c @@ -2074,7 +2074,7 @@ main(int argc, char *argv[]) /* Write to our output file with this comment (if the type supports it, * otherwise exp_pdu_open() will ignore the comment) */ comment = g_strdup_printf("Dump of PDUs from %s", cf_name); - exp_pdu_status = exp_pdu_open(&exp_pdu_tap_data, + exp_pdu_status = exp_pdu_open(&exp_pdu_tap_data, exp_pdu_filename, out_file_type, exp_fd, comment, &err, &err_info); g_free(comment); diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c index c9a7c1c8782..97195ff3693 100644 --- a/ui/export_pdu_ui_utils.c +++ b/ui/export_pdu_ui_utils.c @@ -64,8 +64,8 @@ do_export_pdu(const char *filter, const gchar *tap_name) file_type_subtype = wtap_pcapng_file_type_subtype(); /* ...with this comment */ comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename); - status = exp_pdu_open(&exp_pdu_tap_data, file_type_subtype, import_file_fd, - comment, &err, &err_info); + status = exp_pdu_open(&exp_pdu_tap_data, capfile_name, file_type_subtype, + import_file_fd, comment, &err, &err_info); g_free(comment); if (!status) { cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file", diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c index 29c56c98173..c7eceb5690b 100644 --- a/ui/tap_export_pdu.c +++ b/ui/tap_export_pdu.c @@ -35,6 +35,11 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const guint8 *packet_buf; tap_packet_status status = TAP_PACKET_DONT_REDRAW; /* no GUI, nothing to redraw */ + /* + * Count this packet. + */ + exp_pdu_tap_data->framenum++; + memset(&rec, 0, sizeof rec); buffer_len = exp_pdu_data->tvb_captured_length + exp_pdu_data->tlv_buffer_len; packet_buf = (guint8 *)g_malloc(buffer_len); @@ -66,7 +71,8 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const /* XXX: should the rec.rec_header.packet_header.pseudo_header be set to the pinfo's pseudo-header? */ if (!wtap_dump(exp_pdu_tap_data->wdh, &rec, packet_buf, &err, &err_info)) { - report_cfile_write_failure(NULL, g_strdup("whatever"), err, err_info, 69, + report_cfile_write_failure(NULL, exp_pdu_tap_data->pathname, + err, err_info, exp_pdu_tap_data->framenum, wtap_dump_file_type_subtype(exp_pdu_tap_data->wdh)); status = TAP_PACKET_FAILED; } @@ -78,8 +84,9 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const } gboolean -exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int file_type_subtype, int fd, - const char *comment, int *err, gchar **err_info) +exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, char *pathname, + int file_type_subtype, int fd, const char *comment, + int *err, gchar **err_info) { /* pcapng defs */ wtap_block_t shb_hdr; @@ -169,6 +176,8 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int file_type_subtype, int fd, if (exp_pdu_tap_data->wdh == NULL) return FALSE; + exp_pdu_tap_data->pathname = pathname; + exp_pdu_tap_data->framenum = 0; /* No frames written yet */ return TRUE; } diff --git a/ui/tap_export_pdu.h b/ui/tap_export_pdu.h index 62208acb3ef..767f53c116e 100644 --- a/ui/tap_export_pdu.h +++ b/ui/tap_export_pdu.h @@ -16,10 +16,12 @@ extern "C" { #endif /* __cplusplus */ typedef struct _exp_pdu_t { + char* pathname; int pkt_encap; wtap_dumper* wdh; GArray* shb_hdrs; wtapng_iface_descriptions_t* idb_inf; + guint32 framenum; } exp_pdu_t; /** @@ -44,8 +46,8 @@ char *exp_pdu_pre_open(const char *tap_name, const char *filter, * the error * @return TRUE on success or FALSE on failure. */ -gboolean exp_pdu_open(exp_pdu_t *data, int file_type_subtype, int fd, - const char *comment, int *err, gchar **err_info); +gboolean exp_pdu_open(exp_pdu_t *data, char *pathname, int file_type_subtype, + int fd, const char *comment, int *err, gchar **err_info); /* Stops the PDUs export. */ gboolean exp_pdu_close(exp_pdu_t *exp_pdu_tap_data, int *err, gchar **err_info);