Skip to content

Commit

Permalink
tap_export_pdu: finish the job of reporting errors.
Browse files Browse the repository at this point in the history
Provide the pathname of the file, and the frame number, to the error
routines.
  • Loading branch information
guyharris committed Mar 15, 2021
1 parent 8795edd commit 9bf838b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ui/export_pdu_ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 12 additions & 3 deletions ui/tap_export_pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions ui/tap_export_pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand Down

0 comments on commit 9bf838b

Please sign in to comment.