2001-10-19 20:18:48 +00:00
|
|
|
/* dbs-etherwatch.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
2003-01-17 23:54:19 +00:00
|
|
|
* Copyright (c) 2001 by Marc Milgram <ethereal@mmilgram.NOSPAMmail.net>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "dbs-etherwatch.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* This module reads the text output of the 'DBS-ETHERTRACE' command in VMS
|
|
|
|
* It was initially based on vms.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-12-07 01:18:17 +00:00
|
|
|
Example 'ETHERWATCH' output data (with "printable" characters in the
|
|
|
|
"printable characters" section of the output replaced by "." if they have
|
|
|
|
the 8th bit set, so as not to upset compilers that are expecting text
|
|
|
|
in comments to be in a particular character encoding that can't handle
|
|
|
|
those values):
|
2001-10-19 20:18:48 +00:00
|
|
|
ETHERWATCH X5-008
|
|
|
|
42 names and addresses were loaded
|
|
|
|
Reading recorded data from PERSISTENCE
|
|
|
|
------------------------------------------------------------------------------
|
2002-03-04 00:25:35 +00:00
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
2001-10-19 20:18:48 +00:00
|
|
|
Protocol 08-00 00 00-00-00-00-00, 60 byte buffer at 10-OCT-2001 10:20:45.16
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..<8...........]- 0-[45 00 00 3C 38 93 00 00 1D 06 D2 12 80 93 11 1A]
|
|
|
|
[.........(......]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 90 00 00 00 00]
|
|
|
|
[................]- 32-[A0 02 FF FF 95 BD 00 00 02 04 05 B4 03 03 04 01]
|
|
|
|
[............ ]- 48-[01 01 08 0A 90 90 E5 14 00 00 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
------------------------------------------------------------------------------
|
2002-03-04 00:25:35 +00:00
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
2001-10-19 20:18:48 +00:00
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..(8......%....]- 0-[45 00 00 28 38 94 00 00 1D 06 D2 25 80 93 11 1A]
|
|
|
|
[.........(..Z.4w]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 91 5A 1C 34 77]
|
|
|
|
[P.#(.s..........]- 32-[50 10 23 28 C1 73 00 00 02 04 05 B4 03 03 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
[.. ]- 48-[02 04]
|
2003-12-29 00:36:12 +00:00
|
|
|
|
|
|
|
|
2006-05-28 15:56:15 +00:00
|
|
|
Alternative HEX only output, slightly more efficient and all wireshark needs:
|
2003-12-29 00:36:12 +00:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
|
|
|
0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A 80 93 80 D6]
|
|
|
|
20-[02 D2 02 03 00 28 A4 BF 5A 1C 34 79 50 10 23 28 C1 43 00 00]
|
|
|
|
40-[03 30 30 30 30 30 00 00 03 30]
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Magic text to check for DBS-ETHERWATCH-ness of file */
|
|
|
|
static const char dbs_etherwatch_hdr_magic[] =
|
2017-01-19 15:28:35 +00:00
|
|
|
{ 'E', 'T', 'H', 'E', 'R', 'W', 'A', 'T', 'C', 'H', ' '};
|
2001-10-19 20:18:48 +00:00
|
|
|
#define DBS_ETHERWATCH_HDR_MAGIC_SIZE \
|
|
|
|
(sizeof dbs_etherwatch_hdr_magic / sizeof dbs_etherwatch_hdr_magic[0])
|
|
|
|
|
|
|
|
/* Magic text for start of packet */
|
|
|
|
static const char dbs_etherwatch_rec_magic[] =
|
|
|
|
{'F', 'r', 'o', 'm', ' '};
|
|
|
|
#define DBS_ETHERWATCH_REC_MAGIC_SIZE \
|
2015-01-02 00:45:22 +00:00
|
|
|
(sizeof dbs_etherwatch_rec_magic / sizeof dbs_etherwatch_rec_magic[0])
|
2001-10-19 20:18:48 +00:00
|
|
|
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
/*
|
2016-04-30 18:30:07 +00:00
|
|
|
* Default packet size - maximum normal Ethernet packet size, without an
|
|
|
|
* FCS.
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
*/
|
2016-04-30 18:30:07 +00:00
|
|
|
#define DBS_ETHERWATCH_MAX_ETHERNET_PACKET_LEN 1514
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec,
|
|
|
|
Buffer *buf, int *err, gchar **err_info, gint64 *data_offset);
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info);
|
2018-10-01 00:57:39 +00:00
|
|
|
static gboolean parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec,
|
2015-01-02 00:45:22 +00:00
|
|
|
Buffer* buf, int *err, gchar **err_info);
|
2003-12-29 00:36:12 +00:00
|
|
|
static guint parse_single_hex_dump_line(char* rec, guint8 *buf,
|
2015-01-02 00:45:22 +00:00
|
|
|
int byte_offset);
|
2020-10-10 23:42:05 +00:00
|
|
|
static guint parse_hex_dump(char* dump, guint8 *buf, char separator, char end);
|
2001-10-19 20:18:48 +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 dbs_etherwatch_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_dbs_etherwatch(void);
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
/* Seeks to the beginning of the next packet, and returns the
|
2011-04-21 09:41:52 +00:00
|
|
|
byte offset. Returns -1 on failure, and sets "*err" to the error
|
|
|
|
and "*err_info" to null or an additional error string. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err,
|
2015-01-02 00:45:22 +00:00
|
|
|
gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
int byte;
|
|
|
|
unsigned int level = 0;
|
|
|
|
gint64 cur_off;
|
|
|
|
|
|
|
|
while ((byte = file_getc(wth->fh)) != EOF) {
|
|
|
|
if (byte == dbs_etherwatch_rec_magic[level]) {
|
|
|
|
level++;
|
|
|
|
if (level >= DBS_ETHERWATCH_REC_MAGIC_SIZE) {
|
|
|
|
/* note: we're leaving file pointer right after the magic characters */
|
|
|
|
cur_off = file_tell(wth->fh);
|
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return cur_off + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
level = 0;
|
2002-03-04 00:25:35 +00:00
|
|
|
}
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2015-01-02 00:45:22 +00:00
|
|
|
/* EOF or error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return -1;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
#define DBS_ETHERWATCH_HEADER_LINES_TO_CHECK 200
|
|
|
|
#define DBS_ETHERWATCH_LINE_LENGTH 240
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
/* Look through the first part of a file to see if this is
|
|
|
|
* a DBS Ethertrace text trace file.
|
|
|
|
*
|
2002-03-04 00:25:35 +00:00
|
|
|
* Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
|
2011-04-21 09:41:52 +00:00
|
|
|
* if we get an I/O error, "*err" will be set to a non-zero value and
|
|
|
|
* "*err_info" will be set to null or an error string.
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err,
|
2011-04-21 09:41:52 +00:00
|
|
|
gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
char buf[DBS_ETHERWATCH_LINE_LENGTH];
|
|
|
|
int line, byte;
|
|
|
|
gsize reclen;
|
|
|
|
unsigned int i, level;
|
|
|
|
|
|
|
|
buf[DBS_ETHERWATCH_LINE_LENGTH-1] = 0;
|
|
|
|
|
|
|
|
for (line = 0; line < DBS_ETHERWATCH_HEADER_LINES_TO_CHECK; line++) {
|
|
|
|
if (file_gets(buf, DBS_ETHERWATCH_LINE_LENGTH, wth->fh) == NULL) {
|
|
|
|
/* EOF or error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
reclen = strlen(buf);
|
|
|
|
if (reclen < DBS_ETHERWATCH_HDR_MAGIC_SIZE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
level = 0;
|
|
|
|
for (i = 0; i < reclen; i++) {
|
|
|
|
byte = buf[i];
|
|
|
|
if (byte == dbs_etherwatch_hdr_magic[level]) {
|
|
|
|
level++;
|
|
|
|
if (level >=
|
|
|
|
DBS_ETHERWATCH_HDR_MAGIC_SIZE) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
level = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*err = 0;
|
|
|
|
return FALSE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
/* Look for DBS ETHERWATCH header */
|
|
|
|
if (!dbs_etherwatch_check_file_type(wth, err, err_info)) {
|
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wth->file_encap = WTAP_ENCAP_ETHERNET;
|
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 = dbs_etherwatch_file_type_subtype;
|
2015-01-02 00:45:22 +00:00
|
|
|
wth->snapshot_length = 0; /* not known */
|
|
|
|
wth->subtype_read = dbs_etherwatch_read;
|
|
|
|
wth->subtype_seek_read = dbs_etherwatch_seek_read;
|
|
|
|
wth->file_tsprec = WTAP_TSPREC_CSEC;
|
|
|
|
|
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);
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 11:00:49 +00:00
|
|
|
/* Find the next packet and parse it; called from wtap_read(). */
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean dbs_etherwatch_read(wtap *wth, wtap_rec *rec,
|
|
|
|
Buffer *buf, int *err, gchar **err_info, gint64 *data_offset)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
gint64 offset;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/* Find the next packet */
|
|
|
|
offset = dbs_etherwatch_seek_next_packet(wth, err, err_info);
|
|
|
|
if (offset < 1)
|
|
|
|
return FALSE;
|
|
|
|
*data_offset = offset;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/* Parse the packet */
|
2019-04-05 01:56:27 +00:00
|
|
|
return parse_dbs_etherwatch_packet(wth->fh, rec, buf, err, err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Used to read packets in random-access fashion */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf, int *err, gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2018-10-01 00:57:39 +00:00
|
|
|
return parse_dbs_etherwatch_packet(wth->random_fh, rec, buf, err,
|
2015-01-02 00:45:22 +00:00
|
|
|
err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a packet */
|
|
|
|
/*
|
|
|
|
Packet header:
|
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
|
|
|
*/
|
2015-01-02 00:45:22 +00:00
|
|
|
#define MAC_ADDR_LENGTH 6 /* Length MAC address */
|
|
|
|
#define DEST_MAC_PREFIX "] to " /* Prefix to the dest. MAC address */
|
|
|
|
#define PROTOCOL_LENGTH 2 /* Length protocol */
|
|
|
|
#define PROTOCOL_POS 9 /* Position protocol */
|
|
|
|
#define SAP_LENGTH 2 /* Length DSAP+SSAP */
|
|
|
|
#define SAP_POS 9 /* Position DSAP+SSAP */
|
|
|
|
#define CTL_UNNUMB_LENGTH 1 /* Length unnumbered control field */
|
|
|
|
#define CTL_NUMB_LENGTH 2 /* Length numbered control field */
|
|
|
|
#define CTL_POS 15 /* Position control field */
|
|
|
|
#define PID_LENGTH 5 /* Length PID */
|
|
|
|
#define PID_POS 18 /* Position PID */
|
|
|
|
#define LENGTH_POS 33 /* Position length */
|
2020-10-10 23:42:05 +00:00
|
|
|
#define HEX_HDR_SPR '-' /* Separator char header hex values */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define HEX_HDR_END ' ' /* End char hdr. hex val. except PID */
|
|
|
|
#define HEX_PID_END ',' /* End char PID hex value */
|
|
|
|
#define IEEE802_LEN_LEN 2 /* Length of the IEEE 802 len. field */
|
2003-12-29 00:36:12 +00:00
|
|
|
/*
|
|
|
|
To check whether it is Ethernet II or IEEE 802 we check the values of the
|
|
|
|
control field and PID, when they are all 0's we assume it is Ethernet II
|
|
|
|
else IEEE 802. In IEEE 802 the DSAP and SSAP are behind protocol, the
|
|
|
|
length in the IEEE data we have to construct.
|
|
|
|
*/
|
|
|
|
#define ETH_II_CHECK_POS 15
|
|
|
|
#define ETH_II_CHECK_STR "00 00-00-00-00-00,"
|
|
|
|
/*
|
|
|
|
To check whether it IEEE 802.3 with SNAP we check that both the DSAP & SSAP
|
|
|
|
values are 0xAA and the control field 0x03.
|
|
|
|
*/
|
2015-01-02 00:45:22 +00:00
|
|
|
#define SNAP_CHECK_POS 9
|
|
|
|
#define SNAP_CHECK_STR "AA-AA 03"
|
2003-12-29 00:36:12 +00:00
|
|
|
/*
|
|
|
|
To check whether the control field is 1 or two octets we check if it is
|
|
|
|
unnumbered. Unnumbered has length 1, numbered 2.
|
|
|
|
*/
|
2015-01-02 00:45:22 +00:00
|
|
|
#define CTL_UNNUMB_MASK 0x03
|
|
|
|
#define CTL_UNNUMB_VALUE 0x03
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-10-01 00:57:39 +00:00
|
|
|
parse_dbs_etherwatch_packet(FILE_T fh, wtap_rec *rec, Buffer* buf,
|
2013-05-17 00:07:42 +00:00
|
|
|
int *err, gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2015-01-02 00:45:22 +00:00
|
|
|
guint8 *pd;
|
|
|
|
char line[DBS_ETHERWATCH_LINE_LENGTH];
|
|
|
|
int num_items_scanned;
|
2016-05-01 23:02:40 +00:00
|
|
|
int eth_hdr_len, pkt_len, csec;
|
2015-01-02 00:45:22 +00:00
|
|
|
int length_pos, length_from, length;
|
|
|
|
struct tm tm;
|
|
|
|
char mon[4] = "xxx";
|
|
|
|
gchar *p;
|
|
|
|
static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
|
2016-05-01 23:02:40 +00:00
|
|
|
int count, line_count;
|
2015-01-02 00:45:22 +00:00
|
|
|
|
2016-04-30 18:30:07 +00:00
|
|
|
/* Make sure we have enough room for a regular Ethernet packet */
|
|
|
|
ws_buffer_assure_space(buf, DBS_ETHERWATCH_MAX_ETHERNET_PACKET_LEN);
|
2015-01-02 00:45:22 +00:00
|
|
|
pd = ws_buffer_start_ptr(buf);
|
|
|
|
|
|
|
|
eth_hdr_len = 0;
|
|
|
|
memset(&tm, 0, sizeof(tm));
|
|
|
|
/* Our file pointer should be on the first line containing the
|
|
|
|
* summary information for a packet. Read in that line and
|
|
|
|
* extract the useful information
|
|
|
|
*/
|
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
|
|
|
*err = file_error(fh, err_info);
|
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the destination address */
|
|
|
|
p = strstr(line, DEST_MAC_PREFIX);
|
|
|
|
if(!p) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: destination address not found");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
p += strlen(DEST_MAC_PREFIX);
|
|
|
|
if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END)
|
|
|
|
!= MAC_ADDR_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: destination address not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += MAC_ADDR_LENGTH;
|
|
|
|
|
|
|
|
/* Get the source address */
|
|
|
|
/*
|
|
|
|
* Since the first part of the line is already skipped in order to find
|
|
|
|
* the start of the record we cannot index, just look for the first
|
|
|
|
* 'HEX' character
|
|
|
|
*/
|
|
|
|
p = line;
|
|
|
|
while(!g_ascii_isxdigit(*p)) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != MAC_ADDR_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: source address not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += MAC_ADDR_LENGTH;
|
|
|
|
|
|
|
|
/* Read the next line of the record header */
|
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
|
|
|
*err = file_error(fh, err_info);
|
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the lines is as least as long as the length position */
|
|
|
|
if(strlen(line) < LENGTH_POS) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: line too short");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_items_scanned = sscanf(line + LENGTH_POS,
|
2016-05-01 23:02:40 +00:00
|
|
|
"%9d byte buffer at %2d-%3s-%4d %2d:%2d:%2d.%9d",
|
2015-01-02 00:45:22 +00:00
|
|
|
&pkt_len,
|
|
|
|
&tm.tm_mday, mon,
|
|
|
|
&tm.tm_year, &tm.tm_hour, &tm.tm_min,
|
|
|
|
&tm.tm_sec, &csec);
|
|
|
|
|
|
|
|
if (num_items_scanned != 8) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: header line not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-05-01 23:02:40 +00:00
|
|
|
if (pkt_len < 0) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: packet header has a negative packet length");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/* Determine whether it is Ethernet II or IEEE 802 */
|
|
|
|
if(strncmp(&line[ETH_II_CHECK_POS], ETH_II_CHECK_STR,
|
|
|
|
strlen(ETH_II_CHECK_STR)) == 0) {
|
|
|
|
/* Ethernet II */
|
|
|
|
/* Get the Protocol */
|
|
|
|
if(parse_hex_dump(&line[PROTOCOL_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != PROTOCOL_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += PROTOCOL_LENGTH;
|
|
|
|
} else {
|
|
|
|
/* IEEE 802 */
|
|
|
|
/* Remember where to put the length in the header */
|
|
|
|
length_pos = eth_hdr_len;
|
|
|
|
/* Leave room in the header for the length */
|
|
|
|
eth_hdr_len += IEEE802_LEN_LEN;
|
|
|
|
/* Remember how much of the header should not be added to the length */
|
|
|
|
length_from = eth_hdr_len;
|
|
|
|
/* Get the DSAP + SSAP */
|
|
|
|
if(parse_hex_dump(&line[SAP_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != SAP_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += SAP_LENGTH;
|
|
|
|
/* Get the (first part of the) control field */
|
|
|
|
if(parse_hex_dump(&line[CTL_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != CTL_UNNUMB_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Determine whether the control is numbered, and thus longer */
|
|
|
|
if((pd[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) {
|
|
|
|
/* Get the rest of the control field, the first octet in the PID */
|
|
|
|
if(parse_hex_dump(&line[PID_POS],
|
|
|
|
&pd[eth_hdr_len + CTL_UNNUMB_LENGTH], HEX_HDR_END,
|
|
|
|
HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += CTL_NUMB_LENGTH;
|
|
|
|
} else {
|
|
|
|
eth_hdr_len += CTL_UNNUMB_LENGTH;
|
|
|
|
}
|
|
|
|
/* Determine whether it is SNAP */
|
|
|
|
if(strncmp(&line[SNAP_CHECK_POS], SNAP_CHECK_STR,
|
|
|
|
strlen(SNAP_CHECK_STR)) == 0) {
|
|
|
|
/* Get the PID */
|
|
|
|
if(parse_hex_dump(&line[PID_POS], &pd[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_PID_END) != PID_LENGTH) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
eth_hdr_len += PID_LENGTH;
|
|
|
|
}
|
|
|
|
/* Write the length in the header */
|
|
|
|
length = eth_hdr_len - length_from + pkt_len;
|
|
|
|
pd[length_pos] = (length) >> 8;
|
|
|
|
pd[length_pos+1] = (length) & 0xFF;
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
2021-08-30 02:12:13 +00:00
|
|
|
rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
2015-01-02 00:45:22 +00:00
|
|
|
|
|
|
|
p = strstr(months, mon);
|
|
|
|
if (p)
|
|
|
|
tm.tm_mon = (int)(p - months) / 3;
|
|
|
|
tm.tm_year -= 1900;
|
|
|
|
|
|
|
|
tm.tm_isdst = -1;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->ts.secs = mktime(&tm);
|
|
|
|
rec->ts.nsecs = csec * 10000000;
|
|
|
|
rec->rec_header.packet_header.caplen = eth_hdr_len + pkt_len;
|
|
|
|
rec->rec_header.packet_header.len = eth_hdr_len + pkt_len;
|
2015-01-02 00:45:22 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2016-04-30 18:30:07 +00:00
|
|
|
/*
|
|
|
|
* Probably a corrupt capture file; return an error,
|
|
|
|
* so that our caller doesn't blow up trying to allocate
|
|
|
|
* space for an immensely-large packet.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("dbs_etherwatch: File has %u-byte packet, bigger than maximum of %u",
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.caplen, WTAP_MAX_PACKET_SIZE_STANDARD);
|
2016-04-30 18:30:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we have enough room, even for an oversized Ethernet packet */
|
2018-02-09 00:19:12 +00:00
|
|
|
ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen);
|
2016-04-30 18:30:07 +00:00
|
|
|
pd = ws_buffer_start_ptr(buf);
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/*
|
|
|
|
* We don't have an FCS in this frame.
|
|
|
|
*/
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0;
|
2015-01-02 00:45:22 +00:00
|
|
|
|
|
|
|
/* Parse the hex dump */
|
|
|
|
count = 0;
|
|
|
|
while (count < pkt_len) {
|
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
|
|
|
*err = file_error(fh, err_info);
|
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!(line_count = parse_single_hex_dump_line(line,
|
|
|
|
&pd[eth_hdr_len + count], count))) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: packet data value not valid");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
count += line_count;
|
|
|
|
if (count > pkt_len) {
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("dbs_etherwatch: packet data value has too many bytes");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a hex dump line */
|
2001-10-19 20:18:48 +00:00
|
|
|
/*
|
2003-12-29 00:36:12 +00:00
|
|
|
/DISPLAY=BOTH output:
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..(8...........]- 0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A]
|
|
|
|
[.........(..Z.4y]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 BF 5A 1C 34 79]
|
|
|
|
[P.#(.C...00000..]- 32-[50 10 23 28 C1 43 00 00 03 30 30 30 30 30 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
[.0 ]- 48-[03 30]
|
2003-12-29 00:36:12 +00:00
|
|
|
|
|
|
|
/DISPLAY=HEXADECIMAL output:
|
|
|
|
|
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
|
|
|
0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A 80 93 80 D6]
|
|
|
|
20-[02 D2 02 03 00 28 A4 BF 5A 1C 34 79 50 10 23 28 C1 43 00 00]
|
|
|
|
40-[03 30 30 30 30 30 00 00 03 30]
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
#define TYPE_CHECK_POS 2 /* Position to check the type of hex dump */
|
|
|
|
#define TYPE_CHECK_BOTH '[' /* Value at pos. that indicates BOTH type */
|
|
|
|
#define COUNT_POS_BOTH 21 /* Count position BOTH type */
|
|
|
|
#define COUNT_POS_HEX 1 /* Count position HEX type */
|
|
|
|
#define COUNT_SIZE 5 /* Length counter */
|
|
|
|
#define HEX_DUMP_START '[' /* Start char */
|
2020-10-10 23:42:05 +00:00
|
|
|
#define HEX_DUMP_SPR ' ' /* Separator char */
|
2015-01-02 00:45:22 +00:00
|
|
|
#define HEX_DUMP_END ']' /* End char */
|
2003-12-29 00:36:12 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
/* Take a string representing one line from a hex dump and converts the
|
|
|
|
* text to binary data. We check the printed offset with the offset
|
|
|
|
* we are passed to validate the record. We place the bytes in the buffer
|
|
|
|
* at the specified offset.
|
|
|
|
*
|
2003-12-29 00:36:12 +00:00
|
|
|
* Returns length parsed if a good hex dump, 0 if bad.
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2003-12-29 00:36:12 +00:00
|
|
|
static guint
|
|
|
|
parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset) {
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
int pos, i;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
|
|
|
|
/* Check that the record is as least as long as the check offset */
|
|
|
|
for(i = 0; i < TYPE_CHECK_POS; i++)
|
|
|
|
{
|
|
|
|
if(rec[i] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* determine the format and thus the counter offset and hex dump length */
|
|
|
|
if(rec[TYPE_CHECK_POS] == TYPE_CHECK_BOTH)
|
|
|
|
{
|
|
|
|
pos = COUNT_POS_BOTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = COUNT_POS_HEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the record is as least as long as the start position */
|
|
|
|
while(i < pos)
|
|
|
|
{
|
|
|
|
if(rec[i] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the byte_offset directly from the record */
|
|
|
|
value = 0;
|
|
|
|
for(i = 0; i < COUNT_SIZE; i++) {
|
|
|
|
if(!g_ascii_isspace(rec[pos])) {
|
|
|
|
if(g_ascii_isdigit(rec[pos])) {
|
|
|
|
value *= 10;
|
|
|
|
value += rec[pos] - '0';
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != byte_offset) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the start of the hex dump */
|
|
|
|
while(rec[pos] != HEX_DUMP_START) {
|
|
|
|
if(rec[pos] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
return parse_hex_dump(&rec[pos], buf, HEX_DUMP_SPR, HEX_DUMP_END);
|
2003-12-29 00:36:12 +00:00
|
|
|
}
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a hex dump */
|
|
|
|
static guint
|
2020-10-10 23:42:05 +00:00
|
|
|
parse_hex_dump(char* dump, guint8 *buf, char separator, char end) {
|
2015-01-02 00:45:22 +00:00
|
|
|
int pos, count;
|
|
|
|
|
|
|
|
/* Parse the hex dump */
|
|
|
|
pos = 0;
|
|
|
|
count = 0;
|
|
|
|
while(dump[pos] != end) {
|
|
|
|
/* Check the hex value */
|
|
|
|
if(!(g_ascii_isxdigit(dump[pos]) &&
|
|
|
|
g_ascii_isxdigit(dump[pos + 1]))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-20 02:40:23 +00:00
|
|
|
/* Get the hex value */
|
2015-01-02 00:45:22 +00:00
|
|
|
if(g_ascii_isdigit(dump[pos])) {
|
|
|
|
buf[count] = (dump[pos] - '0') << 4;
|
|
|
|
} else {
|
|
|
|
buf[count] = (g_ascii_toupper(dump[pos]) - 'A' + 10) << 4;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
if(g_ascii_isdigit(dump[pos])) {
|
|
|
|
buf[count] += dump[pos] - '0';
|
|
|
|
} else {
|
|
|
|
buf[count] += g_ascii_toupper(dump[pos]) - 'A' + 10;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
count++;
|
2020-10-10 23:42:05 +00:00
|
|
|
/* Skip the separator characters */
|
|
|
|
while(dump[pos] == separator) {
|
2015-01-02 00:45:22 +00:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
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 dbs_etherwatch_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 dbs_etherwatch_info = {
|
|
|
|
"DBS Etherwatch (VMS)", "etherwatch", "txt", 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
|
|
|
FALSE, BLOCKS_SUPPORTED(dbs_etherwatch_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
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void register_dbs_etherwatch(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
dbs_etherwatch_file_type_subtype = wtap_register_file_type_subtype(&dbs_etherwatch_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("DBS_ETHERWATCH",
|
|
|
|
dbs_etherwatch_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: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|