aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/visual.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-14 00:34:10 -0800
committerGuy Harris <gharris@sonic.net>2021-02-14 00:58:46 -0800
commitb8b3531883db249be80e217154c7e7fffb86f5bd (patch)
treebecde2c028097baae1b38d8c13b4a9827d0de8b0 /wiretap/visual.c
parent5b3c3d0682c869e6dd19a5245b1a22c90192e9ae (diff)
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in wiretap/file_access.c and, instead, have the file types register themselves, using wtap_register_file_type_subtypes(). This reduces the source code changes needed to add a new file type from three (add the handler, add the file type to the table in file_access.c, add a #define for the file type in wiretap/wtap.h) to one (add the handler). (It also requires adding the handler's source file to wiretap/CMakeLists.txt, but that's required in both cases.) A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used elsewhere; that needs to be fixed. Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now contains a registration routine. In the process, avoid scanning files that don't implement a file type and won't ever have a registration routine. Add a Lua routine to fetch the total number of file types; we use that in some code to construct the wtap_filetypes table, which we need to do in order to continue to have all the values that used to come from the WTAP_FILE_TYPE_SUBTYPE_ types. While we're at it, add modelines to a file that lacked them.
Diffstat (limited to 'wiretap/visual.c')
-rw-r--r--wiretap/visual.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/wiretap/visual.c b/wiretap/visual.c
index 8fd7613b0a..9440a52a0e 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -157,6 +157,10 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err,
gchar **err_info);
static void visual_dump_free(wtap_dumper *wdh);
+static int visual_file_type_subtype = -1;
+
+void register_visual(void);
+
/* Open a file for reading */
wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info)
@@ -236,7 +240,7 @@ wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info)
}
/* Fill in the wiretap struct with data from the file header */
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_VISUAL_NETWORKS;
+ wth->file_type_subtype = visual_file_type_subtype;
wth->file_encap = encap;
wth->snapshot_length = pletoh16(&vfile_hdr.max_length);
@@ -576,7 +580,7 @@ visual_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec,
/* Check for media types that may be written in Visual file format.
Returns 0 if the specified encapsulation type is supported,
an error indication otherwise. */
-int visual_dump_can_write_encap(int encap)
+static int visual_dump_can_write_encap(int encap)
{
/* Per-packet encapsulations aren't supported. */
if (encap == WTAP_ENCAP_PER_PACKET)
@@ -602,7 +606,7 @@ int visual_dump_can_write_encap(int encap)
/* Open a file for writing.
Returns TRUE on success, FALSE on failure; sets "*err" to an
error code on failure */
-gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
+static gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
{
struct visual_write_info *visual;
@@ -857,6 +861,18 @@ static void visual_dump_free(wtap_dumper *wdh)
}
}
+static const struct file_type_subtype_info visual_info = {
+ "Visual Networks traffic capture", "visual", NULL, NULL,
+ TRUE, FALSE, 0,
+ visual_dump_can_write_encap, visual_dump_open, NULL
+};
+
+void register_visual(void)
+{
+ visual_file_type_subtype = wtap_register_file_type_subtypes(&visual_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*