aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-23 01:18:31 -0800
committerGuy Harris <gharris@sonic.net>2021-02-23 21:56:20 +0000
commit166159f15d24cea75934b9e435e925254d141ae9 (patch)
treef95f098cb6d119d2e2481223bab2a1db449ec7ba /ui
parent3742f921b2e54373483df1e9e78b7421bd32bd69 (diff)
wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.
Register the pcap and pcapng file types/subtypes rather than hardwiring them into the table. Call the registration routines for them directly, rather than through a generated table; they're always supposed to be there, as some code in Wireshark either writes only one of those formats or defaults to writing one of those formats. Don't run their source code through the registration-routine-finder script. Have the file type/subtype codes for them be directly exported to the libwiretap core, and provide routines to return each of them, to be used by the aforementioned code. When reporting errors with cfile_write_failure_message(), use wtap_dump_file_type_subtype() to get the file type/subtype value for the wtap_dumper to which we're writing, rather than hardcoding it. Have the "export PDU" code capable of supporting arbitrary file types/subtypes, although we currently only use pcapng. Get rid of declarations of now-static can_write_encap and dump_open routines in various headers.
Diffstat (limited to 'ui')
-rw-r--r--ui/export_pdu_ui_utils.c11
-rw-r--r--ui/qt/import_text_dialog.cpp7
-rw-r--r--ui/qt/main_window.cpp3
-rw-r--r--ui/tap_export_pdu.c104
-rw-r--r--ui/tap_export_pdu.h4
5 files changed, 78 insertions, 51 deletions
diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c
index f20170f78b..39e9cdbd37 100644
--- a/ui/export_pdu_ui_utils.c
+++ b/ui/export_pdu_ui_utils.c
@@ -34,6 +34,7 @@ static void
exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
{
int import_file_fd;
+ int file_type_subtype;
char *capfile_name, *comment;
gboolean status;
int err;
@@ -48,14 +49,16 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
goto end;
}
+ /* Write a pcapng file... */
+ 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, import_file_fd, comment, &err,
- &err_info);
+ status = exp_pdu_open(exp_pdu_tap_data, 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",
- err, err_info,
- WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
+ err, err_info, file_type_subtype);
goto end;
}
diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp
index 7e9e461d01..89301ac901 100644
--- a/ui/qt/import_text_dialog.cpp
+++ b/ui/qt/import_text_dialog.cpp
@@ -124,19 +124,22 @@ void ImportTextDialog::convertTextFile() {
int err;
gchar *err_info;
wtap_dump_params params;
+ int file_type_subtype;
capfile_name_.clear();
wtap_dump_params_init(&params, NULL);
params.encap = import_info_.encapsulation;
params.snaplen = import_info_.max_frame_length;
params.tsprec = WTAP_TSPREC_USEC; /* XXX - support other precisions? */
+ /* Write a pcapng temporary file */
+ file_type_subtype = wtap_pcapng_file_type_subtype();
/* Use a random name for the temporary import buffer */
- import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_UNCOMPRESSED, &params, &err, &err_info);
+ import_info_.wdh = wtap_dump_open_tempfile(&tmpname, "import", file_type_subtype, WTAP_UNCOMPRESSED, &params, &err, &err_info);
capfile_name_.append(tmpname ? tmpname : "temporary file");
g_free(tmpname);
qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length;
if (import_info_.wdh == NULL) {
- cfile_dump_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, err_info, WTAP_FILE_TYPE_SUBTYPE_PCAP);
+ cfile_dump_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, err_info, file_type_subtype);
fclose(import_info_.import_text_file);
setResult(QDialog::Rejected);
return;
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 0af5047d2a..9a13c1f901 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -1041,7 +1041,8 @@ void MainWindow::dropEvent(QDropEvent *event)
/* merge the files in chronological order */
if (cf_merge_files_to_tempfile(this, &tmpname, local_files.size(),
- in_filenames, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
+ in_filenames,
+ wtap_pcapng_file_type_subtype(),
FALSE) == CF_OK) {
/* Merge succeeded; close the currently-open file and try
to open the merged capture file. */
diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c
index 22915b8a1b..e699a3b938 100644
--- a/ui/tap_export_pdu.c
+++ b/ui/tap_export_pdu.c
@@ -85,8 +85,8 @@ 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 fd, const char *comment, int *err,
- gchar **err_info)
+exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, int file_type_subtype,
+ const char *comment, int *err, gchar **err_info)
{
/* pcapng defs */
wtap_block_t shb_hdr;
@@ -96,49 +96,69 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment, int *err,
gsize opt_len;
gchar *opt_str;
- /* Create data for SHB */
- os_info_str = g_string_new("");
- get_os_version_info(os_info_str);
-
- shb_hdr = wtap_block_create(WTAP_BLOCK_SECTION);
-
- /* options */
- wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
-
/*
- * UTF-8 string containing the name of the operating system used to create
- * this section.
+ * If the file format supports a section block, and the section
+ * block supports comments, create data for it.
*/
- opt_len = os_info_str->len;
- opt_str = g_string_free(os_info_str, FALSE);
- if (opt_str) {
- wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
- g_free(opt_str);
+ if (wtap_file_type_subtype_supports_block(file_type_subtype,
+ WTAP_BLOCK_SECTION) != BLOCK_NOT_SUPPORTED &&
+ wtap_file_type_subtype_supports_option(file_type_subtype,
+ WTAP_BLOCK_SECTION,
+ OPT_COMMENT) != OPTION_NOT_SUPPORTED) {
+ os_info_str = g_string_new("");
+ get_os_version_info(os_info_str);
+
+ shb_hdr = wtap_block_create(WTAP_BLOCK_SECTION);
+
+ /* options */
+ wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
+
+ /*
+ * UTF-8 string containing the name of the operating system used to
+ * create this section.
+ */
+ opt_len = os_info_str->len;
+ opt_str = g_string_free(os_info_str, FALSE);
+ if (opt_str) {
+ wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
+ g_free(opt_str);
+ }
+ /*
+ * UTF-8 string containing the name of the application used to create
+ * this section.
+ */
+ wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "%s",
+ get_appname_and_version());
+
+ 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);
+ } else {
+ exp_pdu_tap_data->shb_hdrs = NULL;
}
+
/*
- * UTF-8 string containing the name of the application used to create
- * this section.
+ * Create a fake IDB even if it's not supported; that provides a
+ * link-layer type
*/
- wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "%s", get_appname_and_version());
-
- /* Create fake IDB info */
- exp_pdu_tap_data->idb_inf = g_new(wtapng_iface_descriptions_t,1);
- exp_pdu_tap_data->idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
-
- /* create the fake interface data */
- int_data = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO);
- int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
- int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
- int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
- int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE_STANDARD;
-
- wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
- wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9);
-
- g_array_append_val(exp_pdu_tap_data->idb_inf->interface_data, int_data);
-
- 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);
+ if (wtap_file_type_subtype_supports_block(file_type_subtype,
+ WTAP_BLOCK_IF_ID_AND_INFO) != BLOCK_NOT_SUPPORTED) {
+ exp_pdu_tap_data->idb_inf = g_new(wtapng_iface_descriptions_t,1);
+ exp_pdu_tap_data->idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+
+ /* create the fake interface data */
+ int_data = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO);
+ int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
+ int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
+ int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
+ int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE_STANDARD;
+
+ wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
+ wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9);
+
+ g_array_append_val(exp_pdu_tap_data->idb_inf->interface_data, int_data);
+ } else {
+ exp_pdu_tap_data->idb_inf = NULL;
+ }
const wtap_dump_params params = {
.encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU,
@@ -147,10 +167,10 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment, int *err,
.idb_inf = exp_pdu_tap_data->idb_inf,
};
if (fd == 1) {
- exp_pdu_tap_data->wdh = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
+ exp_pdu_tap_data->wdh = wtap_dump_open_stdout(file_type_subtype,
WTAP_UNCOMPRESSED, &params, err, err_info);
} else {
- exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
+ exp_pdu_tap_data->wdh = wtap_dump_fdopen(fd, file_type_subtype,
WTAP_UNCOMPRESSED, &params, err, err_info);
}
if (exp_pdu_tap_data->wdh == NULL)
diff --git a/ui/tap_export_pdu.h b/ui/tap_export_pdu.h
index 133abd43ff..62208acb3e 100644
--- a/ui/tap_export_pdu.h
+++ b/ui/tap_export_pdu.h
@@ -44,8 +44,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 fd, const char *comment, int *err,
- gchar **err_info);
+gboolean exp_pdu_open(exp_pdu_t *data, 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);