aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-20 00:13:37 -0800
committerGuy Harris <gharris@sonic.net>2021-02-20 01:36:26 -0800
commit1f595c435c1476a24e2b443a768185ac2503087a (patch)
treed608bd80e5b357c5b11270089629dec883aabc5f /wiretap
parentc80c16759ba23e29c70ec8fbe62e0a9870685a66 (diff)
BER: get rid of WTAP_FILE_TYPE_SUBTYPE_BER.
Save a copy of the pathname used to open a file in the wtap structure. This allows the BER file reader to put a pointer to it in the pseudo-header; it also would allow file readers to attempt to read "associated" files that have the same name as the file, but with a different extension. Instead of having cf_open() special-case BER files, and calling a routine in the BER dissector to specify the file name to the dissector, have separate dissectors for "dissect packet payload as BER" and "dissect a file as BER", and have the latter get the pathname of the file from the pseudo-header and determine the ASN.1 syntax from that. (Side-effect - this means that you can now dissect a BER file, and have the syntax be determined by the file extension, in TShark as well; the above cf_open() special-casing was *not* done in TShark, so it didn't work before. Now the application code doesn't need to do any of that, so it works in TShark as well as Wireshark.)
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/ber.c51
-rw-r--r--wiretap/file_access.c10
-rw-r--r--wiretap/wtap-int.h2
-rw-r--r--wiretap/wtap.c2
-rw-r--r--wiretap/wtap.h6
5 files changed, 60 insertions, 11 deletions
diff --git a/wiretap/ber.c b/wiretap/ber.c
index c6bdd9c600..789f93993c 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -22,6 +22,34 @@
#define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */
#define BER_UNI_TAG_SET 17 /* SET, SET OF */
+static int ber_file_type_subtype = -1;
+
+void register_ber(void);
+
+static gboolean ber_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf,
+ int *err, gchar **err_info,
+ gint64 *data_offset)
+{
+ if (!wtap_full_file_read(wth, rec, buf, err, err_info, data_offset))
+ return FALSE;
+
+ /* Pass the file name. */
+ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname;
+ return TRUE;
+}
+
+static gboolean ber_full_file_seek_read(wtap *wth, gint64 seek_off,
+ wtap_rec *rec, Buffer *buf,
+ int *err, gchar **err_info)
+{
+ if (!wtap_full_file_seek_read(wth, seek_off, rec, buf, err, err_info))
+ return FALSE;
+
+ /* Pass the file name. */
+ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname;
+ return TRUE;
+}
+
wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info)
{
#define BER_BYTES_TO_CHECK 8
@@ -90,17 +118,34 @@ wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BER;
+ wth->file_type_subtype = ber_file_type_subtype;
wth->file_encap = WTAP_ENCAP_BER;
wth->snapshot_length = 0;
- wth->subtype_read = wtap_full_file_read;
- wth->subtype_seek_read = wtap_full_file_seek_read;
+ wth->subtype_read = ber_full_file_read;
+ wth->subtype_seek_read = ber_full_file_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
return WTAP_OPEN_MINE;
}
+static const struct file_type_subtype_info ber_info = {
+ "ASN.1 Basic Encoding Rules", "ber", NULL, NULL,
+ FALSE, FALSE, 0,
+ NULL, NULL, NULL
+};
+
+void register_ber(void)
+{
+ ber_file_type_subtype = wtap_register_file_type_subtypes(&ber_info);
+
+ /*
+ * Register name for backwards compatibility with the
+ * wtap_filetypes table in Lua.
+ */
+ wtap_register_backwards_compatibility_lua_name("BER", ber_file_type_subtype);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index bc5c0bda21..db93a129a5 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -878,6 +878,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
wth->subtype_sequential_close = NULL;
wth->subtype_close = NULL;
wth->file_tsprec = WTAP_TSPREC_USEC;
+ wth->pathname = g_strdup(filename);
wth->priv = NULL;
wth->wslua_data = NULL;
wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
@@ -1279,12 +1280,7 @@ static const struct file_type_subtype_info file_type_subtype_table_base[] = {
/* WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0 */
{ "AIX iptrace 2.0", "iptrace_2", NULL, NULL,
FALSE, FALSE, 0,
- NULL, NULL, NULL },
-
- /* WTAP_FILE_TYPE_SUBTYPE_BER */
- { "ASN.1 Basic Encoding Rules", "ber", NULL, NULL,
- FALSE, FALSE, 0,
- NULL, NULL, NULL },
+ NULL, NULL, NULL }
};
#define N_DUMP_OPEN_TABLE_BASE_ENTRIES (sizeof(file_type_subtype_table_base) / sizeof(struct file_type_subtype_info))
@@ -2829,8 +2825,6 @@ wtap_register_backwards_compatibility_lua_name(const char *name, int ft)
WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0);
wtap_register_backwards_compatibility_lua_name("IPTRACE_2_0",
WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0);
- wtap_register_backwards_compatibility_lua_name("BER",
- WTAP_FILE_TYPE_SUBTYPE_BER);
}
entry.name = name;
entry.ft = ft;
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 8af29422b2..43d612f1be 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -48,6 +48,8 @@ struct wtap {
GArray *nrb_hdrs; /**< holds the Name Res Block's comment/custom_opts, or NULL */
GArray *dsbs; /**< An array of DSBs (of type wtap_block_t), or NULL if not supported. */
+ char *pathname; /**< File pathname; might just be "-" */
+
void *priv; /* this one holds per-file state and is free'd automatically by wtap_close() */
void *wslua_data; /* this one holds wslua state info and is not free'd */
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index f1d8868bf7..26dab87158 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1441,6 +1441,8 @@ wtap_close(wtap *wth)
g_free(wth->priv);
+ g_free(wth->pathname);
+
if (wth->fast_seek != NULL) {
g_ptr_array_foreach(wth->fast_seek, g_fast_seek_item_free, NULL);
g_ptr_array_free(wth->fast_seek, TRUE);
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 40006d829f..6d345d2cbc 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1133,6 +1133,11 @@ struct netmon_phdr {
} subheader;
};
+/* File "pseudo-header" for BER data files. */
+struct ber_phdr {
+ const char *pathname; /* Path name of file. */
+};
+
union wtap_pseudo_header {
struct eth_phdr eth;
struct dte_dce_phdr dte_dce;
@@ -1160,6 +1165,7 @@ union wtap_pseudo_header {
struct llcp_phdr llcp;
struct logcat_phdr logcat;
struct netmon_phdr netmon;
+ struct ber_phdr ber;
};
/*