tap_export_pdu: finish the job of reporting errors.

Provide the pathname of the file, and the frame number, to the error
routines.
This commit is contained in:
Guy Harris 2021-03-15 14:52:12 -07:00
parent 8795edd57c
commit 9bf838b2ea
4 changed files with 19 additions and 8 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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;
}

View File

@ -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);