2000-09-19 17:22:11 +00:00
|
|
|
/* pppdump.c
|
|
|
|
*
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 2000 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
|
2000-09-19 17:22:11 +00:00
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
2000-09-19 17:22:11 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "pppdump.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-11-19 03:47:36 +00:00
|
|
|
#include <errno.h>
|
2000-11-17 21:00:40 +00:00
|
|
|
#include <string.h>
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2021-05-23 23:46:43 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
|
|
|
|
2000-09-19 17:22:11 +00:00
|
|
|
/*
|
|
|
|
pppdump records
|
|
|
|
Daniel Thompson (STMicroelectronics) <daniel.thompson@st.com>
|
|
|
|
|
|
|
|
+------+
|
2002-07-15 08:45:32 +00:00
|
|
|
| 0x07 | Reset time
|
|
|
|
+------+------+------+------+
|
2000-09-19 17:22:11 +00:00
|
|
|
| t3 | t2 | t1 | t0 | t = time_t
|
|
|
|
+------+------+------+------+
|
|
|
|
|
|
|
|
+------+
|
|
|
|
| 0x06 | Time step (short)
|
2002-07-15 08:45:32 +00:00
|
|
|
+------+
|
|
|
|
| ts | ts = time step (tenths of seconds)
|
2000-09-19 17:22:11 +00:00
|
|
|
+------+
|
|
|
|
|
|
|
|
+------+
|
2002-07-15 08:45:32 +00:00
|
|
|
| 0x05 | Time step (long)
|
|
|
|
+------+------+------+------+
|
|
|
|
| ts3 | ts2 | ts1 | ts0 | ts = time step (tenths of seconds)
|
2000-09-19 17:22:11 +00:00
|
|
|
+------+------+------+------+
|
|
|
|
|
|
|
|
+------+
|
|
|
|
| 0x04 | Receive deliminator (not seen in practice)
|
|
|
|
+------+
|
|
|
|
|
|
|
|
+------+
|
|
|
|
| 0x03 | Send deliminator (not seen in practice)
|
|
|
|
+------+
|
|
|
|
|
|
|
|
+------+
|
2002-07-15 08:45:32 +00:00
|
|
|
| 0x02 | Received data
|
|
|
|
+------+------+
|
2000-09-19 17:22:11 +00:00
|
|
|
| n1 | n0 | n = number of bytes following
|
2002-07-15 08:45:32 +00:00
|
|
|
+------+------+
|
2000-09-19 17:22:11 +00:00
|
|
|
| data |
|
|
|
|
| |
|
|
|
|
|
|
|
|
+------+
|
2002-07-15 08:45:32 +00:00
|
|
|
| 0x01 | Sent data
|
|
|
|
+------+------+
|
2000-09-19 17:22:11 +00:00
|
|
|
| n1 | n0 | n = number of bytes following
|
2002-07-15 08:45:32 +00:00
|
|
|
+------+------+
|
2000-09-19 17:22:11 +00:00
|
|
|
| data |
|
|
|
|
| |
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PPPD_SENT_DATA 0x01
|
|
|
|
#define PPPD_RECV_DATA 0x02
|
|
|
|
#define PPPD_SEND_DELIM 0x03
|
|
|
|
#define PPPD_RECV_DELIM 0x04
|
|
|
|
#define PPPD_TIME_STEP_LONG 0x05
|
|
|
|
#define PPPD_TIME_STEP_SHORT 0x06
|
|
|
|
#define PPPD_RESET_TIME 0x07
|
|
|
|
|
2005-01-16 08:45:11 +00:00
|
|
|
/* this buffer must be at least (2*PPPD_MTU) + sizeof(ppp_header) +
|
|
|
|
* sizeof(lcp_header) + sizeof(ipcp_header). PPPD_MTU is *very* rarely
|
|
|
|
* larger than 1500 so this value is fine.
|
2016-04-30 23:38:27 +00:00
|
|
|
*
|
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
|
|
|
* It's less than WTAP_MAX_PACKET_SIZE_STANDARD, so we don't have to worry about
|
2016-04-30 23:38:27 +00:00
|
|
|
* too-large packets.
|
2000-12-09 03:02:43 +00:00
|
|
|
*/
|
|
|
|
#define PPPD_BUF_SIZE 8192
|
|
|
|
|
2000-09-19 17:22:11 +00:00
|
|
|
typedef enum {
|
|
|
|
DIRECTION_SENT,
|
|
|
|
DIRECTION_RECV
|
|
|
|
} direction_enum;
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean pppdump_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 pppdump_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);
|
2000-09-19 17:22:11 +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 pppdump_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_pppdump(void);
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* Information saved about a packet, during the initial sequential pass
|
|
|
|
* through the file, to allow us to later re-read it when randomly
|
|
|
|
* reading packets.
|
|
|
|
*
|
|
|
|
* "offset" is the offset in the file of the first data chunk containing data
|
|
|
|
* from that packet; note that it may also contain data from previous
|
|
|
|
* packets.
|
|
|
|
*
|
|
|
|
* "num_bytes_to_skip" is the number of bytes from previous packets in that
|
|
|
|
* first data chunk.
|
|
|
|
*
|
|
|
|
* "dir" is the direction of the packet.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
typedef struct {
|
2009-04-22 03:07:37 +00:00
|
|
|
gint64 offset;
|
|
|
|
gint64 num_bytes_to_skip;
|
2000-09-19 17:22:11 +00:00
|
|
|
direction_enum dir;
|
|
|
|
} pkt_id;
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* Information about a packet currently being processed. There is one of
|
|
|
|
* these for the sent packet being processed and one of these for the
|
|
|
|
* received packet being processed, as we could be in the middle of
|
|
|
|
* processing both a received packet and a sent packet.
|
|
|
|
*
|
|
|
|
* "dir" is the direction of the packet.
|
|
|
|
*
|
|
|
|
* "cnt" is the number of bytes of packet data we've accumulated.
|
|
|
|
*
|
|
|
|
* "esc" is TRUE if the next byte we see is escaped (and thus must be XORed
|
|
|
|
* with 0x20 before saving it), FALSE otherwise.
|
|
|
|
*
|
|
|
|
* "buf" is a buffer containing the packet data we've accumulated.
|
|
|
|
*
|
|
|
|
* "id_offset" is the offset in the file of the first data chunk
|
|
|
|
* containing data from the packet we're processing.
|
|
|
|
*
|
|
|
|
* "sd_offset" is the offset in the file of the first data byte from
|
|
|
|
* the packet we're processing - which isn't necessarily right after
|
|
|
|
* the header of the first data chunk, as we may already have assembled
|
|
|
|
* packets from that chunk.
|
|
|
|
*
|
|
|
|
* "cd_offset" is the offset in the file of the current data chunk we're
|
|
|
|
* processing.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
typedef struct {
|
|
|
|
direction_enum dir;
|
|
|
|
int cnt;
|
|
|
|
gboolean esc;
|
2000-12-09 03:02:43 +00:00
|
|
|
guint8 buf[PPPD_BUF_SIZE];
|
2009-04-22 03:07:37 +00:00
|
|
|
gint64 id_offset;
|
|
|
|
gint64 sd_offset;
|
|
|
|
gint64 cd_offset;
|
2000-09-19 17:22:11 +00:00
|
|
|
} pkt_t;
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* This keeps state used while processing records.
|
|
|
|
*
|
|
|
|
* "timestamp" is the seconds portion of the current time stamp value,
|
|
|
|
* as updated from PPPD_RESET_TIME, PPPD_TIME_STEP_LONG, and
|
|
|
|
* PPPD_TIME_STEP_SHORT records. "tenths" is the tenths-of-seconds
|
|
|
|
* portion.
|
|
|
|
*
|
|
|
|
* "spkt" and "rpkt" are "pkt_t" structures for the sent and received
|
|
|
|
* packets we're currently working on.
|
|
|
|
*
|
|
|
|
* "offset" is the current offset in the file.
|
|
|
|
*
|
|
|
|
* "num_bytes" and "pkt" are information saved when we finish accumulating
|
|
|
|
* the data for a packet, if the data chunk we're working on still has more
|
|
|
|
* data in it:
|
|
|
|
*
|
|
|
|
* "num_bytes" is the number of bytes of additional data remaining
|
|
|
|
* in the chunk after we've finished accumulating the data for the
|
|
|
|
* packet.
|
|
|
|
*
|
|
|
|
* "pkt" is the "pkt_t" for the type of packet the data chunk is for
|
|
|
|
* (sent or received packet).
|
|
|
|
*
|
|
|
|
* "seek_state" is another state structure used while processing records
|
|
|
|
* when doing a seek-and-read. (That structure doesn't itself have a
|
|
|
|
* "seek_state" structure.)
|
|
|
|
*
|
|
|
|
* "pids" is a GPtrArray of pointers to "pkt_id" structures for all the
|
|
|
|
* packets we've seen during the initial sequential pass, to allow us to
|
|
|
|
* later retrieve them with random accesses.
|
|
|
|
*
|
|
|
|
* "pkt_cnt" is the number of packets we've seen up to this point in the
|
|
|
|
* sequential pass.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
typedef struct _pppdump_t {
|
|
|
|
time_t timestamp;
|
|
|
|
guint tenths;
|
|
|
|
pkt_t spkt;
|
|
|
|
pkt_t rpkt;
|
2009-04-22 03:50:13 +00:00
|
|
|
gint64 offset;
|
2002-07-15 08:45:32 +00:00
|
|
|
int num_bytes;
|
|
|
|
pkt_t *pkt;
|
2000-09-19 17:22:11 +00:00
|
|
|
struct _pppdump_t *seek_state;
|
|
|
|
GPtrArray *pids;
|
|
|
|
guint pkt_cnt;
|
|
|
|
} pppdump_t;
|
|
|
|
|
|
|
|
static int
|
2002-07-15 09:50:02 +00:00
|
|
|
process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
|
2011-04-21 09:41:52 +00:00
|
|
|
int *err, gchar **err_info, pkt_id *pid);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
static gboolean
|
2019-01-04 13:12:45 +00:00
|
|
|
collate(pppdump_t *state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
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
|
|
|
int *num_bytes, direction_enum *direction, pkt_id *pid,
|
2009-04-22 03:07:37 +00:00
|
|
|
gint64 num_bytes_to_skip);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
static void
|
2014-05-09 05:18:49 +00:00
|
|
|
pppdump_close(wtap *wth);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
init_state(pppdump_t *state)
|
|
|
|
{
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
state->num_bytes = 0;
|
|
|
|
state->pkt = NULL;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
state->spkt.dir = DIRECTION_SENT;
|
|
|
|
state->spkt.cnt = 0;
|
|
|
|
state->spkt.esc = FALSE;
|
|
|
|
state->spkt.id_offset = 0;
|
2002-07-15 08:45:32 +00:00
|
|
|
state->spkt.sd_offset = 0;
|
|
|
|
state->spkt.cd_offset = 0;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
state->rpkt.dir = DIRECTION_RECV;
|
|
|
|
state->rpkt.cnt = 0;
|
|
|
|
state->rpkt.esc = FALSE;
|
|
|
|
state->rpkt.id_offset = 0;
|
2002-07-15 08:45:32 +00:00
|
|
|
state->rpkt.sd_offset = 0;
|
|
|
|
state->rpkt.cd_offset = 0;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
state->seek_state = NULL;
|
|
|
|
state->offset = 0x100000; /* to detect errors during development */
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:30:45 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val
|
2014-05-09 05:18:49 +00:00
|
|
|
pppdump_open(wtap *wth, int *err, gchar **err_info)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
guint8 buffer[6]; /* Looking for: 0x07 t3 t2 t1 t0 ID */
|
|
|
|
pppdump_t *state;
|
|
|
|
|
|
|
|
/* There is no file header, only packet records. Fortunately for us,
|
|
|
|
* timestamp records are separated from packet records, so we should
|
|
|
|
* find an "initial time stamp" (i.e., a "reset time" record, or
|
|
|
|
* record type 0x07) at the beginning of the file. We'll check for
|
|
|
|
* that, plus a valid record following the 0x07 and the four bytes
|
|
|
|
* representing the timestamp.
|
|
|
|
*/
|
|
|
|
|
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, buffer, sizeof(buffer),
|
|
|
|
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;
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
}
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
if (buffer[0] == PPPD_RESET_TIME &&
|
|
|
|
(buffer[5] == PPPD_SENT_DATA ||
|
|
|
|
buffer[5] == PPPD_RECV_DATA ||
|
|
|
|
buffer[5] == PPPD_TIME_STEP_LONG ||
|
|
|
|
buffer[5] == PPPD_TIME_STEP_SHORT ||
|
|
|
|
buffer[5] == PPPD_RESET_TIME)) {
|
|
|
|
|
|
|
|
goto my_file_type;
|
|
|
|
}
|
|
|
|
else {
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my_file_type:
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, 5, SEEK_SET, err) == -1)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2002-03-04 00:25:35 +00:00
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
state = g_new(pppdump_t, 1);
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->priv = (void *)state;
|
2013-12-03 20:35:50 +00:00
|
|
|
state->timestamp = pntoh32(&buffer[1]);
|
2000-09-19 17:22:11 +00:00
|
|
|
state->tenths = 0;
|
|
|
|
|
|
|
|
init_state(state);
|
|
|
|
|
2002-07-15 09:50:02 +00:00
|
|
|
state->offset = 5;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_PPP_WITH_PHDR;
|
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 = pppdump_file_type_subtype;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->snapshot_length = PPPD_BUF_SIZE; /* just guessing */
|
|
|
|
wth->subtype_read = pppdump_read;
|
|
|
|
wth->subtype_seek_read = pppdump_seek_read;
|
|
|
|
wth->subtype_close = pppdump_close;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_DSEC;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2012-06-02 15:32:34 +00:00
|
|
|
state->seek_state = g_new(pppdump_t,1);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2002-07-16 09:41:32 +00:00
|
|
|
/* If we have a random stream open, we're going to be reading
|
|
|
|
the file randomly; set up a GPtrArray of pointers to
|
|
|
|
information about how to retrieve the data for each packet. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wth->random_fh != NULL)
|
2002-07-16 09:41:32 +00:00
|
|
|
state->pids = g_ptr_array_new();
|
|
|
|
else
|
|
|
|
state->pids = NULL;
|
2000-09-19 17:22:11 +00:00
|
|
|
state->pkt_cnt = 0;
|
|
|
|
|
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;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 13:23:14 +00:00
|
|
|
/* Set part of the struct wtap_rec. */
|
2013-06-15 01:51:21 +00:00
|
|
|
static void
|
2018-02-09 00:19:12 +00:00
|
|
|
pppdump_set_phdr(wtap_rec *rec, int num_bytes,
|
2013-06-15 01:51:21 +00:00
|
|
|
direction_enum direction)
|
|
|
|
{
|
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->rec_header.packet_header.len = num_bytes;
|
|
|
|
rec->rec_header.packet_header.caplen = num_bytes;
|
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
|
2013-06-15 01:51:21 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? TRUE : FALSE);
|
2013-06-15 01:51:21 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 11:00:49 +00:00
|
|
|
/* Find the next packet and parse it; called from wtap_read(). */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2019-04-05 01:56:27 +00:00
|
|
|
pppdump_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info,
|
|
|
|
gint64 *data_offset)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
int num_bytes;
|
|
|
|
direction_enum direction;
|
|
|
|
pppdump_t *state;
|
|
|
|
pkt_id *pid;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
state = (pppdump_t *)wth->priv;
|
2002-07-16 09:41:32 +00:00
|
|
|
|
|
|
|
/* If we have a random stream open, allocate a structure to hold
|
|
|
|
the information needed to read this packet's data again. */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (wth->random_fh != NULL) {
|
2002-07-16 09:41:32 +00:00
|
|
|
pid = g_new(pkt_id, 1);
|
|
|
|
if (!pid) {
|
|
|
|
*err = errno; /* assume a malloc failed and set "errno" */
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2002-07-16 09:41:32 +00:00
|
|
|
}
|
|
|
|
pid->offset = 0;
|
|
|
|
} else
|
|
|
|
pid = NULL; /* sequential only */
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
ws_buffer_assure_space(buf, PPPD_BUF_SIZE);
|
|
|
|
if (!collate(state, wth->fh, err, err_info, ws_buffer_start_ptr(buf),
|
|
|
|
&num_bytes, &direction, pid, 0)) {
|
2017-08-26 08:30:47 +00:00
|
|
|
g_free(pid);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 09:41:32 +00:00
|
|
|
if (pid != NULL)
|
|
|
|
pid->dir = direction;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2002-07-16 09:41:32 +00:00
|
|
|
if (pid != NULL)
|
|
|
|
g_ptr_array_add(state->pids, pid);
|
2000-09-19 17:22:11 +00:00
|
|
|
/* The user's data_offset is not really an offset, but a packet number. */
|
|
|
|
*data_offset = state->pkt_cnt;
|
|
|
|
state->pkt_cnt++;
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
pppdump_set_phdr(rec, num_bytes, direction);
|
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
|
|
|
rec->ts.secs = state->timestamp;
|
|
|
|
rec->ts.nsecs = state->tenths * 100000000;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns number of bytes copied for record, -1 if failure.
|
|
|
|
*
|
2005-01-16 08:45:11 +00:00
|
|
|
* This is modeled after pppdump.c, the utility to parse pppd log files; it
|
|
|
|
* comes with the ppp distribution.
|
2000-09-19 17:22:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2002-07-15 09:50:02 +00:00
|
|
|
process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
|
2011-04-21 09:41:52 +00:00
|
|
|
int *err, gchar **err_info, pkt_id *pid)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int num_bytes = n;
|
|
|
|
int num_written;
|
|
|
|
|
|
|
|
for (; num_bytes > 0; --num_bytes) {
|
|
|
|
c = file_getc(fh);
|
2005-01-16 08:45:11 +00:00
|
|
|
if (c == EOF) {
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(fh, err_info);
|
2005-01-16 08:45:11 +00:00
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2000-09-19 17:22:11 +00:00
|
|
|
state->offset++;
|
|
|
|
switch (c) {
|
2002-07-14 10:59:38 +00:00
|
|
|
case 0x7e:
|
|
|
|
/*
|
|
|
|
* Flag Sequence for RFC 1662 HDLC-like
|
|
|
|
* framing.
|
|
|
|
*
|
|
|
|
* As this is a raw trace of octets going
|
|
|
|
* over the wire, and that might include
|
|
|
|
* the login sequence, there is no
|
|
|
|
* guarantee that *only* PPP traffic
|
|
|
|
* appears in this file, so there is no
|
|
|
|
* guarantee that the first 0x7e we see is
|
|
|
|
* a start flag sequence, and therefore we
|
|
|
|
* cannot safely ignore all characters up
|
|
|
|
* to the first 0x7e, and therefore we
|
|
|
|
* might end up with some bogus PPP
|
|
|
|
* packets.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
if (pkt->cnt > 0) {
|
2002-07-14 10:59:38 +00:00
|
|
|
/*
|
|
|
|
* We've seen stuff before this,
|
|
|
|
* so this is the end of a frame.
|
|
|
|
* Make a frame out of that stuff.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
pkt->esc = FALSE;
|
|
|
|
|
2001-12-17 22:22:42 +00:00
|
|
|
num_written = pkt->cnt;
|
2000-09-19 17:22:11 +00:00
|
|
|
pkt->cnt = 0;
|
|
|
|
if (num_written <= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-09 03:02:43 +00:00
|
|
|
if (num_written > PPPD_BUF_SIZE) {
|
2016-04-30 23:38:27 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("pppdump: File has %u-byte packet, bigger than maximum of %u",
|
2016-04-30 23:38:27 +00:00
|
|
|
num_written, PPPD_BUF_SIZE);
|
2000-11-19 20:56:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-09-19 17:22:11 +00:00
|
|
|
memcpy(pd, pkt->buf, num_written);
|
|
|
|
|
2002-07-15 09:50:02 +00:00
|
|
|
/*
|
|
|
|
* Remember the offset of the
|
|
|
|
* first record containing data
|
|
|
|
* for this packet, and how far
|
|
|
|
* into that record to skip to
|
|
|
|
* get to the beginning of the
|
|
|
|
* data for this packet; the number
|
|
|
|
* of bytes to skip into that record
|
|
|
|
* is the file offset of the first
|
|
|
|
* byte of this packet minus the
|
|
|
|
* file offset of the first byte of
|
|
|
|
* this record, minus 3 bytes for the
|
|
|
|
* header of this record (which, if
|
|
|
|
* we re-read this record, we will
|
|
|
|
* process, not skip).
|
|
|
|
*/
|
|
|
|
if (pid) {
|
|
|
|
pid->offset = pkt->id_offset;
|
|
|
|
pid->num_bytes_to_skip =
|
|
|
|
pkt->sd_offset - pkt->id_offset - 3;
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(pid->num_bytes_to_skip >= 0);
|
2002-07-15 09:50:02 +00:00
|
|
|
}
|
|
|
|
|
2000-09-19 17:22:11 +00:00
|
|
|
num_bytes--;
|
|
|
|
if (num_bytes > 0) {
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
2002-07-15 09:50:02 +00:00
|
|
|
* There's more data in this
|
|
|
|
* record.
|
|
|
|
* Set the initial data offset
|
|
|
|
* for the next packet.
|
2002-07-15 08:45:32 +00:00
|
|
|
*/
|
|
|
|
pkt->id_offset = pkt->cd_offset;
|
|
|
|
pkt->sd_offset = state->offset;
|
2002-07-15 09:50:02 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There is no more data in
|
|
|
|
* this record.
|
|
|
|
* Thus, we don't have the
|
|
|
|
* initial data offset for
|
|
|
|
* the next packet.
|
|
|
|
*/
|
|
|
|
pkt->id_offset = 0;
|
|
|
|
pkt->sd_offset = 0;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
2002-07-15 08:45:32 +00:00
|
|
|
state->num_bytes = num_bytes;
|
|
|
|
state->pkt = pkt;
|
2000-09-19 17:22:11 +00:00
|
|
|
return num_written;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-07-14 10:59:38 +00:00
|
|
|
case 0x7d:
|
|
|
|
/*
|
|
|
|
* Control Escape octet for octet-stuffed
|
|
|
|
* RFC 1662 HDLC-like framing.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
if (!pkt->esc) {
|
2002-07-14 10:59:38 +00:00
|
|
|
/*
|
|
|
|
* Control Escape not preceded by
|
|
|
|
* Control Escape; discard it
|
|
|
|
* but XOR the next octet with
|
|
|
|
* 0x20.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
pkt->esc = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-14 10:59:38 +00:00
|
|
|
/*
|
|
|
|
* Control Escape preceded by Control Escape;
|
|
|
|
* treat it as an ordinary character,
|
|
|
|
* by falling through.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2017-02-27 20:10:33 +00:00
|
|
|
/* FALL THROUGH */
|
2000-09-19 17:22:11 +00:00
|
|
|
default:
|
|
|
|
if (pkt->esc) {
|
2002-07-14 10:59:38 +00:00
|
|
|
/*
|
|
|
|
* This character was preceded by
|
|
|
|
* Control Escape, so XOR it with
|
|
|
|
* 0x20, as per RFC 1662's octet-
|
|
|
|
* stuffed framing, and clear
|
|
|
|
* the flag saying that the
|
|
|
|
* character should be escaped.
|
|
|
|
*/
|
2000-09-19 17:22:11 +00:00
|
|
|
c ^= 0x20;
|
|
|
|
pkt->esc = FALSE;
|
|
|
|
}
|
2002-07-14 10:59:38 +00:00
|
|
|
|
2011-02-16 00:44:12 +00:00
|
|
|
if (pkt->cnt >= PPPD_BUF_SIZE) {
|
2016-04-30 23:38:27 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("pppdump: File has %u-byte packet, bigger than maximum of %u",
|
2016-04-30 23:38:27 +00:00
|
|
|
pkt->cnt - 1, PPPD_BUF_SIZE);
|
2000-12-09 03:02:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-02-16 02:16:12 +00:00
|
|
|
pkt->buf[pkt->cnt++] = c;
|
2000-09-19 17:22:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we could have run out of bytes to read */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE if packet data copied, FALSE if error occurred or EOF (no more records). */
|
|
|
|
static gboolean
|
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
|
|
|
collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
|
|
|
int *num_bytes, direction_enum *direction, pkt_id *pid,
|
2009-04-22 03:07:37 +00:00
|
|
|
gint64 num_bytes_to_skip)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
int id;
|
|
|
|
pkt_t *pkt = NULL;
|
2004-10-30 09:14:36 +00:00
|
|
|
int byte0, byte1;
|
2000-09-19 17:22:11 +00:00
|
|
|
int n, num_written = 0;
|
2009-04-22 04:33:49 +00:00
|
|
|
gint64 start_offset;
|
2000-09-19 17:22:11 +00:00
|
|
|
guint32 time_long;
|
|
|
|
guint8 time_short;
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* Process any data left over in the current record when doing
|
|
|
|
* sequential processing.
|
|
|
|
*/
|
|
|
|
if (state->num_bytes > 0) {
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(num_bytes_to_skip == 0);
|
2002-07-15 08:45:32 +00:00
|
|
|
pkt = state->pkt;
|
|
|
|
num_written = process_data(state, fh, pkt, state->num_bytes,
|
2011-04-21 09:41:52 +00:00
|
|
|
pd, err, err_info, pid);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
if (num_written < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-15 09:50:02 +00:00
|
|
|
else if (num_written > 0) {
|
2000-09-19 17:22:11 +00:00
|
|
|
*num_bytes = num_written;
|
|
|
|
*direction = pkt->dir;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* if 0 bytes written, keep processing */
|
2002-07-15 08:45:32 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We didn't have any data left over, so the packet will
|
|
|
|
* start at the beginning of a record.
|
|
|
|
*/
|
|
|
|
if (pid)
|
|
|
|
pid->num_bytes_to_skip = 0;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* That didn't get all the data for this packet, so process
|
|
|
|
* subsequent records.
|
|
|
|
*/
|
2005-01-16 08:45:11 +00:00
|
|
|
start_offset = state->offset;
|
2000-09-19 17:22:11 +00:00
|
|
|
while ((id = file_getc(fh)) != EOF) {
|
|
|
|
state->offset++;
|
|
|
|
switch (id) {
|
|
|
|
case PPPD_SENT_DATA:
|
|
|
|
case PPPD_RECV_DATA:
|
|
|
|
pkt = id == PPPD_SENT_DATA ? &state->spkt : &state->rpkt;
|
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* Save the offset of the beginning of
|
|
|
|
* the current record.
|
|
|
|
*/
|
|
|
|
pkt->cd_offset = state->offset - 1;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* Get the length of the record.
|
|
|
|
*/
|
2004-10-30 09:14:36 +00:00
|
|
|
byte0 = file_getc(fh);
|
2005-01-16 08:45:11 +00:00
|
|
|
if (byte0 == EOF)
|
|
|
|
goto done;
|
|
|
|
state->offset++;
|
2004-10-30 09:14:36 +00:00
|
|
|
byte1 = file_getc(fh);
|
2005-01-16 08:45:11 +00:00
|
|
|
if (byte1 == EOF)
|
|
|
|
goto done;
|
|
|
|
state->offset++;
|
2004-10-30 09:14:36 +00:00
|
|
|
n = (byte0 << 8) | byte1;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
if (pkt->id_offset == 0) {
|
|
|
|
/*
|
|
|
|
* We don't have the initial data
|
|
|
|
* offset for this packet, which
|
|
|
|
* means this is the first
|
|
|
|
* data record for that packet.
|
|
|
|
* Save the offset of the
|
|
|
|
* beginning of that record and
|
|
|
|
* the offset of the first data
|
|
|
|
* byte in the packet, which is
|
|
|
|
* the first data byte in the
|
|
|
|
* record.
|
|
|
|
*/
|
|
|
|
pkt->id_offset = pkt->cd_offset;
|
|
|
|
pkt->sd_offset = state->offset;
|
|
|
|
}
|
|
|
|
|
2007-05-23 06:03:48 +00:00
|
|
|
if (n == 0)
|
|
|
|
continue;
|
|
|
|
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(num_bytes_to_skip < n);
|
2002-07-15 08:45:32 +00:00
|
|
|
while (num_bytes_to_skip) {
|
2005-01-16 08:45:11 +00:00
|
|
|
if (file_getc(fh) == EOF)
|
|
|
|
goto done;
|
2002-07-15 08:45:32 +00:00
|
|
|
state->offset++;
|
|
|
|
num_bytes_to_skip--;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
num_written = process_data(state, fh, pkt, n,
|
2011-04-21 09:41:52 +00:00
|
|
|
pd, err, err_info, pid);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
if (num_written < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (num_written > 0) {
|
|
|
|
*num_bytes = num_written;
|
|
|
|
*direction = pkt->dir;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* if 0 bytes written, keep looping */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPD_SEND_DELIM:
|
|
|
|
case PPPD_RECV_DELIM:
|
|
|
|
/* What can we do? */
|
|
|
|
break;
|
|
|
|
|
2001-12-17 22:22:42 +00:00
|
|
|
case PPPD_RESET_TIME:
|
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(fh, &time_long, sizeof(guint32), err, err_info))
|
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
state->offset += sizeof(guint32);
|
2013-12-03 20:35:50 +00:00
|
|
|
state->timestamp = pntoh32(&time_long);
|
2000-09-19 17:22:11 +00:00
|
|
|
state->tenths = 0;
|
|
|
|
break;
|
|
|
|
|
2001-12-17 22:22:42 +00:00
|
|
|
case PPPD_TIME_STEP_LONG:
|
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(fh, &time_long, sizeof(guint32), err, err_info))
|
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
state->offset += sizeof(guint32);
|
2013-12-03 20:35:50 +00:00
|
|
|
state->tenths += pntoh32(&time_long);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
if (state->tenths >= 10) {
|
|
|
|
state->timestamp += state->tenths / 10;
|
|
|
|
state->tenths = state->tenths % 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPD_TIME_STEP_SHORT:
|
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(fh, &time_short, sizeof(guint8), err, err_info))
|
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
state->offset += sizeof(guint8);
|
|
|
|
state->tenths += time_short;
|
|
|
|
|
|
|
|
if (state->tenths >= 10) {
|
|
|
|
state->timestamp += state->tenths / 10;
|
|
|
|
state->tenths = state->tenths % 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* XXX - bad file */
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2021-12-18 18:48:20 +00:00
|
|
|
*err_info = ws_strdup_printf("pppdump: bad ID byte 0x%02x", id);
|
2002-05-29 02:11:57 +00:00
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-01-16 08:45:11 +00:00
|
|
|
done:
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(fh, err_info);
|
2005-01-16 08:45:11 +00:00
|
|
|
if (*err == 0) {
|
|
|
|
if (state->offset != start_offset) {
|
|
|
|
/*
|
|
|
|
* We read at least one byte, so we were working
|
|
|
|
* on a record; an EOF means that record was
|
|
|
|
* cut short.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
}
|
2000-09-19 17:22:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
pppdump_seek_read(wtap *wth,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 seek_off,
|
2018-02-09 00:19:12 +00:00
|
|
|
wtap_rec *rec,
|
2013-06-16 00:20:00 +00:00
|
|
|
Buffer *buf,
|
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
|
|
|
int *err,
|
|
|
|
gchar **err_info)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
int num_bytes;
|
2013-06-16 00:20:00 +00:00
|
|
|
guint8 *pd;
|
2000-09-19 17:22:11 +00:00
|
|
|
direction_enum direction;
|
|
|
|
pppdump_t *state;
|
|
|
|
pkt_id *pid;
|
2009-04-22 03:07:37 +00:00
|
|
|
gint64 num_bytes_to_skip;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
state = (pppdump_t *)wth->priv;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2012-06-02 14:13:14 +00:00
|
|
|
pid = (pkt_id *)g_ptr_array_index(state->pids, seek_off);
|
2000-09-19 17:22:11 +00:00
|
|
|
if (!pid) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE; /* XXX - better error? */
|
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("pppdump: PID not found for record");
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->random_fh, pid->offset, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
init_state(state->seek_state);
|
2002-07-15 08:45:32 +00:00
|
|
|
state->seek_state->offset = pid->offset;
|
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(buf, PPPD_BUF_SIZE);
|
|
|
|
pd = ws_buffer_start_ptr(buf);
|
2013-06-16 00:20:00 +00:00
|
|
|
|
2002-07-15 08:45:32 +00:00
|
|
|
/*
|
|
|
|
* We'll start reading at the first record containing data from
|
|
|
|
* this packet; however, that doesn't mean "collate()" will
|
|
|
|
* stop only when we've read that packet, as there might be
|
|
|
|
* data for packets going in the other direction as well, and
|
|
|
|
* we might finish processing one of those packets before we
|
|
|
|
* finish processing the packet we're reading.
|
|
|
|
*
|
|
|
|
* Therefore, we keep reading until we get a packet that's
|
|
|
|
* going in the direction we want.
|
|
|
|
*/
|
|
|
|
num_bytes_to_skip = pid->num_bytes_to_skip;
|
|
|
|
do {
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!collate(state->seek_state, wth->random_fh, err, err_info,
|
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
|
|
|
pd, &num_bytes, &direction, NULL, num_bytes_to_skip))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2002-07-15 08:45:32 +00:00
|
|
|
num_bytes_to_skip = 0;
|
|
|
|
} while (direction != pid->dir);
|
2000-09-19 17:22:11 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
pppdump_set_phdr(rec, num_bytes, pid->dir);
|
2000-09-21 04:41:37 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2000-09-19 17:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-09 05:18:49 +00:00
|
|
|
pppdump_close(wtap *wth)
|
2000-09-19 17:22:11 +00:00
|
|
|
{
|
|
|
|
pppdump_t *state;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
state = (pppdump_t *)wth->priv;
|
2000-09-19 17:22:11 +00:00
|
|
|
|
|
|
|
if (state->seek_state) { /* should always be TRUE */
|
|
|
|
g_free(state->seek_state);
|
|
|
|
}
|
|
|
|
|
2002-07-16 09:41:32 +00:00
|
|
|
if (state->pids) {
|
2002-03-04 00:25:35 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < g_ptr_array_len(state->pids); i++) {
|
|
|
|
g_free(g_ptr_array_index(state->pids, i));
|
|
|
|
}
|
2001-12-13 05:49:13 +00:00
|
|
|
g_ptr_array_free(state->pids, TRUE);
|
2000-09-19 17:22:11 +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 pppdump_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 pppdump_info = {
|
|
|
|
"pppd log (pppdump format)", "pppd", NULL, 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(pppdump_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_pppdump(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
pppdump_file_type_subtype = wtap_register_file_type_subtype(&pppdump_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("PPPDUMP",
|
|
|
|
pppdump_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:
|
|
|
|
*/
|