2009-06-15 18:56:46 +00:00
|
|
|
/* ascendtext.c
|
1999-09-11 04:53:26 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
1999-09-11 04:53:26 +00:00
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
#include "config.h"
|
2000-05-19 23:07:04 +00:00
|
|
|
#include "wtap-int.h"
|
2009-06-15 18:56:46 +00:00
|
|
|
#include "ascendtext.h"
|
1999-10-08 07:45:31 +00:00
|
|
|
#include "ascend-int.h"
|
2000-01-13 07:09:20 +00:00
|
|
|
#include "file_wrappers.h"
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2002-03-04 00:25:35 +00:00
|
|
|
#include <errno.h>
|
2000-01-10 17:33:17 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
1999-09-11 04:53:26 +00:00
|
|
|
#include <unistd.h>
|
2000-01-10 17:33:17 +00:00
|
|
|
#endif
|
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-02-05 17:39:12 +00:00
|
|
|
/* Last updated: Feb 03 2005: Josh Bailey (joshbailey@lucent.com).
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2005-02-05 17:39:12 +00:00
|
|
|
This module reads the text hex dump output of various TAOS
|
2020-11-19 01:39:19 +00:00
|
|
|
(Avaya/Alcatel/Lucent/Ascend Max, Max TNT, APX, etc) debug commands, including:
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
* pridisplay traces primary rate ISDN
|
|
|
|
* ether-display traces Ethernet packets (dangerous! CPU intensive)
|
2005-02-05 17:39:12 +00:00
|
|
|
* wanopening, wandisplay, wannext, wandsess
|
2015-01-02 00:45:22 +00:00
|
|
|
traces PPP or other WAN connections
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
Please see ascend_parser.lemon for examples.
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2020-07-22 07:14:15 +00:00
|
|
|
Detailed documentation on TAOS products was at http://support.lucent.com;
|
|
|
|
that no longer works, and appears not to be available on the Wayback
|
|
|
|
Machine.
|
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
Some online manuals and other information include:
|
2020-07-22 07:14:15 +00:00
|
|
|
|
|
|
|
MAX Administration Guide:
|
|
|
|
https://downloads.avaya.com/elmodocs2/definity/def_r10_new/max/0678_002.pdf
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
Other MAX documentation:
|
|
|
|
https://support.avaya.com/products/P1192/max
|
|
|
|
https://web.archive.org/web/20201127014004/https://support.avaya.com/products/P1192/max#Tab4
|
|
|
|
|
|
|
|
Ascend Router Information:
|
|
|
|
http://maxrouter.rde.net/
|
|
|
|
https://web.archive.org/web/20200807215418/http://maxrouter.rde.net/
|
|
|
|
|
|
|
|
*/
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2005-02-05 17:39:12 +00:00
|
|
|
typedef struct _ascend_magic_string {
|
2020-11-19 01:39:19 +00:00
|
|
|
guint type;
|
|
|
|
const gchar *strptr;
|
|
|
|
size_t strlength;
|
2005-02-05 17:39:12 +00:00
|
|
|
} ascend_magic_string;
|
|
|
|
|
|
|
|
/* these magic strings signify the headers of a supported debug commands */
|
2015-11-30 08:31:12 +00:00
|
|
|
#define ASCEND_MAGIC_ENTRY(type, string) \
|
2020-11-19 01:39:19 +00:00
|
|
|
{ type, string, sizeof string - 1 } /* strlen of a constant string */
|
2005-02-05 17:39:12 +00:00
|
|
|
static const ascend_magic_string ascend_magic[] = {
|
2020-11-19 01:39:19 +00:00
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_ISDN_X, "PRI-XMIT-"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_ISDN_R, "PRI-RCV-"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_X, "XMIT-"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_R, "RECV-"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_X, "XMIT:"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_R, "RECV:"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_X, "PPP-OUT"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDS_R, "PPP-IN"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_WDD, "WD_DIALOUT_DISP:"),
|
|
|
|
ASCEND_MAGIC_ENTRY(ASCEND_PFX_ETHER, "ETHER"),
|
2005-02-05 17:39:12 +00:00
|
|
|
};
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2015-11-30 08:31:12 +00:00
|
|
|
#define ASCEND_MAGIC_STRINGS G_N_ELEMENTS(ascend_magic)
|
|
|
|
|
|
|
|
#define ASCEND_DATE "Date:"
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean ascend_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 ascend_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf,
|
2015-01-02 00:45:22 +00:00
|
|
|
int *err, gchar **err_info);
|
1999-09-11 06:49:42 +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 ascend_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_ascend(void);
|
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
/* Seeks to the beginning of the next packet, and returns the
|
2005-02-05 17:39:12 +00:00
|
|
|
byte offset at which the header for that packet begins.
|
|
|
|
Returns -1 on failure. */
|
2018-10-02 11:20:19 +00:00
|
|
|
static gint64 ascend_find_next_packet(wtap *wth, int *err, gchar **err_info)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2020-11-19 01:39:19 +00:00
|
|
|
int byte;
|
|
|
|
gint64 date_off = -1, cur_off, packet_off;
|
|
|
|
size_t string_level[ASCEND_MAGIC_STRINGS];
|
|
|
|
guint string_i = 0;
|
|
|
|
static const gchar ascend_date[] = ASCEND_DATE;
|
|
|
|
size_t ascend_date_len = sizeof ascend_date - 1; /* strlen of a constant string */
|
|
|
|
size_t ascend_date_string_level;
|
|
|
|
guint excessive_read_count = 262144;
|
|
|
|
|
|
|
|
memset(&string_level, 0, sizeof(string_level));
|
|
|
|
ascend_date_string_level = 0;
|
|
|
|
|
|
|
|
while (((byte = file_getc(wth->fh)) != EOF)) {
|
|
|
|
excessive_read_count--;
|
|
|
|
|
|
|
|
if (!excessive_read_count) {
|
|
|
|
*err = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-11 22:07:55 +00:00
|
|
|
|
2015-11-30 04:59:26 +00:00
|
|
|
/*
|
2020-11-19 01:39:19 +00:00
|
|
|
* See whether this is the string_level[string_i]th character of
|
|
|
|
* Ascend magic string string_i.
|
|
|
|
*/
|
|
|
|
for (string_i = 0; string_i < ASCEND_MAGIC_STRINGS; string_i++) {
|
|
|
|
const gchar *strptr = ascend_magic[string_i].strptr;
|
|
|
|
size_t len = ascend_magic[string_i].strlength;
|
|
|
|
|
|
|
|
if (byte == *(strptr + string_level[string_i])) {
|
|
|
|
/*
|
|
|
|
* Yes, it is, so we need to check for the next character of
|
|
|
|
* that string.
|
|
|
|
*/
|
|
|
|
string_level[string_i]++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have we matched the entire string?
|
|
|
|
*/
|
|
|
|
if (string_level[string_i] >= len) {
|
|
|
|
/*
|
|
|
|
* Yes.
|
|
|
|
*/
|
|
|
|
cur_off = file_tell(wth->fh);
|
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We matched some other type of header. */
|
|
|
|
if (date_off == -1) {
|
|
|
|
/* We haven't yet seen a date header, so this packet
|
|
|
|
doesn't have one.
|
|
|
|
Back up over the header we just read; that's where a read
|
|
|
|
of this packet should start. */
|
|
|
|
packet_off = cur_off - len;
|
|
|
|
} else {
|
|
|
|
/* This packet has a date/time header; a read of it should
|
|
|
|
start at the beginning of *that* header. */
|
|
|
|
packet_off = date_off;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Not a match for this string, so reset the match process.
|
|
|
|
*/
|
|
|
|
string_level[string_i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 04:59:26 +00:00
|
|
|
|
|
|
|
/*
|
2020-11-19 01:39:19 +00:00
|
|
|
* See whether this is the date_string_level'th character of
|
|
|
|
* ASCEND_DATE.
|
|
|
|
*/
|
|
|
|
if (byte == *(ascend_date + ascend_date_string_level)) {
|
|
|
|
/*
|
|
|
|
* Yes, it is, so we need to check for the next character of
|
|
|
|
* that string.
|
|
|
|
*/
|
|
|
|
ascend_date_string_level++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have we matched the entire string?
|
|
|
|
*/
|
|
|
|
if (ascend_date_string_level >= ascend_date_len) {
|
|
|
|
/* We matched a Date: header. It's a special case;
|
|
|
|
remember the offset, but keep looking for other
|
|
|
|
headers.
|
|
|
|
|
|
|
|
Reset the amount of Date: header that we've matched,
|
|
|
|
so that we start the process of matching a Date:
|
|
|
|
header all over again.
|
|
|
|
|
|
|
|
XXX - what if we match multiple Date: headers before
|
|
|
|
matching some other header? */
|
|
|
|
cur_off = file_tell(wth->fh);
|
|
|
|
if (cur_off == -1) {
|
2005-02-05 17:39:12 +00:00
|
|
|
/* Error. */
|
2014-05-09 05:18:49 +00:00
|
|
|
*err = file_error(wth->fh, err_info);
|
2005-02-05 17:39:12 +00:00
|
|
|
return -1;
|
2020-11-19 01:39:19 +00:00
|
|
|
}
|
2015-11-30 08:31:12 +00:00
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
date_off = cur_off - ascend_date_len;
|
|
|
|
ascend_date_string_level = 0;
|
2015-11-30 08:31:12 +00:00
|
|
|
}
|
2020-11-19 01:39:19 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Not a match for the Date: string, so reset the match process.
|
|
|
|
*/
|
2015-11-30 08:31:12 +00:00
|
|
|
ascend_date_string_level = 0;
|
2020-11-19 01:39:19 +00:00
|
|
|
}
|
2015-11-30 08:31:12 +00:00
|
|
|
}
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return -1;
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
|
|
|
|
found:
|
2020-11-19 01:39:19 +00:00
|
|
|
/*
|
|
|
|
* Move to where the read for this packet should start, and return
|
|
|
|
* that seek offset.
|
|
|
|
*/
|
|
|
|
if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1)
|
|
|
|
return -1;
|
2005-02-05 17:39:12 +00:00
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
return packet_off;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2020-11-19 01:39:19 +00:00
|
|
|
gint64 offset;
|
|
|
|
guint8 buf[ASCEND_MAX_PKT_LEN];
|
|
|
|
ascend_state_t parser_state = {0};
|
|
|
|
ws_statb64 statbuf;
|
|
|
|
ascend_t *ascend;
|
|
|
|
wtap_rec rec;
|
|
|
|
|
|
|
|
/* We haven't yet allocated a data structure for our private stuff;
|
|
|
|
set the pointer to null, so that "ascend_find_next_packet()" knows
|
|
|
|
not to fill it in. */
|
|
|
|
wth->priv = NULL;
|
|
|
|
|
|
|
|
offset = ascend_find_next_packet(wth, err, err_info);
|
|
|
|
if (offset == -1) {
|
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
|
|
|
return WTAP_OPEN_ERROR; /* read error */
|
|
|
|
return WTAP_OPEN_NOT_MINE; /* EOF */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do a trial parse of the first packet just found to see if we might
|
|
|
|
really have an Ascend file. If it fails with an actual error,
|
|
|
|
fail; those will be I/O errors. */
|
|
|
|
parser_state.fh = wth->fh;
|
|
|
|
parser_state.pseudo_header = &rec.rec_header.packet_header.pseudo_header.ascend;
|
|
|
|
if (run_ascend_parser(buf, &parser_state, err, err_info) != 0 && *err != 0) {
|
|
|
|
/* An I/O error. */
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Either the parse succeeded, or it failed but didn't get an I/O
|
|
|
|
error.
|
|
|
|
|
|
|
|
If we got at least some data, return success even if the parser
|
|
|
|
reported an error. This is because the debug header gives the
|
|
|
|
number of bytes on the wire, not actually how many bytes are in
|
|
|
|
the trace. We won't know where the data ends until we run into
|
|
|
|
the next packet. */
|
|
|
|
if (parser_state.caplen == 0) {
|
|
|
|
/* We read no data, so this presumably isn't an Ascend file. */
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
|
|
|
|
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 = ascend_file_type_subtype;
|
2020-11-19 01:39:19 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_ASCEND;
|
|
|
|
|
|
|
|
wth->snapshot_length = ASCEND_MAX_PKT_LEN;
|
|
|
|
wth->subtype_read = ascend_read;
|
|
|
|
wth->subtype_seek_read = ascend_seek_read;
|
2020-12-21 02:30:28 +00:00
|
|
|
ascend = g_new(ascend_t, 1);
|
2020-11-19 01:39:19 +00:00
|
|
|
wth->priv = (void *)ascend;
|
|
|
|
|
|
|
|
/* The first packet we want to read is the one that
|
|
|
|
"ascend_find_next_packet()" just found; start searching
|
|
|
|
for it at the offset at which it found it. */
|
|
|
|
ascend->next_packet_seek_start = offset;
|
|
|
|
|
|
|
|
/* MAXen and Pipelines report the time since reboot. In order to keep
|
|
|
|
from reporting packet times near the epoch, we subtract the first
|
|
|
|
packet's timestamp from the capture file's ctime, which gives us an
|
|
|
|
offset that we can apply to each packet.
|
|
|
|
*/
|
|
|
|
if (wtap_fstat(wth, &statbuf, err) == -1) {
|
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
ascend->inittime = statbuf.st_ctime;
|
|
|
|
ascend->adjusted = FALSE;
|
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
return WTAP_OPEN_MINE;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/* Parse the capture file.
|
2016-08-18 02:03:11 +00:00
|
|
|
Returns TRUE if we got a packet, FALSE otherwise. */
|
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
parse_ascend(ascend_t *ascend, FILE_T fh, wtap_rec *rec, Buffer *buf,
|
2018-10-02 11:20:19 +00:00
|
|
|
guint length, gint64 *next_packet_seek_start_ret,
|
|
|
|
int *err, gchar **err_info)
|
2016-03-31 01:44:01 +00:00
|
|
|
{
|
2020-11-19 01:39:19 +00:00
|
|
|
ascend_state_t parser_state = {0};
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
ws_buffer_assure_space(buf, length);
|
|
|
|
parser_state.fh = fh;
|
|
|
|
parser_state.pseudo_header = &rec->rec_header.packet_header.pseudo_header.ascend;
|
|
|
|
|
|
|
|
retval = run_ascend_parser(ws_buffer_start_ptr(buf), &parser_state, err, err_info);
|
|
|
|
|
|
|
|
/* Did we see any data (hex bytes)? */
|
|
|
|
if (parser_state.first_hexbyte) {
|
|
|
|
/* Yes. Provide the offset of the first byte so that our caller can
|
|
|
|
tip off ascend_find_next_packet() as to where to look for the next
|
|
|
|
packet, if any. */
|
|
|
|
if (next_packet_seek_start_ret != NULL)
|
|
|
|
*next_packet_seek_start_ret = parser_state.first_hexbyte;
|
|
|
|
} else {
|
|
|
|
/* No. Maybe this record was broken; sometimes, a header will be
|
|
|
|
printed but the data will be omitted, or worse -- two headers will
|
|
|
|
be printed, followed by the data for each.
|
|
|
|
|
|
|
|
Because of this, we need to be fairly tolerant of what we accept
|
|
|
|
here. Provide our current offset so that our caller can tell
|
|
|
|
ascend_find_next_packet() to skip over what we've read so far so
|
|
|
|
we can try reading a new packet.
|
|
|
|
|
|
|
|
. That keeps us from getting into an infinite loop reading a broken
|
|
|
|
trace. */
|
|
|
|
if (next_packet_seek_start_ret != NULL)
|
|
|
|
*next_packet_seek_start_ret = file_tell(fh);
|
|
|
|
|
|
|
|
/* Don't treat that as a fatal error; pretend the parse succeeded. */
|
|
|
|
retval = 0;
|
2016-03-31 01:44:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 01:39:19 +00:00
|
|
|
/* if we got at least some data, return success even if the parser
|
|
|
|
reported an error. This is because the debug header gives the number
|
|
|
|
of bytes on the wire, not actually how many bytes are in the trace.
|
|
|
|
We won't know where the data ends until we run into the next packet. */
|
|
|
|
if (parser_state.caplen) {
|
|
|
|
if (! ascend->adjusted) {
|
|
|
|
ascend->adjusted = TRUE;
|
|
|
|
if (parser_state.saw_timestamp) {
|
|
|
|
/*
|
|
|
|
* Capture file contained a date and time.
|
|
|
|
* We do this only if this is the very first packet we've seen -
|
|
|
|
* i.e., if "ascend->adjusted" is false - because
|
|
|
|
* if we get a date and time after the first packet, we can't
|
|
|
|
* go back and adjust the time stamps of the packets we've already
|
|
|
|
* processed, and basing the time stamps of this and following
|
|
|
|
* packets on the time stamp from the file text rather than the
|
|
|
|
* ctime of the capture file means times before this and after
|
|
|
|
* this can't be compared.
|
|
|
|
*/
|
|
|
|
ascend->inittime = parser_state.timestamp;
|
|
|
|
}
|
|
|
|
if (ascend->inittime > parser_state.secs)
|
|
|
|
ascend->inittime -= parser_state.secs;
|
|
|
|
}
|
2021-05-31 09:44:57 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
2021-08-30 02:12:13 +00:00
|
|
|
rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
|
2020-11-19 01:39:19 +00:00
|
|
|
rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
|
|
|
rec->ts.secs = parser_state.secs + ascend->inittime;
|
|
|
|
rec->ts.nsecs = parser_state.usecs * 1000;
|
|
|
|
rec->rec_header.packet_header.caplen = parser_state.caplen;
|
|
|
|
rec->rec_header.packet_header.len = parser_state.wirelen;
|
|
|
|
|
|
|
|
return TRUE;
|
2016-03-31 01:44:01 +00:00
|
|
|
}
|
2020-11-19 01:39:19 +00:00
|
|
|
|
|
|
|
/* Didn't see any data. Still, perhaps the parser was happy. */
|
|
|
|
if (retval) {
|
|
|
|
if (*err == 0) {
|
|
|
|
/* Parser failed, but didn't report an I/O error, so a parse error.
|
|
|
|
Return WTAP_ERR_BAD_FILE, with the parse error as the error string. */
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup((parser_state.ascend_parse_error != NULL) ? parser_state.ascend_parse_error : "parse error");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*err == 0) {
|
|
|
|
/* Parser succeeded, but got no data, and didn't report an I/O error.
|
|
|
|
Return WTAP_ERR_BAD_FILE, with a "got no data" error string. */
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup("no data returned by parse");
|
|
|
|
}
|
2016-08-18 02:03:11 +00:00
|
|
|
}
|
2020-11-19 01:39:19 +00:00
|
|
|
return FALSE;
|
2016-03-31 01:44:01 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 11:00:49 +00:00
|
|
|
/* Read the next packet; called from wtap_read(). */
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean ascend_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
|
|
|
|
gchar **err_info, gint64 *data_offset)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2020-11-19 01:39:19 +00:00
|
|
|
ascend_t *ascend = (ascend_t *)wth->priv;
|
|
|
|
gint64 offset;
|
|
|
|
|
|
|
|
/* parse_ascend() will advance the point at which to look for the next
|
|
|
|
packet's header, to just after the last packet's header (ie. at the
|
|
|
|
start of the last packet's data). We have to get past the last
|
|
|
|
packet's header because we might mistake part of it for a new header. */
|
|
|
|
if (file_seek(wth->fh, ascend->next_packet_seek_start,
|
|
|
|
SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
offset = ascend_find_next_packet(wth, err, err_info);
|
|
|
|
if (offset == -1) {
|
|
|
|
/* EOF or read error */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!parse_ascend(ascend, wth->fh, rec, buf, wth->snapshot_length,
|
|
|
|
&ascend->next_packet_seek_start, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Flex might have gotten an EOF and caused *err to be set to
|
|
|
|
WTAP_ERR_SHORT_READ. If so, that's not an error, as the parser
|
|
|
|
didn't return an error; set *err to 0, and get rid of any error
|
|
|
|
string. */
|
|
|
|
*err = 0;
|
|
|
|
if (*err_info != NULL) {
|
|
|
|
g_free(*err_info);
|
|
|
|
*err_info = NULL;
|
|
|
|
}
|
|
|
|
*data_offset = offset;
|
|
|
|
return TRUE;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean ascend_seek_read(wtap *wth, gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec, Buffer *buf,
|
2015-01-02 00:45:22 +00:00
|
|
|
int *err, gchar **err_info)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2020-11-19 01:39:19 +00:00
|
|
|
ascend_t *ascend = (ascend_t *)wth->priv;
|
|
|
|
|
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
|
|
|
return FALSE;
|
|
|
|
if (!parse_ascend(ascend, wth->random_fh, rec, buf,
|
|
|
|
wth->snapshot_length, NULL, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Flex might have gotten an EOF and caused *err to be set to
|
|
|
|
WTAP_ERR_SHORT_READ. If so, that's not an error, as the parser
|
|
|
|
didn't return an error; set *err to 0, and get rid of any error
|
|
|
|
string. */
|
|
|
|
*err = 0;
|
|
|
|
if (*err_info != NULL) {
|
|
|
|
g_free(*err_info);
|
|
|
|
*err_info = NULL;
|
|
|
|
}
|
|
|
|
return TRUE;
|
1999-09-11 04:53:26 +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
|
|
|
|
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 ascend_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 ascend_info = {
|
|
|
|
"Lucent/Ascend access server trace", "ascend", "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(ascend_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_ascend(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
ascend_file_type_subtype = wtap_register_file_type_subtype(&ascend_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("ASCEND",
|
|
|
|
ascend_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
|
|
|
}
|