2004-02-11 20:05:16 +00:00
|
|
|
/* eyesdn.c
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2004-02-11 20:05:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "eyesdn.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
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 eyesdn_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_eyesdn(void);
|
|
|
|
|
2004-02-11 20:05:16 +00:00
|
|
|
/* This module reads the output of the EyeSDN USB S0/E1 ISDN probes
|
|
|
|
* They store HDLC frames of D and B channels in a binary format
|
|
|
|
* The fileformat is
|
2013-11-08 17:17:57 +00:00
|
|
|
*
|
2004-02-11 20:05:16 +00:00
|
|
|
* 1-6 Byte: EyeSDN - Magic
|
|
|
|
* 7-n Byte: Frames
|
2013-11-08 17:17:57 +00:00
|
|
|
*
|
2004-02-11 20:05:16 +00:00
|
|
|
* Each Frame starts with the 0xff Flag byte
|
2009-04-22 03:07:37 +00:00
|
|
|
* - Bytes 0-2: timestamp (usec in network byte order)
|
2004-02-11 20:05:16 +00:00
|
|
|
* - Bytes 3-7: timestamp (40bits sec since 1970 in network byte order)
|
2008-04-20 11:53:31 +00:00
|
|
|
* - Byte 8: channel (0 for D channel, 1-30 for B1-B30)
|
|
|
|
* - Byte 9: Sender Bit 0(0 NT, 1 TE), Protocol in Bits 7:1, see enum
|
2004-02-11 20:05:16 +00:00
|
|
|
* - Byte 10-11: frame size in bytes
|
|
|
|
* - Byte 12-n: Frame Payload
|
2013-11-08 17:17:57 +00:00
|
|
|
*
|
2004-02-11 20:05:16 +00:00
|
|
|
* All multibyte values are represented in network byte order
|
|
|
|
* The frame is terminated with a flag character (0xff)
|
|
|
|
* bytes 0xff within a frame are escaped using the 0xfe escape character
|
|
|
|
* the byte following the escape character is decremented by two:
|
|
|
|
* so 0xfe 0xfd is actually a 0xff
|
|
|
|
* Characters that need to be escaped are 0xff and 0xfe
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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
|
|
|
static gboolean esc_read(FILE_T fh, guint8 *buf, int len, int *err, gchar **err_info)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
int i;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
for(i=0; i<len; i++) {
|
|
|
|
value=file_getc(fh);
|
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(value==-1) {
|
|
|
|
/* EOF or error */
|
|
|
|
*err=file_error(fh, err_info);
|
|
|
|
if(*err==0)
|
|
|
|
*err=WTAP_ERR_SHORT_READ;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(value==0xff) {
|
|
|
|
/* error !!, read into next frame */
|
|
|
|
*err=WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info=g_strdup("eyesdn: No flag character seen in frame");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-06 19:37:49 +00:00
|
|
|
if(value==0xfe) {
|
|
|
|
/* we need to escape */
|
|
|
|
value=file_getc(fh);
|
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(value==-1) {
|
|
|
|
/* EOF or error */
|
|
|
|
*err=file_error(fh, err_info);
|
|
|
|
if(*err==0)
|
|
|
|
*err=WTAP_ERR_SHORT_READ;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-06 19:37:49 +00:00
|
|
|
value+=2;
|
|
|
|
}
|
|
|
|
buf[i]=value;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
2010-06-06 19:37:49 +00:00
|
|
|
|
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
|
|
|
return TRUE;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Magic text to check for eyesdn-ness of file */
|
|
|
|
static const unsigned char eyesdn_hdr_magic[] =
|
|
|
|
{ 'E', 'y', 'e', 'S', 'D', 'N'};
|
2015-11-16 21:02:43 +00:00
|
|
|
#define EYESDN_HDR_MAGIC_SIZE sizeof(eyesdn_hdr_magic)
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2004-02-13 19:19:13 +00:00
|
|
|
/* Size of a record header */
|
2004-02-11 20:05:16 +00:00
|
|
|
#define EYESDN_HDR_LENGTH 12
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
static gboolean eyesdn_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 eyesdn_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);
|
|
|
|
static int read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer* buf,
|
2012-10-18 23:11:40 +00:00
|
|
|
int *err, gchar **err_info);
|
2004-02-11 20:05:16 +00:00
|
|
|
|
|
|
|
/* Seeks to the beginning of the next packet, and returns the
|
2011-04-21 09:41:52 +00:00
|
|
|
byte offset. Returns -1 on failure, and sets "*err" to the error
|
|
|
|
and "*err_info" to null or an additional error string. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gint64 eyesdn_seek_next_packet(wtap *wth, int *err, gchar **err_info)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
int byte;
|
|
|
|
gint64 cur_off;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
while ((byte = file_getc(wth->fh)) != EOF) {
|
2010-06-06 19:37:49 +00:00
|
|
|
if (byte == 0xff) {
|
2014-05-09 05:18:49 +00:00
|
|
|
cur_off = file_tell(wth->fh);
|
2010-06-06 19:37:49 +00:00
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
2014-05-09 05:18:49 +00:00
|
|
|
*err = file_error(wth->fh, err_info);
|
2010-06-06 19:37:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return cur_off;
|
|
|
|
}
|
|
|
|
}
|
2012-12-27 22:59:39 +00:00
|
|
|
/* EOF or error. */
|
2014-05-09 05:18:49 +00:00
|
|
|
*err = file_error(wth->fh, err_info);
|
2010-06-06 19:37:49 +00:00
|
|
|
return -1;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val eyesdn_open(wtap *wth, int *err, gchar **err_info)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2004-03-23 00:17:50 +00:00
|
|
|
char magic[EYESDN_HDR_MAGIC_SIZE];
|
|
|
|
|
2004-02-11 20:05:16 +00:00
|
|
|
/* Look for eyesdn header */
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, 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;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
2004-03-23 00:17:50 +00:00
|
|
|
if (memcmp(magic, eyesdn_hdr_magic, EYESDN_HDR_MAGIC_SIZE) != 0)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
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 = eyesdn_file_type_subtype;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->snapshot_length = 0; /* not known */
|
|
|
|
wth->subtype_read = eyesdn_read;
|
|
|
|
wth->subtype_seek_read = eyesdn_seek_read;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
/* Find the next record and parse it; called from wtap_read(). */
|
|
|
|
static gboolean eyesdn_read(wtap *wth, wtap_rec *rec, Buffer *buf,
|
|
|
|
int *err, gchar **err_info, gint64 *data_offset)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 offset;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* Find the next record */
|
2014-05-09 05:18:49 +00:00
|
|
|
offset = eyesdn_seek_next_packet(wth, err, err_info);
|
2004-02-11 20:05:16 +00:00
|
|
|
if (offset < 1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2004-02-11 20:05:16 +00:00
|
|
|
*data_offset = offset;
|
2013-06-17 21:18:47 +00:00
|
|
|
|
|
|
|
/* Parse the record */
|
2019-04-05 01:56:27 +00:00
|
|
|
return read_eyesdn_rec(wth->fh, rec, buf, err, err_info);
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Used to read packets in random-access fashion */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
eyesdn_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
|
2014-01-02 20:47:21 +00:00
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
return read_eyesdn_rec(wth->random_fh, rec, buf, err, err_info);
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 21:18:47 +00:00
|
|
|
/* Parses a record. */
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
read_eyesdn_rec(FILE_T fh, wtap_rec *rec, Buffer *buf, int *err,
|
2013-06-17 21:18:47 +00:00
|
|
|
gchar **err_info)
|
2004-02-11 20:05:16 +00:00
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
|
2004-02-12 21:25:07 +00:00
|
|
|
guint8 hdr[EYESDN_HDR_LENGTH];
|
2009-04-22 03:07:37 +00:00
|
|
|
time_t secs;
|
|
|
|
int usecs;
|
2021-01-20 03:02:01 +00:00
|
|
|
guint pkt_len;
|
2006-09-29 08:47:51 +00:00
|
|
|
guint8 channel, direction;
|
2015-01-02 00:45:22 +00:00
|
|
|
guint8 *pd;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2004-02-12 21:25:07 +00:00
|
|
|
/* Our file pointer should be at the summary information header
|
|
|
|
* for a packet. Read in that header and extract the useful
|
|
|
|
* information.
|
2004-02-11 20:05:16 +00:00
|
|
|
*/
|
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 (!esc_read(fh, hdr, EYESDN_HDR_LENGTH, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
/* extract information from header */
|
|
|
|
usecs = pntoh24(&hdr[0]);
|
2013-11-08 17:17:57 +00:00
|
|
|
#ifdef TV64BITS
|
2015-01-02 00:45:22 +00:00
|
|
|
secs = hdr[3];
|
2013-11-08 17:17:57 +00:00
|
|
|
#else
|
2015-01-02 00:45:22 +00:00
|
|
|
secs = 0;
|
2013-11-08 17:17:57 +00:00
|
|
|
#endif
|
2015-01-02 00:45:22 +00:00
|
|
|
secs = (secs << 8) | hdr[4];
|
|
|
|
secs = (secs << 8) | hdr[5];
|
|
|
|
secs = (secs << 8) | hdr[6];
|
|
|
|
secs = (secs << 8) | hdr[7];
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2015-01-02 00:45:22 +00:00
|
|
|
channel = hdr[8];
|
|
|
|
direction = hdr[9];
|
|
|
|
pkt_len = pntoh16(&hdr[10]);
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2008-04-20 11:53:31 +00:00
|
|
|
switch(direction >> 1) {
|
2010-06-06 19:37:49 +00:00
|
|
|
|
2008-04-20 11:53:31 +00:00
|
|
|
default:
|
2008-05-07 05:26:40 +00:00
|
|
|
case EYESDN_ENCAP_ISDN: /* ISDN */
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->isdn.uton = direction & 1;
|
|
|
|
pseudo_header->isdn.channel = channel;
|
|
|
|
if(channel) { /* bearer channels */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */
|
2012-10-18 23:11:40 +00:00
|
|
|
pseudo_header->isdn.uton=!pseudo_header->isdn.uton; /* bug */
|
2010-06-06 19:37:49 +00:00
|
|
|
} else { /* D channel */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ISDN;
|
2008-04-20 11:53:31 +00:00
|
|
|
}
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EYESDN_ENCAP_MSG: /* Layer 1 message */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_LAYER1_EVENT;
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->l1event.uton = (direction & 1);
|
|
|
|
break;
|
|
|
|
|
2013-11-08 17:17:57 +00:00
|
|
|
case EYESDN_ENCAP_LAPB: /* X.25 via LAPB */
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_LAPB;
|
2018-09-26 00:12:43 +00:00
|
|
|
pseudo_header->dte_dce.flags = (direction & 1) ? 0 : 0x80;
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-07 05:26:40 +00:00
|
|
|
case EYESDN_ENCAP_ATM: { /* ATM cells */
|
2008-04-20 11:53:31 +00:00
|
|
|
#define CELL_LEN 53
|
2010-06-06 19:37:49 +00:00
|
|
|
unsigned char cell[CELL_LEN];
|
|
|
|
gint64 cur_off;
|
|
|
|
|
|
|
|
if(pkt_len != CELL_LEN) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2010-06-06 19:37:49 +00:00
|
|
|
*err_info = g_strdup_printf(
|
|
|
|
"eyesdn: ATM cell has a length != 53 (%u)",
|
|
|
|
pkt_len);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2010-06-06 19:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cur_off = file_tell(fh);
|
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 (!esc_read(fh, cell, CELL_LEN, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2010-06-06 19:37:49 +00:00
|
|
|
if (file_seek(fh, cur_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED;
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->atm.flags=ATM_RAW_CELL;
|
|
|
|
pseudo_header->atm.aal=AAL_UNKNOWN;
|
|
|
|
pseudo_header->atm.type=TRAF_UMTS_FP;
|
|
|
|
pseudo_header->atm.subtype=TRAF_ST_UNKNOWN;
|
|
|
|
pseudo_header->atm.vpi=((cell[0]&0xf)<<4) + (cell[0]&0xf);
|
|
|
|
pseudo_header->atm.vci=((cell[0]&0xf)<<4) + cell[0]; /* from cell */
|
|
|
|
pseudo_header->atm.channel=direction & 1;
|
|
|
|
}
|
|
|
|
break;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2008-05-07 05:26:40 +00:00
|
|
|
case EYESDN_ENCAP_MTP2: /* SS7 frames */
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->mtp2.sent = direction & 1;
|
|
|
|
pseudo_header->mtp2.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN;
|
2013-11-08 17:17:57 +00:00
|
|
|
pseudo_header->mtp2.link_number = channel;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR;
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-27 21:13:26 +00:00
|
|
|
case EYESDN_ENCAP_DPNSS: /* DPNSS */
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->isdn.uton = direction & 1;
|
|
|
|
pseudo_header->isdn.channel = channel;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DPNSS;
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-27 21:13:26 +00:00
|
|
|
case EYESDN_ENCAP_DASS2: /* DASS2 frames */
|
2010-06-06 19:37:49 +00:00
|
|
|
pseudo_header->isdn.uton = direction & 1;
|
|
|
|
pseudo_header->isdn.channel = channel;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_DPNSS;
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-27 21:13:26 +00:00
|
|
|
case EYESDN_ENCAP_BACNET: /* BACNET async over HDLC frames */
|
2012-04-04 07:33:39 +00:00
|
|
|
pseudo_header->isdn.uton = direction & 1;
|
|
|
|
pseudo_header->isdn.channel = channel;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR;
|
2010-06-06 19:37:49 +00:00
|
|
|
break;
|
2012-04-04 07:33:39 +00:00
|
|
|
|
|
|
|
case EYESDN_ENCAP_V5_EF: /* V5EF */
|
|
|
|
pseudo_header->isdn.uton = direction & 1;
|
|
|
|
pseudo_header->isdn.channel = channel;
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = WTAP_ENCAP_V5_EF;
|
2012-04-04 07:33:39 +00:00
|
|
|
break;
|
2010-06-06 19:37:49 +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
|
|
|
if(pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2010-06-06 19:37:49 +00:00
|
|
|
*err_info = g_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u",
|
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
|
|
|
pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
|
|
|
rec->presence_flags = WTAP_HAS_TS;
|
|
|
|
rec->ts.secs = secs;
|
|
|
|
rec->ts.nsecs = usecs * 1000;
|
|
|
|
rec->rec_header.packet_header.caplen = pkt_len;
|
|
|
|
rec->rec_header.packet_header.len = pkt_len;
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2013-06-16 00:20:00 +00:00
|
|
|
/* Make sure we have enough room for the packet */
|
2016-04-30 01:47:49 +00:00
|
|
|
ws_buffer_assure_space(buf, pkt_len);
|
2004-02-11 20:05:16 +00:00
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
pd = ws_buffer_start_ptr(buf);
|
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 (!esc_read(fh, pd, pkt_len, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2004-02-11 20:05:16 +00:00
|
|
|
}
|
2010-06-05 22:59:20 +00:00
|
|
|
|
|
|
|
|
2010-06-06 19:37:49 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err)
|
2010-06-05 22:59:20 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
int i;
|
|
|
|
guint8 byte;
|
|
|
|
static const guint8 esc = 0xfe;
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2010-06-06 19:37:49 +00:00
|
|
|
for(i=0; i<len; i++) {
|
|
|
|
byte=buf[i];
|
|
|
|
if(byte == 0xff || byte == 0xfe) {
|
|
|
|
/*
|
|
|
|
* Escape the frame delimiter and escape byte.
|
|
|
|
*/
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &esc, sizeof esc, err))
|
2010-06-06 19:37:49 +00:00
|
|
|
return FALSE;
|
|
|
|
byte-=2;
|
|
|
|
}
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &byte, sizeof byte, err))
|
2010-06-06 19:37:49 +00:00
|
|
|
return FALSE;
|
2010-06-05 22:59:20 +00:00
|
|
|
}
|
2010-06-06 19:37:49 +00:00
|
|
|
return TRUE;
|
2010-06-05 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean eyesdn_dump(wtap_dumper *wdh,
|
2018-02-09 00:19:12 +00:00
|
|
|
const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info);
|
2010-06-05 22:59:20 +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 gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
|
2010-06-05 22:59:20 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
wdh->subtype_write=eyesdn_dump;
|
2010-06-05 22:59:20 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, eyesdn_hdr_magic,
|
2010-06-06 19:37:49 +00:00
|
|
|
EYESDN_HDR_MAGIC_SIZE, err))
|
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += EYESDN_HDR_MAGIC_SIZE;
|
|
|
|
*err=0;
|
|
|
|
return TRUE;
|
2010-06-05 22:59:20 +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 eyesdn_dump_can_write_encap(int encap)
|
2010-06-05 22:59:20 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
switch (encap) {
|
|
|
|
case WTAP_ENCAP_ISDN:
|
|
|
|
case WTAP_ENCAP_LAYER1_EVENT:
|
|
|
|
case WTAP_ENCAP_DPNSS:
|
|
|
|
case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
|
|
|
|
case WTAP_ENCAP_LAPB:
|
2012-04-05 20:25:26 +00:00
|
|
|
case WTAP_ENCAP_MTP2_WITH_PHDR:
|
2012-04-06 03:42:32 +00:00
|
|
|
case WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR:
|
2010-06-06 19:37:49 +00:00
|
|
|
case WTAP_ENCAP_PER_PACKET:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2010-06-06 19:37:49 +00:00
|
|
|
}
|
2010-06-05 22:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
* Returns TRUE on success, FALSE on failure. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean eyesdn_dump(wtap_dumper *wdh,
|
2018-02-09 00:19:12 +00:00
|
|
|
const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info _U_)
|
2010-06-05 22:59:20 +00:00
|
|
|
{
|
2010-06-06 19:37:49 +00:00
|
|
|
static const guint8 start_flag = 0xff;
|
2018-02-09 00:19:12 +00:00
|
|
|
const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
|
2010-06-06 19:37:49 +00:00
|
|
|
guint8 buf[EYESDN_HDR_LENGTH];
|
|
|
|
int usecs;
|
|
|
|
time_t secs;
|
|
|
|
int channel;
|
|
|
|
int origin;
|
|
|
|
int protocol;
|
|
|
|
int size;
|
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_type != REC_TYPE_PACKET) {
|
2014-12-18 00:31:49 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_REC_TYPE;
|
2014-05-24 18:28:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write out anything bigger than we can read.
|
|
|
|
* (The length field in packet headers is 16 bits, which
|
|
|
|
* imposes a hard limit.) */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > 65535) {
|
2014-01-22 00:26:36 +00:00
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
usecs=rec->ts.nsecs/1000;
|
|
|
|
secs=rec->ts.secs;
|
|
|
|
size=rec->rec_header.packet_header.caplen;
|
2010-06-06 19:37:49 +00:00
|
|
|
origin = pseudo_header->isdn.uton;
|
|
|
|
channel = pseudo_header->isdn.channel;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
switch(rec->rec_header.packet_header.pkt_encap) {
|
2010-06-06 19:37:49 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ISDN:
|
|
|
|
protocol=EYESDN_ENCAP_ISDN; /* set depending on decoder format and mode */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_LAYER1_EVENT:
|
|
|
|
protocol=EYESDN_ENCAP_MSG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_DPNSS:
|
|
|
|
protocol=EYESDN_ENCAP_DPNSS;
|
|
|
|
break;
|
|
|
|
|
2010-06-05 22:59:20 +00:00
|
|
|
#if 0
|
2010-06-06 19:37:49 +00:00
|
|
|
case WTAP_ENCAP_DASS2:
|
|
|
|
protocol=EYESDN_ENCAP_DASS2;
|
|
|
|
break;
|
2010-06-05 22:59:20 +00:00
|
|
|
#endif
|
2010-06-06 19:37:49 +00:00
|
|
|
|
|
|
|
case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
|
|
|
|
protocol=EYESDN_ENCAP_ATM;
|
|
|
|
channel=0x80;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_LAPB:
|
|
|
|
protocol=EYESDN_ENCAP_LAPB;
|
|
|
|
break;
|
|
|
|
|
2012-04-05 20:25:26 +00:00
|
|
|
case WTAP_ENCAP_MTP2_WITH_PHDR:
|
2010-06-06 19:37:49 +00:00
|
|
|
protocol=EYESDN_ENCAP_MTP2;
|
|
|
|
break;
|
|
|
|
|
2012-04-06 03:42:32 +00:00
|
|
|
case WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR:
|
2010-06-06 19:37:49 +00:00
|
|
|
protocol=EYESDN_ENCAP_BACNET;
|
|
|
|
break;
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2012-04-04 07:33:39 +00:00
|
|
|
case WTAP_ENCAP_V5_EF:
|
|
|
|
protocol=EYESDN_ENCAP_V5_EF;
|
|
|
|
break;
|
2010-06-06 19:37:49 +00:00
|
|
|
|
|
|
|
default:
|
2014-12-17 06:40:45 +00:00
|
|
|
*err=WTAP_ERR_UNWRITABLE_ENCAP;
|
2010-06-06 19:37:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
phton24(&buf[0], usecs);
|
|
|
|
|
|
|
|
buf[3] = (guint8)0;
|
|
|
|
buf[4] = (guint8)(0xff & (secs >> 24));
|
|
|
|
buf[5] = (guint8)(0xff & (secs >> 16));
|
|
|
|
buf[6] = (guint8)(0xff & (secs >> 8));
|
|
|
|
buf[7] = (guint8)(0xff & (secs >> 0));
|
|
|
|
|
|
|
|
buf[8] = (guint8) channel;
|
|
|
|
buf[9] = (guint8) (origin?1:0) + (protocol << 1);
|
|
|
|
phtons(&buf[10], size);
|
2013-11-08 17:17:57 +00:00
|
|
|
|
2010-06-06 19:37:49 +00:00
|
|
|
/* start flag */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &start_flag, sizeof start_flag, err))
|
2010-06-06 19:37:49 +00:00
|
|
|
return FALSE;
|
|
|
|
if (!esc_write(wdh, buf, 12, err))
|
|
|
|
return FALSE;
|
|
|
|
if (!esc_write(wdh, pd, size, err))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2010-06-05 22:59:20 +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 eyesdn_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 eyesdn_info = {
|
|
|
|
"EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "trc", 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(eyesdn_blocks_supported),
|
|
|
|
eyesdn_dump_can_write_encap, eyesdn_dump_open, NULL
|
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
|
|
|
};
|
|
|
|
|
|
|
|
void register_eyesdn(void)
|
|
|
|
{
|
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
|
|
|
eyesdn_file_type_subtype = wtap_register_file_type_subtypes(&eyesdn_info);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register name for backwards compatibility with the
|
|
|
|
* wtap_filetypes table in Lua.
|
|
|
|
*/
|
|
|
|
wtap_register_backwards_compatibility_lua_name("EYESDN",
|
|
|
|
eyesdn_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:
|
|
|
|
*/
|