2016-12-02 19:18:50 +00:00
|
|
|
%top {
|
|
|
|
/* Include this before everything else, for various large-file definitions */
|
|
|
|
#include "config.h"
|
2021-10-17 12:17:47 +00:00
|
|
|
#include <wireshark.h>
|
2016-12-02 19:18:50 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* We want a reentrant scanner.
|
|
|
|
*/
|
|
|
|
%option reentrant
|
|
|
|
|
2013-02-10 19:13:07 +00:00
|
|
|
/*
|
|
|
|
* We don't use input, so don't generate code for it.
|
|
|
|
*/
|
|
|
|
%option noinput
|
|
|
|
|
2007-07-30 20:22:37 +00:00
|
|
|
/*
|
|
|
|
* We don't use unput, so don't generate code for it.
|
|
|
|
*/
|
2007-11-26 18:55:17 +00:00
|
|
|
%option nounput
|
2007-07-30 20:22:37 +00:00
|
|
|
|
|
|
|
/*
|
2015-11-05 23:35:04 +00:00
|
|
|
* We don't read interactively from the terminal.
|
2007-07-30 20:22:37 +00:00
|
|
|
*/
|
2007-05-24 17:02:06 +00:00
|
|
|
%option never-interactive
|
2007-07-30 20:22:37 +00:00
|
|
|
|
2015-12-05 03:52:51 +00:00
|
|
|
/*
|
|
|
|
* We want to stop processing when we get to the end of the input.
|
|
|
|
*/
|
|
|
|
%option noyywrap
|
|
|
|
|
2007-07-30 20:22:37 +00:00
|
|
|
/*
|
2016-03-31 01:44:01 +00:00
|
|
|
* The type for the state we keep for a scanner.
|
|
|
|
*/
|
|
|
|
%option extra-type="k12text_state_t *"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prefix scanner routines with "k12text_" rather than "yy", so this scanner
|
2007-07-30 20:22:37 +00:00
|
|
|
* can coexist with other scanners.
|
|
|
|
*/
|
2016-03-31 01:44:01 +00:00
|
|
|
%option prefix="k12text_"
|
2007-07-30 20:22:37 +00:00
|
|
|
|
|
|
|
%option outfile="k12text.c"
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
/* Options useful for debugging */
|
|
|
|
/* noline: Prevent generation of #line directives */
|
|
|
|
/* Seems to be required when using the */
|
|
|
|
/* Windows VS debugger so as to be able */
|
|
|
|
/* to properly step through the code and */
|
|
|
|
/* set breakpoints & etc using the */
|
|
|
|
/* k12text.c file rather than the */
|
|
|
|
/* k12text.l file */
|
|
|
|
/* XXX: %option noline gives an error message: */
|
|
|
|
/* "unrecognized %option: line" */
|
|
|
|
/* with flex 2.5.35; the --noline */
|
|
|
|
/* command-line option works OK. */
|
|
|
|
/* */
|
|
|
|
/* debug: Do output of "rule acceptance" info */
|
|
|
|
/* during parse */
|
|
|
|
/* */
|
2009-01-14 20:50:39 +00:00
|
|
|
/* %option noline */
|
|
|
|
/* %option debug */
|
2009-01-05 19:45:58 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* We have to override the memory allocators so that we don't get
|
|
|
|
* "unused argument" warnings from the yyscanner argument (which
|
|
|
|
* we don't use, as we have a global memory allocator).
|
|
|
|
*
|
|
|
|
* We provide, as macros, our own versions of the routines generated by Flex,
|
|
|
|
* which just call malloc()/realloc()/free() (as the Flex versions do),
|
|
|
|
* discarding the extra argument.
|
|
|
|
*/
|
|
|
|
%option noyyalloc
|
|
|
|
%option noyyrealloc
|
|
|
|
%option noyyfree
|
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
%{
|
|
|
|
/* k12text.l
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2018-04-30 07:47:58 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-11-26 18:55:17 +00:00
|
|
|
|
|
|
|
/*
|
2007-05-24 17:02:06 +00:00
|
|
|
* TODO:
|
|
|
|
* - fix timestamps after midnight
|
|
|
|
* - verify encapsulations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "wtap.h"
|
|
|
|
#include "file_wrappers.h"
|
2014-07-15 23:40:46 +00:00
|
|
|
#include <wsutil/buffer.h>
|
2007-05-24 17:02:06 +00:00
|
|
|
#include "k12.h"
|
|
|
|
|
2008-09-07 13:43:49 +00:00
|
|
|
#ifndef HAVE_UNISTD_H
|
|
|
|
#define YY_NO_UNISTD_H
|
|
|
|
#endif
|
|
|
|
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Disable diagnostics in the code generated by Flex.
|
|
|
|
*/
|
2022-11-19 22:52:09 +00:00
|
|
|
DIAG_OFF_FLEX()
|
2017-08-18 19:11:47 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* State kept by the scanner.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
FILE_T fh;
|
2016-09-15 22:20:26 +00:00
|
|
|
int err;
|
|
|
|
gchar *err_info;
|
2016-03-31 01:44:01 +00:00
|
|
|
int start_state;
|
|
|
|
|
|
|
|
guint g_h;
|
|
|
|
guint g_m;
|
|
|
|
guint g_s;
|
|
|
|
guint g_ms;
|
|
|
|
guint g_ns;
|
|
|
|
gint g_encap;
|
2017-03-27 21:14:59 +00:00
|
|
|
guint8 *bb;
|
2016-03-31 01:44:01 +00:00
|
|
|
guint ii;
|
|
|
|
gboolean is_k12text;
|
|
|
|
gboolean at_eof;
|
|
|
|
guint junk_chars;
|
|
|
|
gchar* error_str;
|
|
|
|
guint64 file_bytes_read;
|
|
|
|
gboolean ok_frame;
|
|
|
|
} k12text_state_t;
|
|
|
|
|
|
|
|
#define KERROR(text) do { yyextra->error_str = g_strdup(text); yyterminate(); } while(0)
|
|
|
|
#define SET_HOURS(text) yyextra->g_h = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_MINUTES(text) yyextra->g_m = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_SECONDS(text) yyextra->g_s = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_MS(text) yyextra->g_ms = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_NS(text) yyextra->g_ns = (guint) strtoul(text,NULL,10)
|
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
|
|
|
#define ADD_BYTE(text) do {if (yyextra->ii >= WTAP_MAX_PACKET_SIZE_STANDARD) {KERROR("frame too large");} yyextra->bb[yyextra->ii++] = (guint8)strtoul(text,NULL,16); } while(0)
|
2016-03-31 01:44:01 +00:00
|
|
|
#define FINALIZE_FRAME() do { yyextra->ok_frame = TRUE; } while (0)
|
2007-11-26 18:55:17 +00:00
|
|
|
/*~ #define ECHO*/
|
2016-03-31 01:44:01 +00:00
|
|
|
#define YY_USER_ACTION yyextra->file_bytes_read += yyleng;
|
|
|
|
#define YY_USER_INIT { \
|
|
|
|
k12text_state_t *scanner_state = k12text_get_extra(yyscanner); \
|
|
|
|
BEGIN(scanner_state->start_state); \
|
|
|
|
}
|
|
|
|
#define YY_INPUT(buf,result,max_size) { \
|
|
|
|
k12text_state_t *scanner_state = k12text_get_extra(yyscanner); \
|
|
|
|
int c = file_getc(scanner_state->fh); \
|
|
|
|
if (c == EOF) { \
|
2016-09-15 22:20:26 +00:00
|
|
|
scanner_state->err = file_error(scanner_state->fh, \
|
|
|
|
&scanner_state->err_info); \
|
|
|
|
if (scanner_state->err == 0) \
|
|
|
|
scanner_state->err = WTAP_ERR_SHORT_READ; \
|
2016-03-31 01:44:01 +00:00
|
|
|
result = YY_NULL; \
|
|
|
|
} else { \
|
|
|
|
buf[0] = c; \
|
|
|
|
result = 1; \
|
|
|
|
} \
|
|
|
|
}
|
2007-05-24 17:02:06 +00:00
|
|
|
#define MAX_JUNK 400000
|
|
|
|
#define ECHO
|
2012-05-04 16:56:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Private per-file data.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/*
|
|
|
|
* The file position after the end of the previous frame processed by
|
|
|
|
* k12text_read.
|
|
|
|
*
|
|
|
|
* We need to keep this around, and seek to it at the beginning of
|
|
|
|
* each call to k12text_read(), since the lexer undoubtedly did some
|
|
|
|
* amount of look-ahead when processing the previous frame.
|
|
|
|
*/
|
|
|
|
gint64 next_frame_offset;
|
|
|
|
} k12text_t;
|
2016-03-31 01:44:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sleazy hack to suppress compiler warnings in yy_fatal_error().
|
|
|
|
*/
|
|
|
|
#define YY_EXIT_FAILURE ((void)yyscanner, 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for the allocators, to discard the extra argument.
|
|
|
|
*/
|
|
|
|
#define k12text_alloc(size, yyscanner) (void *)malloc(size)
|
|
|
|
#define k12text_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
|
|
|
|
#define k12text_free(ptr, yyscanner) free((char *)ptr)
|
|
|
|
|
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 k12text_file_type_subtype = -1;
|
|
|
|
|
|
|
|
void register_k12text(void);
|
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
%}
|
|
|
|
start_timestamp \053[\055]{9}\053[\055]{15,100}\053[\055]{10,100}\053
|
|
|
|
oneormoredigits [0-9]+:
|
|
|
|
twodigits [0-9][0-9]
|
|
|
|
colon :
|
|
|
|
comma ,
|
|
|
|
threedigits [0-9][0-9][0-9]
|
|
|
|
start_bytes \174\060\040\040\040\174
|
|
|
|
bytes_junk \174[A-F0-9][A-F0-9\040][A-F0-9\040][A-F0-9\040]\174
|
|
|
|
byte [a-f0-9][a-f0-9]\174
|
2009-01-05 19:45:58 +00:00
|
|
|
end_bytes \015?\012\015?\012
|
2007-05-24 17:02:06 +00:00
|
|
|
eth ETHER
|
2014-12-17 05:29:41 +00:00
|
|
|
mtp2 MTP-L2
|
|
|
|
sscop SSCOP
|
2007-05-24 17:02:06 +00:00
|
|
|
sscfnni SSCF
|
|
|
|
hdlc HDLC
|
|
|
|
|
2009-01-05 19:45:58 +00:00
|
|
|
%START MAGIC NEXT_FRAME HOURS MINUTES M2S SECONDS S2M MS M2N NS ENCAP STARTBYTES BYTE
|
2007-05-24 17:02:06 +00:00
|
|
|
%%
|
2016-03-31 01:44:01 +00:00
|
|
|
<MAGIC>{start_timestamp} { yyextra->is_k12text = TRUE; yyterminate(); }
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
<MAGIC>. { if (++ yyextra->junk_chars > MAX_JUNK) { yyextra->is_k12text = FALSE; yyterminate(); } }
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2009-01-05 19:45:58 +00:00
|
|
|
<NEXT_FRAME>{start_timestamp} {BEGIN(HOURS); }
|
2007-05-24 17:02:06 +00:00
|
|
|
<HOURS>{oneormoredigits} { SET_HOURS(yytext); BEGIN(MINUTES); }
|
|
|
|
<MINUTES>{twodigits} { SET_MINUTES(yytext); BEGIN(M2S);}
|
|
|
|
<M2S>{colon} { BEGIN(SECONDS);}
|
|
|
|
<SECONDS>{twodigits} { SET_SECONDS(yytext); BEGIN(S2M); }
|
|
|
|
<S2M>{comma} { BEGIN(MS); }
|
|
|
|
<MS>{threedigits} { SET_MS(yytext); BEGIN(M2N); }
|
|
|
|
<M2N>{comma} { BEGIN(NS); }
|
|
|
|
<NS>{threedigits} { SET_NS(yytext); BEGIN(ENCAP);}
|
2016-03-31 01:44:01 +00:00
|
|
|
<ENCAP>{eth} {yyextra->g_encap = WTAP_ENCAP_ETHERNET; BEGIN(STARTBYTES); }
|
|
|
|
<ENCAP>{mtp2} {yyextra->g_encap = WTAP_ENCAP_MTP2; BEGIN(STARTBYTES); }
|
|
|
|
<ENCAP>{sscop} {yyextra->g_encap = WTAP_ENCAP_ATM_PDUS; BEGIN(STARTBYTES); }
|
|
|
|
<ENCAP>{sscfnni} {yyextra->g_encap = WTAP_ENCAP_MTP3; BEGIN(STARTBYTES); }
|
|
|
|
<ENCAP>{hdlc} {yyextra->g_encap = WTAP_ENCAP_CHDLC; BEGIN(STARTBYTES); }
|
2014-12-19 22:07:29 +00:00
|
|
|
<ENCAP,STARTBYTES>{start_bytes} { BEGIN(BYTE); }
|
2007-05-24 17:02:06 +00:00
|
|
|
<BYTE>{byte} { ADD_BYTE(yytext); }
|
|
|
|
<BYTE>{bytes_junk} ;
|
|
|
|
<BYTE>{end_bytes} { FINALIZE_FRAME(); yyterminate(); }
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
. { if (++yyextra->junk_chars > MAX_JUNK) { KERROR("too much junk"); } }
|
|
|
|
<<EOF>> { yyextra->at_eof = TRUE; yyterminate(); }
|
2007-05-24 17:02:06 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Turn diagnostics back on, so we check the code that we've written.
|
|
|
|
*/
|
2022-11-19 22:52:09 +00:00
|
|
|
DIAG_ON_FLEX()
|
2017-08-18 19:11:47 +00:00
|
|
|
|
2013-05-17 21:55:33 +00:00
|
|
|
/* Fill in pkthdr */
|
2009-01-06 21:25:11 +00:00
|
|
|
|
2014-12-17 05:29:41 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
k12text_set_headers(wtap_rec *rec, k12text_state_t *state,
|
2016-03-31 01:44:01 +00:00
|
|
|
int *err, gchar **err_info)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_type = REC_TYPE_PACKET;
|
2021-08-30 02:12:13 +00:00
|
|
|
rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
2013-05-17 21:55:33 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->ts.secs = 946681200 + (3600*state->g_h) + (60*state->g_m) + state->g_s;
|
|
|
|
rec->ts.nsecs = 1000000*state->g_ms + 1000*state->g_ns;
|
2013-05-17 21:55:33 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.caplen = rec->rec_header.packet_header.len = state->ii;
|
2013-05-17 21:55:33 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pkt_encap = state->g_encap;
|
2013-05-17 21:55:33 +00:00
|
|
|
|
2009-01-06 21:25:11 +00:00
|
|
|
/* The file-encap is WTAP_ENCAP_PER_PACKET */
|
2016-03-31 01:44:01 +00:00
|
|
|
switch(state->g_encap) {
|
2009-01-06 21:25:11 +00:00
|
|
|
case WTAP_ENCAP_ETHERNET:
|
2018-02-09 00:19:12 +00:00
|
|
|
rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0;
|
2009-01-06 21:25:11 +00:00
|
|
|
break;
|
|
|
|
case WTAP_ENCAP_MTP3:
|
|
|
|
case WTAP_ENCAP_CHDLC:
|
|
|
|
/* no pseudo_header to fill in for these types */
|
|
|
|
break;
|
2011-03-29 14:29:45 +00:00
|
|
|
case WTAP_ENCAP_MTP2: /* not (yet) supported */
|
2014-12-17 05:29:41 +00:00
|
|
|
/* XXX: I don't know how to fill in the */
|
|
|
|
/* pseudo_header for these types. */
|
2014-12-17 06:22:29 +00:00
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2014-12-17 05:29:41 +00:00
|
|
|
*err_info = g_strdup("k12text: MTP2 packets not yet supported");
|
|
|
|
return FALSE;
|
2011-03-29 14:29:45 +00:00
|
|
|
case WTAP_ENCAP_ATM_PDUS: /* not (yet) supported */
|
|
|
|
/* XXX: I don't know how to fill in the */
|
2014-12-17 05:29:41 +00:00
|
|
|
/* pseudo_header for these types. */
|
2014-12-17 06:22:29 +00:00
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2014-12-17 05:29:41 +00:00
|
|
|
*err_info = g_strdup("k12text: SSCOP packets not yet supported");
|
|
|
|
return FALSE;
|
2009-01-06 21:25:11 +00:00
|
|
|
default:
|
2014-12-17 06:22:29 +00:00
|
|
|
*err = WTAP_ERR_UNSUPPORTED;
|
2014-12-17 05:29:41 +00:00
|
|
|
*err_info = g_strdup("k12text: unknown encapsulation type");
|
|
|
|
return FALSE;
|
2009-01-06 21:25:11 +00:00
|
|
|
}
|
2014-12-17 05:29:41 +00:00
|
|
|
return TRUE;
|
2009-01-06 21:25:11 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
/* Note: k12text_reset is called each time data is to be processed from */
|
|
|
|
/* a file. This ensures that no "state" from a previous read is */
|
|
|
|
/* used (such as the lexer look-ahead buffer, file_handle, file */
|
|
|
|
/* position and so on. This allows a single lexer buffer to be */
|
|
|
|
/* used even when multiple files are open simultaneously (as for */
|
|
|
|
/* a file merge). */
|
2009-01-05 19:45:58 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
static gboolean
|
|
|
|
k12text_run_scanner(k12text_state_t *state, FILE_T fh, int start_state,
|
|
|
|
int *err, gchar **err_info)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2016-03-31 01:44:01 +00:00
|
|
|
yyscan_t scanner = NULL;
|
|
|
|
|
|
|
|
if (yylex_init(&scanner) != 0) {
|
|
|
|
/* errno is set if this fails */
|
|
|
|
*err = errno;
|
|
|
|
*err_info = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
state->fh = fh;
|
2016-09-15 22:20:26 +00:00
|
|
|
state->err = 0;
|
|
|
|
state->err_info = NULL;
|
2016-03-31 01:44:01 +00:00
|
|
|
state->start_state = start_state;
|
|
|
|
|
|
|
|
state->g_encap = WTAP_ENCAP_UNKNOWN;
|
|
|
|
state->ok_frame = FALSE;
|
|
|
|
state->is_k12text = FALSE;
|
|
|
|
state->at_eof = FALSE;
|
|
|
|
state->junk_chars = 0;
|
|
|
|
state->error_str = NULL;
|
|
|
|
state->file_bytes_read=0;
|
|
|
|
state->g_h=0;
|
|
|
|
state->g_m=0;
|
|
|
|
state->g_s=0;
|
|
|
|
state->g_ns=0;
|
|
|
|
state->g_ms=0;
|
|
|
|
state->ii=0;
|
|
|
|
|
|
|
|
/* Associate the state with the scanner */
|
|
|
|
k12text_set_extra(state, scanner);
|
|
|
|
|
|
|
|
yylex(scanner);
|
|
|
|
yylex_destroy(scanner);
|
2016-09-15 22:20:26 +00:00
|
|
|
if (state->err != 0 && state->err != WTAP_ERR_SHORT_READ) {
|
2016-03-31 01:44:01 +00:00
|
|
|
/* I/O error. */
|
2016-09-15 22:20:26 +00:00
|
|
|
*err = state->err;
|
|
|
|
*err_info = state->err_info;
|
2016-03-31 01:44:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2009-01-05 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2019-04-05 01:56:27 +00:00
|
|
|
k12text_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err, char ** err_info, gint64 *data_offset)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_t *k12text = (k12text_t *)wth->priv;
|
2016-03-31 01:44:01 +00:00
|
|
|
k12text_state_t state;
|
2012-05-04 16:56:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We seek to the file position after the end of the previous frame
|
|
|
|
* processed by k12text_read(), since the lexer undoubtedly did some
|
|
|
|
* amount of look-ahead when processing the previous frame.
|
|
|
|
*
|
|
|
|
* We also clear out any lexer state (eg: look-ahead buffer) and
|
|
|
|
* init vars set by lexer.
|
|
|
|
*/
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if ( file_seek(wth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) {
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2009-01-05 19:45:58 +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
|
|
|
state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD);
|
2017-03-27 21:14:59 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (!k12text_run_scanner(&state, wth->fh, NEXT_FRAME, err, err_info)) {
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2016-03-31 01:44:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (state.ok_frame == FALSE) {
|
|
|
|
if (state.at_eof) {
|
2007-05-24 17:02:06 +00:00
|
|
|
*err = 0;
|
2011-02-04 08:10:08 +00:00
|
|
|
*err_info = NULL;
|
2007-05-24 17:02:06 +00:00
|
|
|
} else {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2016-03-31 01:44:01 +00:00
|
|
|
*err_info = state.error_str;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
*data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */
|
|
|
|
k12text->next_frame_offset += state.file_bytes_read; /* file position after end of this frame */
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
if (!k12text_set_headers(rec, &state, err, err_info)) {
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-12-17 05:29:41 +00:00
|
|
|
return FALSE;
|
2017-03-27 21:14:59 +00:00
|
|
|
}
|
2019-04-05 01:56:27 +00:00
|
|
|
ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen);
|
|
|
|
memcpy(ws_buffer_start_ptr(buf), state.bb, rec->rec_header.packet_header.caplen);
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
k12text_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2016-03-31 01:44:01 +00:00
|
|
|
k12text_state_t state;
|
|
|
|
|
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;
|
2007-05-24 17:02:06 +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
|
|
|
state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD);
|
2017-03-27 21:14:59 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (!k12text_run_scanner(&state, wth->random_fh, NEXT_FRAME, err, err_info)) {
|
2018-01-24 02:20:50 +00:00
|
|
|
g_free(state.bb);
|
2016-03-31 01:44:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (state.ok_frame == FALSE) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2016-03-31 01:44:01 +00:00
|
|
|
if (state.at_eof) {
|
2009-01-05 19:45:58 +00:00
|
|
|
/* What happened ? The desired frame was previously read without a problem */
|
|
|
|
*err_info = g_strdup("Unexpected EOF (program error ?)");
|
|
|
|
} else {
|
2016-03-31 01:44:01 +00:00
|
|
|
*err_info = state.error_str;
|
2009-01-05 19:45:58 +00:00
|
|
|
}
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2009-01-05 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
if (!k12text_set_headers(rec, &state, err, err_info)) {
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-12-17 05:29:41 +00:00
|
|
|
return FALSE;
|
2017-03-27 21:14:59 +00:00
|
|
|
}
|
2018-02-09 00:19:12 +00:00
|
|
|
ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen);
|
|
|
|
memcpy(ws_buffer_start_ptr(buf), state.bb, rec->rec_header.packet_header.caplen);
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-05-23 10:50:02 +00:00
|
|
|
return TRUE;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val
|
2017-08-27 20:49:04 +00:00
|
|
|
k12text_open(wtap *wth, int *err, gchar **err_info)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2012-05-04 16:56:18 +00:00
|
|
|
k12text_t *k12text;
|
2016-03-31 01:44:01 +00:00
|
|
|
k12text_state_t state;
|
2007-11-26 18:55:17 +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
|
|
|
state.bb = (guint8*)g_malloc(WTAP_MAX_PACKET_SIZE_STANDARD);
|
2016-03-31 01:44:01 +00:00
|
|
|
if (!k12text_run_scanner(&state, wth->fh, MAGIC, err, err_info)) {
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2016-03-31 01:44:01 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
}
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (!state.is_k12text) {
|
|
|
|
/* *err might have been set to WTAP_ERR_SHORT_READ */
|
|
|
|
*err = 0;
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2016-03-31 01:44:01 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE;
|
|
|
|
}
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if ( file_seek(wth->fh, 0, SEEK_SET, err) == -1) {
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 03:27:43 +00:00
|
|
|
k12text = g_new(k12text_t, 1);
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->priv = (void *)k12text;
|
2012-05-04 16:56:18 +00:00
|
|
|
k12text->next_frame_offset = 0;
|
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 = k12text_file_type_subtype;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
|
|
|
wth->snapshot_length = 0;
|
|
|
|
wth->subtype_read = k12text_read;
|
|
|
|
wth->subtype_seek_read = k12text_seek_read;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_NSEC;
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2017-03-27 21:14:59 +00:00
|
|
|
g_free(state.bb);
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct { int e; const char* s; } encaps[] = {
|
|
|
|
{ WTAP_ENCAP_ETHERNET, "ETHER" },
|
|
|
|
{ WTAP_ENCAP_MTP2, "MTP-L2" },
|
|
|
|
{ WTAP_ENCAP_ATM_PDUS, "SSCOP" },
|
|
|
|
{ WTAP_ENCAP_MTP3, "SSCF" },
|
|
|
|
{ WTAP_ENCAP_CHDLC, "HDLC" },
|
|
|
|
/* ... */
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
static gboolean
|
2018-02-09 00:19:12 +00:00
|
|
|
k12text_dump(wtap_dumper *wdh, const wtap_rec *rec,
|
2014-12-18 00:02:50 +00:00
|
|
|
const guint8 *pd, int *err, gchar **err_info _U_) {
|
2011-03-29 14:29:45 +00:00
|
|
|
#define K12BUF_SIZE 196808
|
|
|
|
char *buf;
|
|
|
|
size_t left = K12BUF_SIZE;
|
2013-05-17 23:53:44 +00:00
|
|
|
size_t wl;
|
2011-03-29 14:29:45 +00:00
|
|
|
char *p;
|
2011-11-18 21:39:18 +00:00
|
|
|
const char* str_enc;
|
2007-05-24 17:02:06 +00:00
|
|
|
guint i;
|
|
|
|
guint ns;
|
|
|
|
guint ms;
|
2011-03-29 14:29:45 +00:00
|
|
|
gboolean ret;
|
2013-01-04 14:56:27 +00:00
|
|
|
struct tm *tmp;
|
2011-03-29 14:29:45 +00:00
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write anything bigger than we're willing to read. */
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) {
|
2014-01-22 00:26:36 +00:00
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-18 21:39:18 +00:00
|
|
|
str_enc = NULL;
|
|
|
|
for(i=0; encaps[i].s; i++) {
|
2018-02-09 00:19:12 +00:00
|
|
|
if (rec->rec_header.packet_header.pkt_encap == encaps[i].e) {
|
2011-11-18 21:39:18 +00:00
|
|
|
str_enc = encaps[i].s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (str_enc == NULL) {
|
|
|
|
/*
|
|
|
|
* That encapsulation type is not supported. Fail.
|
|
|
|
*/
|
2014-12-17 06:40:45 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_ENCAP;
|
2011-11-18 21:39:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-02 15:32:34 +00:00
|
|
|
buf = (char *)g_malloc(K12BUF_SIZE);
|
2011-03-29 14:29:45 +00:00
|
|
|
p = buf;
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
ms = rec->ts.nsecs / 1000000;
|
|
|
|
ns = (rec->ts.nsecs - (1000000*ms))/1000;
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
tmp = gmtime(&rec->ts.secs);
|
2013-01-04 14:56:27 +00:00
|
|
|
if (tmp == NULL)
|
2021-12-17 20:05:19 +00:00
|
|
|
snprintf(p, 90, "+---------+---------------+----------+\r\nXX:XX:XX,");
|
2013-01-04 14:56:27 +00:00
|
|
|
else
|
|
|
|
strftime(p, 90, "+---------+---------------+----------+\r\n%H:%M:%S,", tmp);
|
2010-06-06 22:19:30 +00:00
|
|
|
wl = strlen(p);
|
|
|
|
p += wl;
|
|
|
|
left -= wl;
|
|
|
|
|
2021-12-17 20:05:19 +00:00
|
|
|
wl = snprintf(p, (gulong)left, "%.3d,%.3d %s\r\n|0 |", ms, ns, str_enc);
|
2011-03-29 14:29:45 +00:00
|
|
|
p += wl;
|
2010-06-06 22:19:30 +00:00
|
|
|
left -= wl;
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
for(i = 0; i < rec->rec_header.packet_header.caplen && left > 2; i++) {
|
2021-12-17 20:05:19 +00:00
|
|
|
wl = snprintf(p, (gulong)left, "%.2x|", pd[i]);
|
2010-06-06 22:19:30 +00:00
|
|
|
p += wl;
|
|
|
|
left -= wl;
|
|
|
|
}
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2021-12-17 20:05:19 +00:00
|
|
|
wl = snprintf(p, (gulong)left, "\r\n\r\n");
|
2010-06-06 22:19:30 +00:00
|
|
|
left -= wl;
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
ret = wtap_dump_file_write(wdh, buf, K12BUF_SIZE - left, err);
|
2011-03-29 14:29:45 +00:00
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
return ret;
|
2007-05-24 17:02:06 +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
|
2020-10-14 01:48:46 +00:00
|
|
|
k12text_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
wdh->subtype_write = k12text_dump;
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
return TRUE;
|
2007-05-24 17:02:06 +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
|
2011-03-29 14:29:45 +00:00
|
|
|
k12text_dump_can_write_encap(int encap)
|
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
switch (encap) {
|
2011-03-29 14:29:45 +00:00
|
|
|
case WTAP_ENCAP_PER_PACKET:
|
2007-05-24 17:02:06 +00:00
|
|
|
case WTAP_ENCAP_ETHERNET:
|
|
|
|
case WTAP_ENCAP_MTP3:
|
|
|
|
case WTAP_ENCAP_CHDLC:
|
|
|
|
return 0;
|
2009-01-06 21:25:11 +00:00
|
|
|
case WTAP_ENCAP_MTP2:
|
|
|
|
case WTAP_ENCAP_ATM_PDUS:
|
2007-05-24 17:02:06 +00:00
|
|
|
default:
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2014-05-09 05:18:49 +00:00
|
|
|
}
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().
This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler). (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)
A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.
Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine. In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.
Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.
While we're at it, add modelines to a file that lacked them.
2021-02-14 08:34:10 +00:00
|
|
|
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
static const struct supported_block_type k12text_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 k12text_info = {
|
|
|
|
"K12 text file", "k12text", "txt", NULL,
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
FALSE, BLOCKS_SUPPORTED(k12text_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
|
|
|
k12text_dump_can_write_encap, k12text_dump_open, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void register_k12text(void)
|
|
|
|
{
|
2021-02-24 03:10:35 +00:00
|
|
|
k12text_file_type_subtype = wtap_register_file_type_subtype(&k12text_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("K12TEXT",
|
|
|
|
k12text_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
|
|
|
}
|