2003-07-29 19:42:01 +00:00
|
|
|
/* 5views.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2003-07-29 19:42:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "file_wrappers.h"
|
2005-08-02 04:23:39 +00:00
|
|
|
#include "5views.h"
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Signature;
|
|
|
|
guint32 Size; /* Total size of Header in bytes (included Signature) */
|
|
|
|
guint32 Version; /* Identify version and so the format of this record */
|
|
|
|
guint32 DataSize; /* Total size of data included in the Info Record (except the header size) */
|
|
|
|
guint32 FileType; /* Type of the file */
|
|
|
|
guint32 Reserved[3]; /* Reserved for future use */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Info_Header;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Type; /* Id of the attribute */
|
|
|
|
guint16 Size; /* Size of the data part of the attribute (not including header size) */
|
|
|
|
guint16 Nb; /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Attributes_Header;
|
|
|
|
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_INFO_HEADER_KEY 0xAAAAAAAAU /* signature */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_INFO_RECORD_VERSION 0x00010000U /* version */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
#define CST_5VW_DECALE_FILE_TYPE 24
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_SECTION_CAPTURES 0x08U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURES_FILE (CST_5VW_SECTION_CAPTURES << CST_5VW_DECALE_FILE_TYPE) /* 0x08000000 */
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FLAT_FILE 0x10000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURE_FILEID (CST_5VW_FLAT_FILE | CST_5VW_CAPTURES_FILE)
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FAMILY_CAP_ETH 0x01U
|
|
|
|
#define CST_5VW_FAMILY_CAP_WAN 0x02U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_DECALE_FILE_FAMILY 12
|
|
|
|
#define CST_5VW_CAP_ETH (CST_5VW_FAMILY_CAP_ETH << CST_5VW_DECALE_FILE_FAMILY) /* 0x00001000 */
|
|
|
|
#define CST_5VW_CAP_WAN (CST_5VW_FAMILY_CAP_WAN << CST_5VW_DECALE_FILE_FAMILY) /* 0x00002000 */
|
|
|
|
#define CST_5VW_CAPTURE_ETH_FILEID (CST_5VW_CAPTURE_FILEID | CST_5VW_CAP_ETH)
|
|
|
|
#define CST_5VW_CAPTURE_WAN_FILEID (CST_5VW_CAPTURE_FILEID | CST_5VW_CAP_WAN)
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_CAPTURE_FILE_TYPE_MASK 0xFF000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_FRAME_RECORD 0x00000000U
|
|
|
|
#define CST_5VW_RECORDS_HEADER_KEY 0x3333EEEEU
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
t_5VW_Info_Header Info_Header;
|
|
|
|
t_5VW_Attributes_Header HeaderDateCreation;
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Time;
|
2003-07-29 19:42:01 +00:00
|
|
|
t_5VW_Attributes_Header HeaderNbFrames;
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 TramesStockeesInFile;
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_Capture_Header;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-29 20:26:34 +00:00
|
|
|
guint32 Key; /* 0x3333EEEE */
|
|
|
|
guint16 HeaderSize; /* Actual size of this header in bytes (32) */
|
|
|
|
guint16 HeaderType; /* Exact type of this header (0x4000) */
|
|
|
|
guint32 RecType; /* Type of record */
|
|
|
|
guint32 RecSubType; /* Subtype of record */
|
|
|
|
guint32 RecSize; /* Size of one record */
|
|
|
|
guint32 RecNb; /* Number of records */
|
|
|
|
guint32 Utc;
|
|
|
|
guint32 NanoSecondes;
|
|
|
|
guint32 RecInfo; /* Info about Alarm / Event / Frame captured */
|
2003-07-29 19:42:01 +00:00
|
|
|
}t_5VW_TimeStamped_Header;
|
|
|
|
|
|
|
|
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES 0x20000000U
|
|
|
|
#define CST_5VW_IA_DATE_CREATION 0x80000007U /* Struct t_Attrib_Date_Create */
|
|
|
|
#define CST_5VW_TIMESTAMPED_HEADER_TYPE 0x4000U
|
2003-07-29 19:42:01 +00:00
|
|
|
#define CST_5VW_CAPTURES_RECORD (CST_5VW_SECTION_CAPTURES << 28) /* 0x80000000 */
|
2008-02-09 23:35:28 +00:00
|
|
|
#define CST_5VW_SYSTEM_RECORD 0x00000000U
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean _5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset);
|
2018-02-09 00:19:12 +00:00
|
|
|
static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
|
|
|
|
Buffer *buf, int *err, gchar **err_info);
|
2014-05-09 05:18:49 +00:00
|
|
|
static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, int *err, gchar **err_info);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
static gboolean _5views_dump(wtap_dumper *wdh, const wtap_rec *rec, const guint8 *pd, int *err, gchar **err_info);
|
2020-10-14 01:48:46 +00:00
|
|
|
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
static int _5views_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_5views(void);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val
|
|
|
|
_5views_open(wtap *wth, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
t_5VW_Capture_Header Capture_Header;
|
|
|
|
int encap = WTAP_ENCAP_UNKNOWN;
|
|
|
|
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, &Capture_Header.Info_Header,
|
|
|
|
sizeof(t_5VW_Info_Header), err, err_info)) {
|
|
|
|
if (*err != WTAP_ERR_SHORT_READ)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether that's 5Views format or not */
|
|
|
|
if(Capture_Header.Info_Header.Signature != CST_5VW_INFO_HEADER_KEY)
|
|
|
|
{
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check Version */
|
2003-07-29 20:26:34 +00:00
|
|
|
Capture_Header.Info_Header.Version =
|
2013-12-03 20:35:50 +00:00
|
|
|
pletoh32(&Capture_Header.Info_Header.Version);
|
2003-07-29 19:42:01 +00:00
|
|
|
switch (Capture_Header.Info_Header.Version) {
|
|
|
|
|
|
|
|
case CST_5VW_INFO_RECORD_VERSION:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup_printf("5views: header version %u unsupported", Capture_Header.Info_Header.Version);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check File Type */
|
2003-07-29 20:26:34 +00:00
|
|
|
Capture_Header.Info_Header.FileType =
|
2013-12-03 20:35:50 +00:00
|
|
|
pletoh32(&Capture_Header.Info_Header.FileType);
|
2003-07-29 19:42:01 +00:00
|
|
|
if((Capture_Header.Info_Header.FileType & CST_5VW_CAPTURE_FILE_TYPE_MASK) != CST_5VW_CAPTURE_FILEID)
|
|
|
|
{
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup_printf("5views: file is not a capture file (filetype is %u)", Capture_Header.Info_Header.Version);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check possible Encap */
|
|
|
|
switch (Capture_Header.Info_Header.FileType) {
|
|
|
|
case CST_5VW_CAPTURE_ETH_FILEID:
|
|
|
|
encap = WTAP_ENCAP_ETHERNET;
|
|
|
|
break;
|
|
|
|
/* case CST_5VW_CAPTURE_WAN_FILEID:
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
default:
|
2014-12-17 06:22:29 +00:00
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup_printf("5views: network type %u unknown or unsupported",
|
|
|
|
Capture_Header.Info_Header.FileType);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read the remaining header information */
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, &Capture_Header.HeaderDateCreation,
|
|
|
|
sizeof (t_5VW_Capture_Header) - sizeof(t_5VW_Info_Header), err, err_info))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* This is a 5views capture file */
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
wth->file_type_subtype = _5views_file_type_subtype;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->subtype_read = _5views_read;
|
|
|
|
wth->subtype_seek_read = _5views_seek_read;
|
|
|
|
wth->file_encap = encap;
|
|
|
|
wth->snapshot_length = 0; /* not available in header */
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_NSEC;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2020-07-29 08:30:54 +00:00
|
|
|
/*
|
|
|
|
* Add an IDB; we don't know how many interfaces were
|
|
|
|
* involved, so we just say one interface, about which
|
|
|
|
* we only know the link-layer type, snapshot length,
|
|
|
|
* and time stamp resolution.
|
|
|
|
*/
|
|
|
|
wtap_add_generated_idb(wth);
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the next packet */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2019-04-05 01:56:27 +00:00
|
|
|
_5views_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
t_5VW_TimeStamped_Header TimeStamped_Header;
|
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Keep reading until we see a record with a subtype of
|
|
|
|
* CST_5VW_FRAME_RECORD.
|
|
|
|
*/
|
2003-07-29 19:42:01 +00:00
|
|
|
do
|
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2013-05-16 21:19:53 +00:00
|
|
|
|
|
|
|
/* Read record header. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!_5views_read_header(wth, wth->fh, &TimeStamped_Header,
|
2019-04-05 01:56:27 +00:00
|
|
|
rec, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-05-16 21:19:53 +00:00
|
|
|
|
|
|
|
if (TimeStamped_Header.RecSubType == CST_5VW_FRAME_RECORD) {
|
2003-07-29 19:42:01 +00:00
|
|
|
/*
|
2013-05-16 21:19:53 +00:00
|
|
|
* OK, this is a packet.
|
2003-07-29 19:42:01 +00:00
|
|
|
*/
|
2013-05-16 21:19:53 +00:00
|
|
|
break;
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Not a packet - skip to the next record.
|
|
|
|
*/
|
2016-09-29 04:35:12 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, NULL, TimeStamped_Header.RecSize, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
} while (1);
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2011-12-13 00:57:09 +00:00
|
|
|
/*
|
|
|
|
* Probably a corrupt capture file; don't blow up trying
|
|
|
|
* to allocate space for an immensely-large packet.
|
|
|
|
*/
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2011-12-13 00:57:09 +00:00
|
|
|
*err_info = g_strdup_printf("5views: File has %u-byte packet, bigger than maximum of %u",
|
2019-04-05 01:56:27 +00:00
|
|
|
rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2011-12-13 00:57:09 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
return wtap_read_packet_bytes(wth->fh, buf,
|
|
|
|
rec->rec_header.packet_header.caplen, err, err_info);
|
2003-07-29 19:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
_5views_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
|
2014-01-02 20:47:21 +00:00
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2013-05-16 21:19:53 +00:00
|
|
|
t_5VW_TimeStamped_Header TimeStamped_Header;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Read the header.
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!_5views_read_header(wth, wth->random_fh, &TimeStamped_Header,
|
2018-02-09 00:19:12 +00:00
|
|
|
rec, err, err_info)) {
|
2013-12-31 23:30:18 +00:00
|
|
|
if (*err == 0)
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-12-31 23:30:18 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
2018-02-09 00:19:12 +00:00
|
|
|
return wtap_read_packet_bytes(wth->random_fh, buf, rec->rec_header.packet_header.caplen,
|
2014-05-23 10:50:02 +00:00
|
|
|
err, err_info);
|
2013-05-16 21:19:53 +00:00
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-05-16 21:19:53 +00:00
|
|
|
/* Read the header of the next packet. Return TRUE on success, FALSE
|
|
|
|
on error. */
|
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
_5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, int *err, gchar **err_info)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
/* Read record header. */
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes_or_eof(fh, hdr, (unsigned int)sizeof(t_5VW_TimeStamped_Header),
|
|
|
|
err, err_info))
|
2013-05-16 21:19:53 +00:00
|
|
|
return FALSE;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
hdr->Key = pletoh32(&hdr->Key);
|
2013-05-16 21:19:53 +00:00
|
|
|
if (hdr->Key != CST_5VW_RECORDS_HEADER_KEY) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("5views: Time-stamped header has bad key value 0x%08X",
|
|
|
|
hdr->Key);
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
2013-05-16 21:19:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 20:35:50 +00:00
|
|
|
hdr->RecSubType = pletoh32(&hdr->RecSubType);
|
|
|
|
hdr->RecSize = pletoh32(&hdr->RecSize);
|
|
|
|
hdr->Utc = pletoh32(&hdr->Utc);
|
|
|
|
hdr->NanoSecondes = pletoh32(&hdr->NanoSecondes);
|
2013-05-16 21:19:53 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
|
|
|
rec->ts.secs = hdr->Utc;
|
|
|
|
rec->ts.nsecs = hdr->NanoSecondes;
|
|
|
|
rec->rec_header.packet_header.caplen = hdr->RecSize;
|
|
|
|
rec->rec_header.packet_header.len = hdr->RecSize;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
switch (wth->file_encap) {
|
2003-10-01 07:11:49 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET:
|
|
|
|
/* We assume there's no FCS in this frame. */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0;
|
2003-10-01 07:11:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
typedef struct {
|
|
|
|
guint32 nframes;
|
|
|
|
} _5views_dump_t;
|
|
|
|
|
2003-07-29 19:42:01 +00:00
|
|
|
static const int wtap_encap[] = {
|
|
|
|
-1, /* WTAP_ENCAP_UNKNOWN -> unsupported */
|
2011-12-22 09:22:35 +00:00
|
|
|
CST_5VW_CAPTURE_ETH_FILEID, /* WTAP_ENCAP_ETHERNET -> Ethernet */
|
2003-07-29 19:42:01 +00:00
|
|
|
};
|
|
|
|
#define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0])
|
|
|
|
|
|
|
|
/* Returns 0 if we could write the specified encapsulation type,
|
|
|
|
an error indication otherwise. */
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
static int _5views_dump_can_write_encap(int encap)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
|
|
|
/* Per-packet encapsulations aren't supported. */
|
|
|
|
if (encap == WTAP_ENCAP_PER_PACKET)
|
|
|
|
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
|
|
|
|
2014-06-16 22:00:23 +00:00
|
|
|
if (encap < 0 || (unsigned int) encap >= NUM_WTAP_ENCAPS || wtap_encap[encap] == -1)
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
|
|
|
|
failure */
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
static gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* We can't fill in all the fields in the file header, as we
|
|
|
|
haven't yet written any packets. As we'll have to rewrite
|
|
|
|
the header when we've written out all the packets, we just
|
|
|
|
skip over the header for now. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, sizeof(t_5VW_Capture_Header), SEEK_SET, err) == -1)
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* This is a 5Views file */
|
|
|
|
wdh->subtype_write = _5views_dump;
|
2015-11-09 19:54:18 +00:00
|
|
|
wdh->subtype_finish = _5views_dump_finish;
|
2020-12-21 02:30:28 +00:00
|
|
|
_5views = g_new(_5views_dump_t, 1);
|
2010-02-26 07:59:54 +00:00
|
|
|
wdh->priv = (void *)_5views;
|
|
|
|
_5views->nframes = 0;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
Returns TRUE on success, FALSE on failure. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean _5views_dump(wtap_dumper *wdh,
|
2018-02-09 00:19:12 +00:00
|
|
|
const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info _U_)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
|
2013-07-29 07:28:28 +00:00
|
|
|
t_5VW_TimeStamped_Header HeaderFrame;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_type != REC_TYPE_PACKET) {
|
2014-12-18 00:31:49 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_TYPE;
|
2014-05-24 18:28:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Catch attempts to write multiple encapsulation types if unsupported.
If, in the process of opening the input file, we determine that it has
packets of more than one link-layer type, we can catch attempts to write
that file to a file of a format that doesn't support more than one
link-layer type at the time we try to open the output file.
If, however, we don't discover that the file has more than one
link-layer type until we've already created the output file - for
example, if we have a pcapng file with a new IDB, with a different
link-layer type from previous IDBs, after packet blocks for the earlier
interfces - we can't catch that until we try to write the packet.
Currently, that causes the packet's data to be written out as is, so the
output file claims it's of the file's link-layer type, causing programs
reading the file to misdissect the packet.
Report WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on the write attempt
instead, and have a nicer error message for
WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED on a write.
Change-Id: Ic41f2e4367cfe5667eb30c88cc6d3bfe422462f6
Reviewed-on: https://code.wireshark.org/review/30617
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-14 03:38:12 +00:00
|
|
|
/*
|
|
|
|
* Make sure this packet doesn't have a link-layer type that
|
|
|
|
* differs from the one for the file.
|
|
|
|
*/
|
|
|
|
if (wdh->encap != rec->rec_header.packet_header.pkt_encap) {
|
|
|
|
*err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write out something bigger than we can read. */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2014-01-22 00:26:36 +00:00
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-29 19:42:01 +00:00
|
|
|
/* Frame Header */
|
|
|
|
/* constant fields */
|
2013-11-29 18:44:00 +00:00
|
|
|
HeaderFrame.Key = GUINT32_TO_LE(CST_5VW_RECORDS_HEADER_KEY);
|
|
|
|
HeaderFrame.HeaderSize = GUINT16_TO_LE(sizeof(t_5VW_TimeStamped_Header));
|
|
|
|
HeaderFrame.HeaderType = GUINT16_TO_LE(CST_5VW_TIMESTAMPED_HEADER_TYPE);
|
|
|
|
HeaderFrame.RecType = GUINT32_TO_LE(CST_5VW_CAPTURES_RECORD | CST_5VW_SYSTEM_RECORD);
|
|
|
|
HeaderFrame.RecSubType = GUINT32_TO_LE(CST_5VW_FRAME_RECORD);
|
|
|
|
HeaderFrame.RecNb = GUINT32_TO_LE(1);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
2013-07-29 07:28:28 +00:00
|
|
|
/* record-dependent fields */
|
2018-02-09 00:19:12 +00:00
|
|
|
HeaderFrame.Utc = GUINT32_TO_LE(rec->ts.secs);
|
|
|
|
HeaderFrame.NanoSecondes = GUINT32_TO_LE(rec->ts.nsecs);
|
|
|
|
HeaderFrame.RecSize = GUINT32_TO_LE(rec->rec_header.packet_header.len);
|
2013-11-29 18:44:00 +00:00
|
|
|
HeaderFrame.RecInfo = GUINT32_TO_LE(0);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* write the record header */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &HeaderFrame,
|
2010-06-06 22:19:30 +00:00
|
|
|
sizeof(t_5VW_TimeStamped_Header), err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* write the data */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views->nframes ++;
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-14 01:48:46 +00:00
|
|
|
static gboolean _5views_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info _U_)
|
2003-07-29 19:42:01 +00:00
|
|
|
{
|
2010-02-26 07:59:54 +00:00
|
|
|
_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
|
2003-07-29 19:42:01 +00:00
|
|
|
t_5VW_Capture_Header file_hdr;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* fill in the Info_Header */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Info_Header.Signature = GUINT32_TO_LE(CST_5VW_INFO_HEADER_KEY);
|
|
|
|
file_hdr.Info_Header.Size = GUINT32_TO_LE(sizeof(t_5VW_Info_Header)); /* Total size of Header in bytes (included Signature) */
|
|
|
|
file_hdr.Info_Header.Version = GUINT32_TO_LE(CST_5VW_INFO_RECORD_VERSION); /* Identify version and so the format of this record */
|
|
|
|
file_hdr.Info_Header.DataSize = GUINT32_TO_LE(sizeof(t_5VW_Attributes_Header)
|
2003-07-29 20:26:34 +00:00
|
|
|
+ sizeof(guint32)
|
|
|
|
+ sizeof(t_5VW_Attributes_Header)
|
|
|
|
+ sizeof(guint32));
|
|
|
|
/* Total size of data included in the Info Record (except the header size) */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Info_Header.FileType = GUINT32_TO_LE(wtap_encap[wdh->encap]); /* Type of the file */
|
2003-07-29 20:26:34 +00:00
|
|
|
file_hdr.Info_Header.Reserved[0] = 0; /* Reserved for future use */
|
|
|
|
file_hdr.Info_Header.Reserved[1] = 0; /* Reserved for future use */
|
|
|
|
file_hdr.Info_Header.Reserved[2] = 0; /* Reserved for future use */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the HeaderDateCreation */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.HeaderDateCreation.Type = GUINT32_TO_LE(CST_5VW_IA_DATE_CREATION); /* Id of the attribute */
|
|
|
|
file_hdr.HeaderDateCreation.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */
|
|
|
|
file_hdr.HeaderDateCreation.Nb = GUINT16_TO_LE(1); /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the Time field */
|
|
|
|
#ifdef _WIN32
|
|
|
|
_tzset();
|
|
|
|
#endif
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.Time = GUINT32_TO_LE(time(NULL));
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the Time field */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.HeaderNbFrames.Type = GUINT32_TO_LE(CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES); /* Id of the attribute */
|
|
|
|
file_hdr.HeaderNbFrames.Size = GUINT16_TO_LE(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */
|
|
|
|
file_hdr.HeaderNbFrames.Nb = GUINT16_TO_LE(1); /* Number of elements */
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* fill in the number of frames saved */
|
2013-11-29 18:44:00 +00:00
|
|
|
file_hdr.TramesStockeesInFile = GUINT32_TO_LE(_5views->nframes);
|
2003-07-29 19:42:01 +00:00
|
|
|
|
|
|
|
/* Write the file header. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header),
|
2010-06-06 22:19:30 +00:00
|
|
|
err))
|
2003-07-29 19:42:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-01-02 00:45:22 +00:00
|
|
|
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
static const struct supported_block_type _5views_blocks_supported[] = {
|
|
|
|
/*
|
|
|
|
* We support packet blocks, with no comments or other options.
|
|
|
|
*/
|
|
|
|
{ WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED }
|
|
|
|
};
|
|
|
|
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
static const struct file_type_subtype_info _5views_info = {
|
|
|
|
"InfoVista 5View capture", "5views", "5vw", NULL,
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
TRUE, BLOCKS_SUPPORTED(_5views_blocks_supported),
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
_5views_dump_can_write_encap, _5views_dump_open, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void register_5views(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
_5views_file_type_subtype = wtap_register_file_type_subtype(&_5views_info);
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register name for backwards compatibility with the
|
|
|
|
* wtap_filetypes table in Lua.
|
|
|
|
*/
|
|
|
|
wtap_register_backwards_compatibility_lua_name("5VIEWS",
|
|
|
|
_5views_file_type_subtype);
|
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.
2021-02-14 08:34:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2015-01-02 00:45:22 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|