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
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't read from the terminal.
|
|
|
|
*/
|
2007-05-24 17:02:06 +00:00
|
|
|
%option never-interactive
|
2007-07-30 20:22:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prefix scanner routines with "K12Text_" rather than "yy", so this scanner
|
|
|
|
* can coexist with other scanners.
|
|
|
|
*/
|
|
|
|
%option prefix="K12Text_"
|
|
|
|
|
|
|
|
%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
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
%{
|
|
|
|
/* k12text.l
|
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2007-11-26 18:55:17 +00:00
|
|
|
|
|
|
|
/*
|
2007-05-24 17:02:06 +00:00
|
|
|
* TODO:
|
|
|
|
* - fix timestamps after midnight
|
|
|
|
* - verify encapsulations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#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"
|
2007-08-04 02:13:52 +00:00
|
|
|
#include "k12text_lex.h"
|
2007-05-24 17:02:06 +00:00
|
|
|
|
2008-09-07 13:43:49 +00:00
|
|
|
#ifndef HAVE_UNISTD_H
|
|
|
|
#define YY_NO_UNISTD_H
|
|
|
|
#endif
|
|
|
|
|
2010-01-18 21:50:50 +00:00
|
|
|
static guint g_h;
|
|
|
|
static guint g_m;
|
|
|
|
static guint g_s;
|
|
|
|
static guint g_ms;
|
|
|
|
static guint g_ns;
|
|
|
|
static gint g_encap;
|
|
|
|
static guint8 bb[WTAP_MAX_PACKET_SIZE];
|
|
|
|
static guint ii;
|
2007-05-24 17:02:06 +00:00
|
|
|
static gboolean is_k12text;
|
|
|
|
static gboolean at_eof;
|
2009-01-05 19:45:58 +00:00
|
|
|
static guint junk_chars;
|
2007-05-24 17:02:06 +00:00
|
|
|
static void finalize_frame(void);
|
2008-05-30 02:34:45 +00:00
|
|
|
static gchar* error_str;
|
2014-09-06 18:51:59 +00:00
|
|
|
static guint64 file_bytes_read;
|
2007-05-24 17:02:06 +00:00
|
|
|
static gboolean ok_frame;
|
|
|
|
static FILE_T yy_fh;
|
|
|
|
|
2008-05-30 02:34:45 +00:00
|
|
|
#define KERROR(text) do { error_str = g_strdup(text); yyterminate(); } while(0)
|
2013-12-14 18:12:32 +00:00
|
|
|
#define SET_HOURS(text) g_h = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_MINUTES(text) g_m = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_SECONDS(text) g_s = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_MS(text) g_ms = (guint) strtoul(text,NULL,10)
|
|
|
|
#define SET_NS(text) g_ns = (guint) strtoul(text,NULL,10)
|
2010-01-18 21:50:50 +00:00
|
|
|
#define ADD_BYTE(text) do {if (ii >= WTAP_MAX_PACKET_SIZE) {KERROR("frame too large");} bb[ii++] = (guint8)strtoul(text,NULL,16); } while(0)
|
2007-05-24 17:02:06 +00:00
|
|
|
#define FINALIZE_FRAME() finalize_frame()
|
2007-11-26 18:55:17 +00:00
|
|
|
/*~ #define ECHO*/
|
2009-01-05 19:45:58 +00:00
|
|
|
#define YY_USER_ACTION file_bytes_read += yyleng;
|
2007-11-26 18:55:17 +00:00
|
|
|
#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); result = (c==EOF) ? YY_NULL : (buf[0] = c, 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;
|
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
|
2009-01-06 21:25:11 +00:00
|
|
|
/* mtp2 MTP-L2 ;; XXX: Not supported until it's determined how to fill in the pseudo_header req'd by packet-mtp2 */
|
|
|
|
/* sscop SSCOP ;; XXX: Not supported until it's determined how to fill in the pseudo_header req'd by packet-atm */
|
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
|
|
|
%%
|
|
|
|
<MAGIC>{start_timestamp} { is_k12text = TRUE; yyterminate(); }
|
|
|
|
|
|
|
|
<MAGIC>. { if (++ junk_chars > MAX_JUNK) { is_k12text = FALSE; yyterminate(); } }
|
|
|
|
|
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);}
|
2010-01-18 21:50:50 +00:00
|
|
|
<ENCAP>{eth} {g_encap = WTAP_ENCAP_ETHERNET; BEGIN(STARTBYTES); }
|
|
|
|
/* <ENCAP>{mtp2} {g_encap = WTAP_ENCAP_MTP2; BEGIN(STARTBYTES); } Not supported as yet */
|
|
|
|
/* <ENCAP>{sscop} {g_encap = WTAP_ENCAP_ATM_PDUS; BEGIN(STARTBYTES); } Not supported as yet */
|
|
|
|
<ENCAP>{sscfnni} {g_encap = WTAP_ENCAP_MTP3; BEGIN(STARTBYTES); }
|
|
|
|
<ENCAP>{hdlc} {g_encap = WTAP_ENCAP_CHDLC; BEGIN(STARTBYTES); }
|
2007-05-24 17:02:06 +00:00
|
|
|
<ENCAP,STARTBYTES>{start_bytes} { BEGIN(BYTE); }
|
|
|
|
<BYTE>{byte} { ADD_BYTE(yytext); }
|
|
|
|
<BYTE>{bytes_junk} ;
|
|
|
|
<BYTE>{end_bytes} { FINALIZE_FRAME(); yyterminate(); }
|
|
|
|
|
|
|
|
. { if (++junk_chars > MAX_JUNK) { KERROR("too much junk"); } }
|
|
|
|
<<EOF>> { at_eof = TRUE; yyterminate(); }
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
static void finalize_frame(void) {
|
|
|
|
ok_frame = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:55:33 +00:00
|
|
|
/* Fill in pkthdr */
|
2009-01-06 21:25:11 +00:00
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
static void
|
2013-05-17 23:53:44 +00:00
|
|
|
k12text_set_headers(struct wtap_pkthdr *phdr)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-05-17 21:55:33 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
|
|
|
|
|
|
|
phdr->ts.secs = 946681200 + (3600*g_h) + (60*g_m) + g_s;
|
|
|
|
phdr->ts.nsecs = 1000000*g_ms + 1000*g_ns;
|
|
|
|
|
|
|
|
phdr->caplen = phdr->len = ii;
|
|
|
|
|
|
|
|
phdr->pkt_encap = g_encap;
|
|
|
|
|
2009-01-06 21:25:11 +00:00
|
|
|
/* The file-encap is WTAP_ENCAP_PER_PACKET */
|
2013-05-17 23:53:44 +00:00
|
|
|
switch(g_encap) {
|
2009-01-06 21:25:11 +00:00
|
|
|
case WTAP_ENCAP_ETHERNET:
|
2013-05-17 21:55:33 +00:00
|
|
|
phdr->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;
|
|
|
|
#if 0
|
2011-03-29 14:29:45 +00:00
|
|
|
case WTAP_ENCAP_MTP2: /* not (yet) supported */
|
|
|
|
case WTAP_ENCAP_ATM_PDUS: /* not (yet) supported */
|
|
|
|
/* XXX: I don't know how to fill in the */
|
|
|
|
/* pseudo_header for these types. So: The Lexer */
|
|
|
|
/* has recognition for these types commented */
|
|
|
|
/* out .... */
|
2009-01-06 21:25:11 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
static void
|
|
|
|
k12text_reset(FILE_T fh)
|
|
|
|
{
|
2009-01-05 19:45:58 +00:00
|
|
|
yy_fh = fh;
|
|
|
|
yyrestart(0);
|
2010-01-18 21:50:50 +00:00
|
|
|
g_encap = WTAP_ENCAP_UNKNOWN;
|
2009-01-06 21:25:11 +00:00
|
|
|
ok_frame = FALSE;
|
|
|
|
is_k12text = FALSE;
|
|
|
|
at_eof = FALSE;
|
|
|
|
junk_chars = 0;
|
|
|
|
error_str = NULL;
|
2009-01-05 19:45:58 +00:00
|
|
|
file_bytes_read=0;
|
2010-01-18 21:50:50 +00:00
|
|
|
g_h=0;
|
|
|
|
g_m=0;
|
|
|
|
g_s=0;
|
|
|
|
g_ns=0;
|
|
|
|
g_ms=0;
|
|
|
|
ii=0;
|
2009-01-05 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_read(wtap *wth, 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;
|
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
|
|
|
}
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
BEGIN(NEXT_FRAME);
|
|
|
|
yylex();
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
if (ok_frame == FALSE) {
|
|
|
|
if (at_eof) {
|
|
|
|
*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;
|
2011-02-04 08:10:08 +00:00
|
|
|
*err_info = error_str;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
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
|
|
|
|
2012-05-04 16:56:18 +00:00
|
|
|
*data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */
|
|
|
|
k12text->next_frame_offset += file_bytes_read; /* file position after end of this frame */
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2013-05-17 23:53:44 +00:00
|
|
|
k12text_set_headers(&wth->phdr);
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
|
|
|
|
memcpy(ws_buffer_start_ptr(wth->frame_buffer), bb, wth->phdr.caplen);
|
2007-05-24 17:02:06 +00:00
|
|
|
|
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
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, char **err_info)
|
2011-03-29 14:29:45 +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;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_reset(wth->random_fh); /* init lexer buffer and vars set by lexer */
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
BEGIN(NEXT_FRAME);
|
|
|
|
yylex();
|
|
|
|
|
|
|
|
if (ok_frame == FALSE) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
2009-01-05 19:45:58 +00:00
|
|
|
if (at_eof) {
|
|
|
|
/* What happened ? The desired frame was previously read without a problem */
|
|
|
|
*err_info = g_strdup("Unexpected EOF (program error ?)");
|
|
|
|
} else {
|
|
|
|
*err_info = error_str;
|
|
|
|
}
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2009-01-05 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-17 23:53:44 +00:00
|
|
|
k12text_set_headers(phdr);
|
2009-01-06 21:25:11 +00:00
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_assure_space(buf, phdr->caplen);
|
|
|
|
memcpy(ws_buffer_start_ptr(buf), bb, phdr->caplen);
|
2007-05-24 17:02:06 +00:00
|
|
|
|
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
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_open(wtap *wth, int *err, gchar **err_info _U_)
|
2011-03-29 14:29:45 +00:00
|
|
|
{
|
2012-05-04 16:56:18 +00:00
|
|
|
k12text_t *k12text;
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
|
2007-11-26 18:55:17 +00:00
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
BEGIN(MAGIC);
|
|
|
|
yylex();
|
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
if (! is_k12text) 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) {
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 16:56:18 +00:00
|
|
|
k12text = (k12text_t *)g_malloc(sizeof(k12text_t));
|
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;
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_K12TEXT;
|
|
|
|
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
|
|
|
|
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
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr,
|
2011-09-01 09:43:10 +00:00
|
|
|
const guint8 *pd, int *err) {
|
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. */
|
|
|
|
if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
|
|
|
|
*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++) {
|
|
|
|
if (phdr->pkt_encap == encaps[i].e) {
|
|
|
|
str_enc = encaps[i].s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (str_enc == NULL) {
|
|
|
|
/*
|
|
|
|
* That encapsulation type is not supported. Fail.
|
|
|
|
*/
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
|
|
|
|
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
|
|
|
|
2007-05-24 17:02:06 +00:00
|
|
|
ms = phdr->ts.nsecs / 1000000;
|
|
|
|
ns = (phdr->ts.nsecs - (1000000*ms))/1000;
|
|
|
|
|
2013-01-04 14:56:27 +00:00
|
|
|
tmp = gmtime(&phdr->ts.secs);
|
|
|
|
if (tmp == NULL)
|
|
|
|
g_snprintf(p, 90, "+---------+---------------+----------+\r\nXX:XX:XX,");
|
|
|
|
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;
|
|
|
|
|
2014-10-10 01:09:06 +00:00
|
|
|
wl = g_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;
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
for(i = 0; i < phdr->caplen && left > 2; i++) {
|
2014-10-10 01:09:06 +00:00
|
|
|
wl = g_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
|
|
|
|
2014-10-10 01:09:06 +00:00
|
|
|
wl = g_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
k12text_dump_open(wtap_dumper *wdh, int *err _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
|
|
|
}
|
|
|
|
|
2011-03-29 14:29:45 +00:00
|
|
|
int
|
|
|
|
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:
|
|
|
|
return WTAP_ERR_UNSUPPORTED_ENCAP;
|
2014-05-09 05:18:49 +00:00
|
|
|
}
|
2007-05-24 17:02:06 +00:00
|
|
|
}
|
2008-04-25 17:40:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to stop processing when we get to the end of the input.
|
2011-03-29 14:29:45 +00:00
|
|
|
* (%option noyywrap is not used because if used then
|
2008-04-25 17:40:29 +00:00
|
|
|
* some flex versions (eg: 2.5.35) generate code which causes
|
|
|
|
* warnings by the Windows VC compiler).
|
|
|
|
*/
|
|
|
|
|
|
|
|
int yywrap(void) {
|
|
|
|
return 1;
|
|
|
|
}
|