diff options
author | Guy Harris <gharris@sonic.net> | 2021-02-14 00:34:10 -0800 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2021-02-14 00:58:46 -0800 |
commit | b8b3531883db249be80e217154c7e7fffb86f5bd (patch) | |
tree | becde2c028097baae1b38d8c13b4a9827d0de8b0 /wiretap/nettl.c | |
parent | 5b3c3d0682c869e6dd19a5245b1a22c90192e9ae (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/nettl.c')
-rw-r--r-- | wiretap/nettl.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 65d654cd5a..e698b5b3b7 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -173,6 +173,10 @@ static gboolean nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, static gboolean nettl_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info); +static int nettl_file_type_subtype = -1; + +void register_nettl(void); + wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) { struct nettl_file_hdr file_hdr; @@ -200,7 +204,7 @@ wtap_open_return_val nettl_open(wtap *wth, int *err, gchar **err_info) return WTAP_OPEN_ERROR; /* This is an nettl file */ - wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETTL; + wth->file_type_subtype = nettl_file_type_subtype; nettl = g_new(nettl_t,1); wth->priv = (void *)nettl; if (file_hdr.os_vers[2] == '1' && file_hdr.os_vers[3] == '1') @@ -613,7 +617,7 @@ nettl_read_rec(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, when they are first opened, so we allow that for tshark read/write. */ -int nettl_dump_can_write_encap(int encap) +static int nettl_dump_can_write_encap(int encap) { switch (encap) { @@ -642,7 +646,7 @@ int nettl_dump_can_write_encap(int encap) /* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on failure */ -gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) +static gboolean nettl_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) { struct nettl_file_hdr file_hdr; @@ -793,6 +797,18 @@ static gboolean nettl_dump(wtap_dumper *wdh, return TRUE; } +static const struct file_type_subtype_info nettl_info = { + "HP-UX nettl trace", "nettl", "trc0", "trc1", + FALSE, FALSE, 0, + nettl_dump_can_write_encap, nettl_dump_open, NULL +}; + +void register_nettl(void) +{ + nettl_file_type_subtype = wtap_register_file_type_subtypes(&nettl_info, + WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * |