From 0d300bb6f50a3c28adac30b1c09734975f2492cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Mayer?= Date: Mon, 15 Jun 2009 18:56:46 +0000 Subject: Rename all of the ascend files: That way we hopefully won't need the runlex.sh hack any more. Also the ylwrap stuff is (hopefully) obsolete. ascend.[hc] -> ascendtext.[hc] ascend-scanner.l -> ascend_scanner.l ascend-grammar.y -> ascend.y svn path=/trunk/; revision=28744 --- wiretap/CMakeLists.txt | 18 +- wiretap/Makefile.am | 6 +- wiretap/Makefile.common | 18 +- wiretap/Makefile.nmake | 16 +- wiretap/ascend-grammar.y | 515 ---------------------------------------------- wiretap/ascend-scanner.l | 359 -------------------------------- wiretap/ascend.c | 343 ------------------------------ wiretap/ascend.h | 33 --- wiretap/ascend.y | 515 ++++++++++++++++++++++++++++++++++++++++++++++ wiretap/ascend_scanner.l | 359 ++++++++++++++++++++++++++++++++ wiretap/ascendtext.c | 343 ++++++++++++++++++++++++++++++ wiretap/ascendtext.h | 33 +++ wiretap/file_access.c | 2 +- wiretap/libwiretap.vcproj | 8 +- 14 files changed, 1286 insertions(+), 1282 deletions(-) delete mode 100644 wiretap/ascend-grammar.y delete mode 100644 wiretap/ascend-scanner.l delete mode 100644 wiretap/ascend.c delete mode 100644 wiretap/ascend.h create mode 100644 wiretap/ascend.y create mode 100644 wiretap/ascend_scanner.l create mode 100644 wiretap/ascendtext.c create mode 100644 wiretap/ascendtext.h diff --git a/wiretap/CMakeLists.txt b/wiretap/CMakeLists.txt index 038a860d90..80b334ad45 100644 --- a/wiretap/CMakeLists.txt +++ b/wiretap/CMakeLists.txt @@ -25,7 +25,7 @@ set(WIRETAP_FILES 5views.c airopeek9.c - ascend.c + ascendtext.c atm.c ber.c btsnoop.c @@ -51,6 +51,7 @@ set(WIRETAP_FILES libpcap.c mpeg.c netmon.c + netscaler.c netscreen.c nettl.c network_instruments.c @@ -62,23 +63,26 @@ set(WIRETAP_FILES pppdump.c radcom.c snoop.c + tnef.c toshiba.c visual.c vms.c wtap.c ) -ADD_LEX_FILES(WIRETAP_FILES - ascend-scanner.l +add_lex_files(WIRETAP_FILES + ascend_scanner.l k12text.l ) -ADD_YACC_FILES(WIRETAP_FILES - ascend-grammar.y +add_yacc_files(WIRETAP_FILES + ascend.y ) -ADD_LIBRARY(wiretap SHARED +# add_dependency(ascend.c ascend_scanner_lex.h) + +add_library(wiretap SHARED ${WIRETAP_FILES} ) -INSTALL(TARGETS wiretap LIBRARY DESTINATION lib) +install(TARGETS wiretap LIBRARY DESTINATION lib) diff --git a/wiretap/Makefile.am b/wiretap/Makefile.am index 17ed580b1d..c431e6cc11 100644 --- a/wiretap/Makefile.am +++ b/wiretap/Makefile.am @@ -72,16 +72,16 @@ libwiretap_la_LIBADD = libwiretap_generated.la $(GLIB_LIBS) ${top_builddir}/wsut RUNLEX = $(top_srcdir)/tools/runlex.sh -ascend-scanner_lex.h : ascend-scanner.c +ascend_scanner_lex.h : ascend_scanner.c k12text_lex.h : k12text.c -ascend-grammar.c ascend-grammar.h: ascend-grammar.y +ascend.c ascend.h: ascend.y @if [ -z "$(YACC)" ]; then \ echo "Neither bison nor byacc has been found"; \ exit 1; \ fi - $(YACC) -d -p ascend -o ascend-grammar.c $(srcdir)/ascend-grammar.y + $(YACC) -d -p ascend -o ascend.c $(srcdir)/ascend.y checkapi: $(PERL) ../tools/checkAPIs.pl -g abort -g termoutput $(NONGENERATED_C_FILES) $(GENERATOR_FILES) diff --git a/wiretap/Makefile.common b/wiretap/Makefile.common index 966314fedd..d6e3f40120 100644 --- a/wiretap/Makefile.common +++ b/wiretap/Makefile.common @@ -31,7 +31,7 @@ NONGENERATED_C_FILES = \ 5views.c \ airopeek9.c \ - ascend.c \ + ascendtext.c \ atm.c \ ber.c \ btsnoop.c \ @@ -57,8 +57,8 @@ NONGENERATED_C_FILES = \ libpcap.c \ mpeg.c \ netmon.c \ - netscreen.c \ netscaler.c \ + netscreen.c \ nettl.c \ network_instruments.c \ netxray.c \ @@ -79,7 +79,7 @@ NONGENERATED_C_FILES = \ NONGENERATED_HEADER_FILES = \ 5views.h \ airopeek9.h \ - ascend.h \ + ascendtext.h \ ascend-int.h \ atm.h \ ber.h \ @@ -127,20 +127,20 @@ NONGENERATED_HEADER_FILES = \ # Files that generate compileable files GENERATOR_FILES = \ - ascend-grammar.y \ - ascend-scanner.l \ + ascend.y \ + ascend_scanner.l \ k12text.l # The C source files they generate. GENERATED_C_FILES = \ - ascend-grammar.c \ - ascend-scanner.c \ + ascend.c \ + ascend_scanner.c \ k12text.c # The header files that they generate. GENERATED_HEADER_FILES = \ - ascend-grammar.h \ - ascend-scanner_lex.h \ + ascend.h \ + ascend_scanner_lex.h \ k12text_lex.h # All the generated files. diff --git a/wiretap/Makefile.nmake b/wiretap/Makefile.nmake index 9d111a09f1..456d7a9ed5 100644 --- a/wiretap/Makefile.nmake +++ b/wiretap/Makefile.nmake @@ -41,16 +41,16 @@ wiretap-$(WTAP_VERSION).dll : $(OBJECTS) wtap.def ..\image\wiretap.res RUNLEX = ..\tools\runlex.sh -ascend-scanner_lex.h : ascend-scanner.c -ascend-scanner.obj : ascend-scanner.c ascend-grammar.h - $(CC) $(CVARSDLL) $(GENERATED_CFLAGS) -Fd.\ -c ascend-scanner.c +ascend_scanner_lex.h : ascend_scanner.c +ascend_scanner.obj : ascend_scanner.c ascend.h + $(CC) $(CVARSDLL) $(GENERATED_CFLAGS) -Fd.\ -c ascend_scanner.c k12text_lex.h : k12text.c k12text.obj : k12text.c $(CC) $(CVARSDLL) $(GENERATED_CFLAGS) -Fd.\ -c $? -ascend-grammar.c ascend-grammar.h : ascend-grammar.y - $(YACC) $(YACC_OPTS) -d -p ascend ascend-grammar.y -o ascend-grammar.c +ascend.c ascend.h : ascend.y + $(YACC) $(YACC_OPTS) -d -p ascend ascend.y -o ascend.c clean : rm -f $(OBJECTS) \ @@ -62,11 +62,11 @@ clean : # # We remove the generated files with "distclean" because one of them, -# "ascend-scanner.c", needs different #includes for UN*X and Windows +# "ascend_scanner.c", needs different #includes for UN*X and Windows # (UN*X versions of Flex make it include , but that's a # UN*X-only header), so if you're going to build from source, you need -# to build "ascend-scanner.c" from "ascend-scanner.l" with Flex. -# This might not be necessary for "ascend-grammar.{c,h}", but as +# to build "ascend_scanner.c" from "ascend_scanner.l" with Flex. +# This might not be necessary for "ascend.{c,h}", but as # long as you need Flex, you might as well get Bison.... # distclean: clean diff --git a/wiretap/ascend-grammar.y b/wiretap/ascend-grammar.y deleted file mode 100644 index c842e24553..0000000000 --- a/wiretap/ascend-grammar.y +++ /dev/null @@ -1,515 +0,0 @@ -%{ -/* ascend-grammar.y - * - * $Id$ - * - * Wiretap Library - * Copyright (c) 1998 by Gilbert Ramirez - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -/* - Example 'pridisp' output data - one paragraph/frame: - -PRI-XMIT-27: (task "l1Task" at 0x10216fe0, time: 560194.01) 4 octets @ 0x1027c5b0 - [0000]: 00 01 01 a9 .... -PRI-RCV-27: (task "idle task" at 0x10123570, time: 560194.01) 4 octets @ 0x1027fb00 - [0000]: 00 01 01 dd - - Example 'pridisp' output data - two paragraphs/frame for XMIT case only: - -PRI-XMIT-19/1: (task "l1Task" at 0x10216840, time: 274759.98) 4 octets @ 0x1027f230 - [0000]: 00 01 30 d8 ..0. -PRI-XMIT-19/2 (task "l1Task" at 0x10216840, time: 274759.98) 11 octets @ 0x1027f234 - [0000]: 08 02 8c bf 02 18 04 e9 82 83 8f ........ ... - - Example 'ether-disp' output data: - -ETHER3ND RECV: (task "_sarTask" at 0x802c6eb0, time: 259848.03) 775 octets @ 0xa8fb2020 - [0000]: 00 d0 52 04 e7 1e 08 00 20 ae 51 b5 08 00 45 00 ..R..... .Q...E. - [0010]: 02 f9 05 e6 40 00 3f 11 6e 39 87 fe c4 95 3c 3c ....@.?. n9....<< - [0020]: 3c 05 13 c4 13 c4 02 e5 ef ed 49 4e 56 49 54 45 <....... ..INVITE - [0030]: 20 73 69 70 3a 35 32 30 37 33 40 36 30 2e 36 30 sip:520 73@60.60 - [0040]: 2e 36 30 2e 35 20 53 49 50 2f 32 2e 30 0d 0a 56 .60.5 SI P/2.0..V - [0050]: 69 61 3a 20 53 49 50 2f 32 2e 30 2f 55 44 50 20 ia: SIP/ 2.0/UDP - [0060]: 31 33 35 2e 135. - - Example 'wandsess' output data: - -RECV-iguana:241:(task: B02614C0, time: 1975432.85) 49 octets @ 8003BD94 - [0000]: FF 03 00 3D C0 06 CA 22 2F 45 00 00 28 6A 3B 40 - [0010]: 00 3F 03 D7 37 CE 41 62 12 CF 00 FB 08 20 27 00 - [0020]: 50 E4 08 DD D7 7C 4C 71 92 50 10 7D 78 67 C8 00 - [0030]: 00 -XMIT-iguana:241:(task: B04E12C0, time: 1975432.85) 53 octets @ 8009EB16 - [0000]: FF 03 00 3D C0 09 1E 31 21 45 00 00 2C 2D BD 40 - [0010]: 00 7A 06 D8 B1 CF 00 FB 08 CE 41 62 12 00 50 20 - [0020]: 29 7C 4C 71 9C 9A 6A 93 A4 60 12 22 38 3F 10 00 - [0030]: 00 02 04 05 B4 - - Example 'wdd' output data: - -Date: 01/12/1990. Time: 12:22:33 -Cause an attempt to place call to 14082750382 -WD_DIALOUT_DISP: chunk 2515EE type IP. -(task: 251790, time: 994953.28) 44 octets @ 2782B8 - [0000]: 00 C0 7B 71 45 6C 00 60 08 16 AA 51 08 00 45 00 - [0010]: 00 2C 66 1C 40 00 80 06 53 F6 AC 14 00 18 CC 47 - [0020]: C8 45 0A 31 00 50 3B D9 5B 75 00 00 - - The following output comes from a MAX with Software 7.2.3: - -RECV-187:(task: B050B480, time: 18042248.03) 100 octets @ 800012C0 - [0000]: FF 03 00 21 45 00 00 60 E3 49 00 00 7F 11 FD 7B - [0010]: C0 A8 F7 05 8A C8 18 51 00 89 00 89 00 4C C7 C1 - [0020]: CC 8E 40 00 00 01 00 00 00 00 00 01 20 45 4A 45 - [0030]: 42 45 43 45 48 43 4E 46 43 46 41 43 41 43 41 43 - [0040]: 41 43 41 43 41 43 41 43 41 43 41 42 4E 00 00 20 - [0050]: 00 01 C0 0C 00 20 00 01 00 04 93 E0 00 06 60 00 - [0060]: C0 A8 F7 05 -XMIT-187:(task: B0292CA0, time: 18042248.04) 60 octets @ 800AD576 - [0000]: FF 03 00 21 45 00 00 38 D7 EE 00 00 0F 01 11 2B - [0010]: 0A FF FF FE C0 A8 F7 05 03 0D 33 D3 00 00 00 00 - [0020]: 45 00 00 60 E3 49 00 00 7E 11 FE 7B C0 A8 F7 05 - [0030]: 8A C8 18 51 00 89 00 89 00 4C C7 C1 -RECV-187:(task: B0292CA0, time: 18042251.92) 16 octets @ 800018E8 - [0000]: FF 03 C0 21 09 01 00 0C DE 61 96 4B 00 30 94 92 - - In TAOS 8.0, Lucent slightly changed the format as follows: - - Example 'wandisp' output data (TAOS 8.0.3): (same format is used - for 'wanopen' and 'wannext' command) - -RECV-14: (task "idle task" at 0xb05e6e00, time: 1279.01) 29 octets @ 0x8000e0fc - [0000]: ff 03 c0 21 01 01 00 19 01 04 05 f4 11 04 05 f4 ...!.... ........ - [0010]: 13 09 03 00 c0 7b 9a 9f 2d 17 04 10 00 .....{.. -.... -XMIT-14: (task "idle task" at 0xb05e6e00, time: 1279.02) 38 octets @ 0x8007fd56 - [0000]: ff 03 c0 21 01 01 00 22 00 04 00 00 01 04 05 f4 ...!..." ........ - [0010]: 03 05 c2 23 05 11 04 05 f4 13 09 03 00 c0 7b 80 ...#.... ......{. - [0020]: 7c ef 17 04 0e 00 |..... -XMIT-14: (task "idle task" at 0xb05e6e00, time: 1279.02) 29 octets @ 0x8007fa36 - [0000]: ff 03 c0 21 02 01 00 19 01 04 05 f4 11 04 05 f4 ...!.... ........ - [0010]: 13 09 03 00 c0 7b 9a 9f 2d 17 04 10 00 .....{.. -.... - - Example 'wandsess' output data (TAOS 8.0.3): - -RECV-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.50) 20 octets @ 0x8000d198 - [0000]: ff 03 00 3d c0 00 00 04 80 fd 02 01 00 0a 11 06 ...=.... ........ - [0010]: 00 01 01 03 .... -XMIT-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.51) 26 octets @ 0x800806b6 - [0000]: ff 03 00 3d c0 00 00 00 80 21 01 01 00 10 02 06 ...=.... .!...... - [0010]: 00 2d 0f 01 03 06 89 64 03 08 .-.....d .. -XMIT-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.51) 20 octets @ 0x8007f716 - [0000]: ff 03 00 3d c0 00 00 01 80 fd 01 01 00 0a 11 06 ...=.... ........ - [0010]: 00 01 01 03 .... - - The changes since TAOS 7.X are: - - 1) White space is added before "(task". - 2) Task has a name, indicated by a subsequent string surrounded by a - double-quote. - 3) Address expressed in hex number has a preceeding "0x". - 4) Hex numbers are in lower case. - 5) There is a character display corresponding to hex data in each line. - - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "wtap-int.h" -#include "buffer.h" -#include "ascend.h" -#include "ascend-int.h" -#include "file_wrappers.h" - -#define NO_USER "" - -int yyparse(void); -void yyerror(const char *); - -const gchar *ascend_parse_error; - -static unsigned int bcur; -static guint32 start_time, secs, usecs, caplen, wirelen; -static ascend_pkthdr *header; -struct ascend_phdr *pseudo_header; -static guint8 *pkt_data; -static gint64 first_hexbyte; -static FILE_T *fh_ptr; - -%} - -%union { -gchar *s; -guint32 d; -guint8 b; -} - -%token STRING KEYWORD WDD_DATE WDD_CHUNK COUNTER SLASH_SUFFIX -%token WDS_PREFIX ISDN_PREFIX ETHER_PREFIX DECNUM HEXNUM -%token HEXBYTE - -%type string dataln datagroup -%type wds_prefix isdn_prefix ether_prefix decnum hexnum -%type byte bytegroup - -%% - -data_packet: - | ether_hdr datagroup - | deferred_isdn_hdr datagroup deferred_isdn_hdr datagroup - | isdn_hdr datagroup - | wds_hdr datagroup - | wds8_hdr datagroup - | wdp7_hdr datagroup - | wdp8_hdr datagroup - | wdd_date wdd_hdr datagroup - | wdd_hdr datagroup -; - -isdn_prefix: ISDN_PREFIX; - -ether_prefix: ETHER_PREFIX; - -wds_prefix: WDS_PREFIX; - -string: STRING; - -decnum: DECNUM; - -hexnum: HEXNUM; - -/* - pridisp special case - I-frame header printed separately from contents, - one frame across two messages. - -PRI-XMIT-0/1: (task "l1Task" at 0x80152b20, time: 283529.65) 4 octets @ -0x80128220 - [0000]: 00 01 ae b2 .... -PRI-XMIT-0/2 (task "l1Task" at 0x80152b20, time: 283529.65) 10 octets @ -0x80128224 - [0000]: 08 02 d7 e3 02 18 03 a9 83 8a ........ - -*/ -deferred_isdn_hdr: isdn_prefix decnum SLASH_SUFFIX KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen += $11; - caplen += $11; - secs = $9; - usecs = $10; - if (pseudo_header != NULL) { - pseudo_header->type = $1; - pseudo_header->sess = $2; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $7; - } - /* because we have two data groups */ - first_hexbyte = 0; -} -; - -/* -PRI-XMIT-19: (task "l1Task" at 0x10216840, time: 274758.67) 4 octets @ 0x1027c1c0 - ... or ... -PRI-RCV-27: (task "idle task" at 0x10123570, time: 560194.01) 4 octets @ 0x1027fb00 -*/ -isdn_hdr: isdn_prefix decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $10; - caplen = $10; - secs = $8; - usecs = $9; - if (pseudo_header != NULL) { - pseudo_header->type = $1; - pseudo_header->sess = $2; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $6; - } - first_hexbyte = 0; -} -; - -/* -ETHER3ND XMIT: (task "_sarTask" at 0x802c6eb0, time: 259848.11) 414 octets @ 0xa -885f80e -*/ -ether_hdr: ether_prefix string KEYWORD string KEYWORD hexnum KEYWORD decnum decnum - decnum KEYWORD HEXNUM { - wirelen = $10; - caplen = $10; - secs = $8; - usecs = $9; - if (pseudo_header != NULL) { - pseudo_header->type = $1; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $6; - } -} -; - -/* RECV-iguana:241:(task: B02614C0, time: 1975432.85) 49 octets @ 8003BD94 */ -/* 1 2 3 4 5 6 7 8 9 10 11 */ -wds_hdr: wds_prefix string decnum KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $9; - caplen = $9; - secs = $7; - usecs = $8; - if (pseudo_header != NULL) { - /* pseudo_header->user is set in ascend-scanner.l */ - pseudo_header->type = $1; - pseudo_header->sess = $3; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $5; - } -} -; - -/* RECV-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.50) 20 octets @ 0x8000d198 */ -/* 1 2 3 4 5 6 7 8 9 10 11 12 13 */ -wds8_hdr: wds_prefix string decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $11; - caplen = $11; - secs = $9; - usecs = $10; - if (pseudo_header != NULL) { - /* pseudo_header->user is set in ascend-scanner.l */ - pseudo_header->type = $1; - pseudo_header->sess = $3; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $7; - } -} -; - -/* RECV-187:(task: B050B480, time: 18042248.03) 100 octets @ 800012C0 */ -/* 1 2 3 4 5 6 7 8 9 10 */ -wdp7_hdr: wds_prefix decnum KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $8; - caplen = $8; - secs = $6; - usecs = $7; - if (pseudo_header != NULL) { - /* pseudo_header->user is set in ascend-scanner.l */ - pseudo_header->type = $1; - pseudo_header->sess = $2; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $4; - } -} -; - -/* XMIT-44: (task "freedm_task" at 0xe051fd10, time: 6258.66) 29 octets @ 0x606d1f00 */ -/* 1 2 3 4 5 6 7 8 9 10 11 12 */ -wdp8_hdr: wds_prefix decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $10; - caplen = $10; - secs = $8; - usecs = $9; - if (pseudo_header != NULL) { - /* pseudo_header->user is set in ascend-scanner.l */ - pseudo_header->type = $1; - pseudo_header->sess = $2; - pseudo_header->call_num[0] = '\0'; - pseudo_header->chunk = 0; - pseudo_header->task = $6; - } -} -; - -/* -Date: 01/12/1990. Time: 12:22:33 -Cause an attempt to place call to 14082750382 -*/ -/* 1 2 3 4 5 6 7 8 9 10*/ -wdd_date: WDD_DATE decnum decnum decnum KEYWORD decnum decnum decnum KEYWORD string { - /* - * Supply the date/time value to the code above us; it will use the - * first date/time value supplied as the capture start date/time. - */ - struct tm wddt; - - wddt.tm_sec = $8; - wddt.tm_min = $7; - wddt.tm_hour = $6; - wddt.tm_mday = $3; - wddt.tm_mon = $2 - 1; - wddt.tm_year = ($4 > 1970) ? $4 - 1900 : 70; - wddt.tm_isdst = -1; - - start_time = (guint32) mktime(&wddt); -} -; - -/* -WD_DIALOUT_DISP: chunk 2515EE type IP. -(task: 251790, time: 994953.28) 44 octets @ 2782B8 -*/ -/* 1 2 3 4 5 6 7 8 9 10 11*/ -wdd_hdr: WDD_CHUNK hexnum KEYWORD KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { - wirelen = $9; - caplen = $9; - secs = $7; - usecs = $8; - if (pseudo_header != NULL) { - /* pseudo_header->call_num is set in ascend-scanner.l */ - pseudo_header->type = ASCEND_PFX_WDD; - pseudo_header->user[0] = '\0'; - pseudo_header->sess = 0; - pseudo_header->chunk = $2; - pseudo_header->task = $5; - } -} -; - -byte: HEXBYTE { - /* remember the position of the data group in the trace, to tip - off ascend_seek() as to where to look for the next header. */ - if (first_hexbyte == 0) - first_hexbyte = file_tell(*fh_ptr); - - if (bcur < caplen) { - pkt_data[bcur] = $1; - bcur++; - } - - /* arbitrary safety maximum... */ - if (bcur >= ASCEND_MAX_PKT_LEN) - YYACCEPT; -} -; - -/* XXX There must be a better way to do this... */ -bytegroup: byte - | byte byte - | byte byte byte - | byte byte byte byte - | byte byte byte byte byte - | byte byte byte byte byte byte - | byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte - | byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte -; - -dataln: COUNTER bytegroup; - -datagroup: dataln - | dataln dataln - | dataln dataln dataln - | dataln dataln dataln dataln - | dataln dataln dataln dataln dataln - | dataln dataln dataln dataln dataln dataln - | dataln dataln dataln dataln dataln dataln dataln - | dataln dataln dataln dataln dataln dataln dataln dataln -; - -%% - -void -init_parse_ascend() -{ - at_eof = 0; - start_time = 0; /* we haven't see a date/time yet */ -} - -/* Parse the capture file. Return the offset of the next packet, or zero - if there is none. */ -int -parse_ascend(FILE_T fh, guint8 *pd, struct ascend_phdr *phdr, - ascend_pkthdr *hdr, gint64 *start_of_data) -{ - /* yydebug = 1; */ - int retval; - ascend_init_lexer(fh); - pkt_data = pd; - pseudo_header = phdr; - header = hdr; - fh_ptr = &fh; - - bcur = 0; - first_hexbyte = 0; - wirelen = 0; - caplen = 0; - - /* - * Not all packets in a "wdd" dump necessarily have a "Cause an - * attempt to place call to" header (I presume this can happen if - * there was a call in progress when the packet was sent or - * received), so we won't necessarily have the phone number for - * the packet. - * - * XXX - we could assume, in the sequential pass, that it's the - * phone number from the last call, and remember that for use - * when doing random access. - */ - pseudo_header->call_num[0] = '\0'; - - retval = yyparse(); - - caplen = bcur; - - /* did we see any data (hex bytes)? if so, tip off ascend_seek() - as to where to look for the next packet, if any. If we didn't, - maybe this record was broken. Advance so we don't get into - an infinite loop reading a broken trace. */ - if (first_hexbyte) - *start_of_data = first_hexbyte; - - /* if we got at least some data, return success even if the parser - reported an error. This is because the debug header gives the number - of bytes on the wire, not actually how many bytes are in the trace. - We won't know where the data ends until we run into the next packet. */ - if (caplen) { - if (header) { - header->start_time = start_time; - header->secs = secs; - header->usecs = usecs; - header->caplen = caplen; - header->len = wirelen; - } - - return 1; - } - - /* Didn't see any data. Still, perhaps the parser was happy. */ - if (retval) - return 0; - else - return 1; -} - -void -yyerror (const char *s) -{ - ascend_parse_error = s; -} diff --git a/wiretap/ascend-scanner.l b/wiretap/ascend-scanner.l deleted file mode 100644 index 59908aea6b..0000000000 --- a/wiretap/ascend-scanner.l +++ /dev/null @@ -1,359 +0,0 @@ -/* - * We don't read from the terminal. - */ -%option never-interactive - -/* - * Prefix scanner routines with "ascend" rather than "yy", so this scanner - * can coexist with other scanners. - */ -%option prefix="ascend" - -%{ -/* ascend-scanner.l - * - * $Id$ - * - * Wiretap Library - * Copyright (c) 1998 by Gilbert Ramirez - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifdef HAVE_IO_H -#include /* for isatty() on win32 */ -#endif - -#include "wtap-int.h" -#include "ascend.h" -#include "ascend-grammar.h" -#include "ascend-int.h" -#include "file_wrappers.h" -#include "ascend-scanner_lex.h" - -FILE_T yy_fh; -extern char *ascend_ra_ptr; -extern char *ascend_ra_last; -#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); \ -result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); } - -int at_eof; -int mul, scratch; - -#define NO_USER "" - -#ifndef HAVE_UNISTD_H -#define YY_NO_UNISTD_H -#endif - - -%} - -D [0-9] -H [A-Fa-f0-9] - -PPP_XPFX PPP-OUT -PPP_RPFX PPP-IN -ISDN_XPFX PRI-XMIT- -ISDN_RPFX PRI-RCV- -WAN_XPFX XMIT[\-:]* -WAN_RPFX RECV[\-:]* -ETHER_PFX ETHER - -WDD_DATE "Date:" -WDD_TIME "Time:" -WDD_CAUSE "Cause an attempt to place call to " -WDD_CALLNUM [^\n\r\t ]+ -WDD_CHUNK "WD_DIALOUT_DISP: chunk" -WDD_TYPE "type "[^\n\r\t ]+ - -%s sc_gen_task -%s sc_gen_time_s -%s sc_gen_time_u -%s sc_gen_octets -%s sc_gen_counter -%s sc_gen_byte - -%s sc_wds_user -%s sc_wds_sess - -%s sc_wdd_date_d -%s sc_wdd_date_m -%s sc_wdd_date_y -%s sc_wdd_time -%s sc_wdd_time_h -%s sc_wdd_time_m -%s sc_wdd_time_s -%s sc_wdd_cause -%s sc_wdd_callnum -%s sc_wdd_chunk -%s sc_wdd_chunknum -%s sc_wdd_type - -%s sc_chardisp - -%s sc_isdn_call -%s sc_ether_direction - -%% - -{ETHER_PFX} { - BEGIN(sc_ether_direction); - ascendlval.d = ASCEND_PFX_ETHER; - return ETHER_PREFIX; -} - -{ISDN_XPFX} { - BEGIN(sc_isdn_call); - ascendlval.d = ASCEND_PFX_ISDN_X; - return ISDN_PREFIX; -} - -{ISDN_RPFX} { - BEGIN(sc_isdn_call); - ascendlval.d = ASCEND_PFX_ISDN_R; - return ISDN_PREFIX; -} - -{WAN_XPFX} { - BEGIN(sc_wds_user); - ascendlval.d = ASCEND_PFX_WDS_X; - return WDS_PREFIX; -} - -{WAN_RPFX} { - BEGIN(sc_wds_user); - ascendlval.d = ASCEND_PFX_WDS_R; - return WDS_PREFIX; -} - -{PPP_XPFX} { - BEGIN(sc_wds_user); - ascendlval.d = ASCEND_PFX_WDS_X; - return WDS_PREFIX; -} - -{PPP_RPFX} { - BEGIN(sc_wds_user); - ascendlval.d = ASCEND_PFX_WDS_R; - return WDS_PREFIX; -} - -[^\(]+ { - BEGIN(sc_gen_task); - return STRING; -} - -[^\/\(:]+ { - BEGIN(sc_gen_task); - return DECNUM; -} - -[^:]+ { - char *atcopy = g_strdup(ascendtext); - char colon = input(); - char after = input(); - int retval = STRING; - - unput(after); unput(colon); - - if (after != '(' && after != ' ') { - BEGIN(sc_wds_sess); - if (pseudo_header != NULL) { - g_strlcpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN); - } - } else { /* We have a version 7 file */ - BEGIN(sc_gen_task); - if (pseudo_header != NULL) { - g_strlcpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN); - } - ascendlval.d = strtol(ascendtext, NULL, 10); - retval = DECNUM; - } - g_free (atcopy); - return retval; -} - -{D}* { - BEGIN(sc_gen_task); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -(0x|0X)?{H}+ { - BEGIN(sc_gen_time_s); - ascendlval.d = strtoul(ascendtext, NULL, 16); - return HEXNUM; -} - -\"[A-Za-z0-9_ ]+\" { - return STRING; -} - -{D}+ { - BEGIN(sc_gen_time_u); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{D}+ { - char *atcopy = g_strdup(ascendtext); - BEGIN(sc_gen_octets); - /* only want the most significant 2 digits. convert to usecs */ - if (strlen(atcopy) > 2) - atcopy[2] = '\0'; - ascendlval.d = strtol(atcopy, NULL, 10) * 10000; - g_free(atcopy); - return DECNUM; -} - -{D}+ { - BEGIN(sc_gen_counter); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -"["{H}{4}"]:" { - BEGIN(sc_gen_byte); - return COUNTER; -} - -{H}{2} { - ascendlval.b = (guint8)strtol(ascendtext, NULL, 16); - return HEXBYTE; -} - -" "{4} { - BEGIN(sc_chardisp); -} - -.* { - BEGIN(sc_gen_byte); -} - -{WDD_DATE} { - BEGIN(sc_wdd_date_d); - return WDD_DATE; -} - -{D}{2} { - BEGIN(sc_wdd_date_m); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{D}{2} { - BEGIN(sc_wdd_date_y); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{D}{4} { - BEGIN(sc_wdd_time); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{WDD_TIME} { - BEGIN(sc_wdd_time_h); - return KEYWORD; -} - -{D}{2} { - BEGIN(sc_wdd_time_m); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{D}{2} { - BEGIN(sc_wdd_time_s); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{D}{2} { - BEGIN(sc_wdd_cause); - ascendlval.d = strtol(ascendtext, NULL, 10); - return DECNUM; -} - -{WDD_CAUSE} { - BEGIN(sc_wdd_callnum); - return KEYWORD; -} - -{WDD_CALLNUM} { - BEGIN(sc_wdd_chunk); - if (pseudo_header != NULL) { - g_strlcpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN); - } - return STRING; -} - -{WDD_CHUNK} { - BEGIN(sc_wdd_chunknum); - return WDD_CHUNK; -} - -{H}+ { - BEGIN(sc_wdd_type); - ascendlval.d = strtoul(ascendtext, NULL, 16); - return HEXNUM; -} - -{WDD_TYPE} { - BEGIN(sc_gen_task); - return KEYWORD; -} - -\/{D}+ { - return SLASH_SUFFIX; -} - -(0x|0X)?{H}+ { return HEXNUM; } - -task:|task|at|time:|octets { return KEYWORD; } - -<> { at_eof++; yyterminate(); } - -(.|\n) ; - -%% - -void ascend_init_lexer(FILE_T fh) -{ - yyrestart(0); - yy_fh = fh; - BEGIN(INITIAL); -} - -/* - * We want to stop processing when we get to the end of the input. - * (%option noyywrap is not used because if used then - * some flex versions (eg: 2.5.35) generate code which causes - * warnings by the Windows VC compiler). - */ - -int yywrap(void) { - return 1; -} diff --git a/wiretap/ascend.c b/wiretap/ascend.c deleted file mode 100644 index 17241b3968..0000000000 --- a/wiretap/ascend.c +++ /dev/null @@ -1,343 +0,0 @@ -/* ascend.c - * - * $Id$ - * - * Wiretap Library - * Copyright (c) 1998 by Gilbert Ramirez - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include "wtap-int.h" -#include "buffer.h" -#include "ascend.h" -#include "ascend-int.h" -#include "file_wrappers.h" -#include - -#include - -#ifdef HAVE_UNISTD_H -#include -#endif - -#include -#include - -/* Last updated: Feb 03 2005: Josh Bailey (joshbailey@lucent.com). - - This module reads the text hex dump output of various TAOS - (Lucent/Ascend Max, Max TNT, APX, etc) debug commands, including: - - * pridisplay traces primary rate ISDN - * ether-display traces Ethernet packets (dangerous! CPU intensive) - * wanopening, wandisplay, wannext, wandsess - traces PPP or other WAN connections - - Please see ascend-grammar.y for examples. - - Detailed documentation on TAOS products is at http://support.lucent.com. - - Support for other commands will be added on an ongoing basis. */ - -typedef struct _ascend_magic_string { - guint type; - const gchar *strptr; -} ascend_magic_string; - -#define ASCEND_MAGIC_STRINGS 11 -#define ASCEND_DATE "Date:" - -/* these magic strings signify the headers of a supported debug commands */ -static const ascend_magic_string ascend_magic[] = { - { ASCEND_PFX_ISDN_X, "PRI-XMIT-" }, - { ASCEND_PFX_ISDN_R, "PRI-RCV-" }, - { ASCEND_PFX_WDS_X, "XMIT-" }, - { ASCEND_PFX_WDS_R, "RECV-" }, - { ASCEND_PFX_WDS_X, "XMIT:" }, - { ASCEND_PFX_WDS_R, "RECV:" }, - { ASCEND_PFX_WDS_X, "PPP-OUT" }, - { ASCEND_PFX_WDS_R, "PPP-IN" }, - { ASCEND_PFX_WDD, ASCEND_DATE }, - { ASCEND_PFX_WDD, "WD_DIALOUT_DISP:" }, - { ASCEND_PFX_ETHER, "ETHER" }, -}; - -static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset); -static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, - union wtap_pseudo_header *pseudo_head, guint8 *pd, int len, - int *err, gchar **err_info); -static void ascend_close(wtap *wth); - -/* Seeks to the beginning of the next packet, and returns the - byte offset at which the header for that packet begins. - Returns -1 on failure. */ -static gint64 ascend_seek(wtap *wth, int *err) -{ - int byte; - gint64 date_off = -1, cur_off, packet_off; - size_t string_level[ASCEND_MAGIC_STRINGS]; - guint string_i = 0, type = 0; - guint excessive_read_count = 262144; - - memset(&string_level, 0, sizeof(string_level)); - - while (((byte = file_getc(wth->fh)) != EOF)) { - excessive_read_count--; - - if (!excessive_read_count) { - return -1; - } - - for (string_i = 0; string_i < ASCEND_MAGIC_STRINGS; string_i++) { - const gchar *strptr = ascend_magic[string_i].strptr; - size_t len = strlen(strptr); - - if (byte == *(strptr + string_level[string_i])) { - string_level[string_i]++; - if (string_level[string_i] >= len) { - cur_off = file_tell(wth->fh); - if (cur_off == -1) { - /* Error. */ - *err = file_error(wth->fh); - return -1; - } - - /* Date: header is a special case. Remember the offset, - but keep looking for other headers. */ - if (strcmp(strptr, ASCEND_DATE) == 0) { - date_off = cur_off - len; - } else { - if (date_off == -1) { - /* Back up over the header we just read; that's where a read - of this packet should start. */ - packet_off = cur_off - len; - } else { - /* This packet has a date/time header; a read of it should - start at the beginning of *that* header. */ - packet_off = date_off; - } - - type = ascend_magic[string_i].type; - goto found; - } - } - } else { - string_level[string_i] = 0; - } - } - } - - if (byte != EOF || file_eof(wth->fh)) { - /* Either we didn't find the offset, or we got an EOF. */ - *err = 0; - } else { - /* We (presumably) got an error (there's no equivalent to "ferror()" - in zlib, alas, so we don't have a wrapper to check for an error). */ - *err = file_error(wth->fh); - } - return -1; - -found: - /* - * Move to where the read for this packet should start, and return - * that seek offset. - */ - if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1) - return -1; - - wth->pseudo_header.ascend.type = type; - - return packet_off; -} - -int ascend_open(wtap *wth, int *err, gchar **err_info _U_) -{ - gint64 offset; - struct stat statbuf; - guint8 buf[ASCEND_MAX_PKT_LEN]; - ascend_pkthdr header; - gint64 dummy_seek_start; - - /* We haven't yet allocated a data structure for our private stuff; - set the pointer to null, so that "ascend_seek()" knows not to - fill it in. */ - wth->capture.ascend = NULL; - - offset = ascend_seek(wth, err); - if (offset == -1) { - if (*err == 0) - return 0; - else - return -1; - } - - /* Do a trial parse of the first packet just found to see if we might really have an Ascend file */ - init_parse_ascend(); - if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, &dummy_seek_start)) { - return 0; - } - - wth->data_offset = offset; - wth->file_type = WTAP_FILE_ASCEND; - - switch(wth->pseudo_header.ascend.type) { - case ASCEND_PFX_ISDN_X: - case ASCEND_PFX_ISDN_R: - wth->file_encap = WTAP_ENCAP_ISDN; - break; - - case ASCEND_PFX_ETHER: - wth->file_encap = WTAP_ENCAP_ETHERNET; - break; - - default: - wth->file_encap = WTAP_ENCAP_ASCEND; - } - - wth->snapshot_length = ASCEND_MAX_PKT_LEN; - wth->subtype_read = ascend_read; - wth->subtype_seek_read = ascend_seek_read; - wth->subtype_close = ascend_close; - wth->capture.ascend = g_malloc(sizeof(ascend_t)); - - /* The first packet we want to read is the one that "ascend_seek()" - just found; start searching for it at the offset at which it - found it. */ - wth->capture.ascend->next_packet_seek_start = offset; - - /* MAXen and Pipelines report the time since reboot. In order to keep - from reporting packet times near the epoch, we subtract the first - packet's timestamp from the capture file's ctime, which gives us an - offset that we can apply to each packet. - */ - if (fstat(wth->fd, &statbuf) == -1) { - *err = errno; - g_free(wth->capture.ascend); - return -1; - } - wth->capture.ascend->inittime = statbuf.st_ctime; - wth->capture.ascend->adjusted = 0; - wth->tsprecision = WTAP_FILE_TSPREC_USEC; - - init_parse_ascend(); - - return 1; -} - -static void config_pseudo_header(union wtap_pseudo_header *pseudo_head) -{ - switch(pseudo_head->ascend.type) { - case ASCEND_PFX_ISDN_X: - pseudo_head->isdn.uton = TRUE; - pseudo_head->isdn.channel = 0; - break; - - case ASCEND_PFX_ISDN_R: - pseudo_head->isdn.uton = FALSE; - pseudo_head->isdn.channel = 0; - break; - - case ASCEND_PFX_ETHER: - pseudo_head->eth.fcs_len = 0; - break; - } -} - -/* Read the next packet; called from wtap_read(). */ -static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, - gint64 *data_offset) -{ - gint64 offset; - guint8 *buf = buffer_start_ptr(wth->frame_buffer); - ascend_pkthdr header; - - /* parse_ascend() will advance the point at which to look for the next - packet's header, to just after the last packet's header (ie. at the - start of the last packet's data). We have to get past the last - packet's header because we might mistake part of it for a new header. */ - if (file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start, - SEEK_SET, err) == -1) - return FALSE; - - offset = ascend_seek(wth, err); - if (offset == -1) - return FALSE; - if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, &(wth->capture.ascend->next_packet_seek_start))) { - *err = WTAP_ERR_BAD_RECORD; - *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); - return FALSE; - } - - buffer_assure_space(wth->frame_buffer, wth->snapshot_length); - - config_pseudo_header(&wth->pseudo_header); - - if (! wth->capture.ascend->adjusted) { - wth->capture.ascend->adjusted = 1; - if (header.start_time != 0) { - /* - * Capture file contained a date and time. - * We do this only if this is the very first packet we've seen - - * i.e., if "wth->capture.ascend->adjusted" is false - because - * if we get a date and time after the first packet, we can't - * go back and adjust the time stamps of the packets we've already - * processed, and basing the time stamps of this and following - * packets on the time stamp from the file text rather than the - * ctime of the capture file means times before this and after - * this can't be compared. - */ - wth->capture.ascend->inittime = header.start_time; - } - if (wth->capture.ascend->inittime > header.secs) - wth->capture.ascend->inittime -= header.secs; - } - wth->phdr.ts.secs = header.secs + wth->capture.ascend->inittime; - wth->phdr.ts.nsecs = header.usecs * 1000; - wth->phdr.caplen = header.caplen; - wth->phdr.len = header.len; - wth->data_offset = offset; - - *data_offset = offset; - return TRUE; -} - -static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, - union wtap_pseudo_header *pseudo_head, guint8 *pd, int len, - int *err, gchar **err_info) -{ - /* don't care for length. */ - (void) len; - - if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) - return FALSE; - if (! parse_ascend(wth->random_fh, pd, &pseudo_head->ascend, NULL, &(wth->capture.ascend->next_packet_seek_start))) { - *err = WTAP_ERR_BAD_RECORD; - *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); - return FALSE; - } - - config_pseudo_header(pseudo_head); - return TRUE; -} - -static void ascend_close(wtap *wth) -{ - g_free(wth->capture.ascend); -} diff --git a/wiretap/ascend.h b/wiretap/ascend.h deleted file mode 100644 index 9e493ab36c..0000000000 --- a/wiretap/ascend.h +++ /dev/null @@ -1,33 +0,0 @@ -/* ascend.h - * - * $Id$ - * - * Wiretap Library - * Copyright (c) 1998 by Gilbert Ramirez - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __ASCEND_H__ -#define __ASCEND_H__ - -#define ASCEND_MAX_DATA_ROWS 8 -#define ASCEND_MAX_DATA_COLS 16 -#define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS) - -int ascend_open(wtap *wth, int *err, gchar **err_info); - -#endif diff --git a/wiretap/ascend.y b/wiretap/ascend.y new file mode 100644 index 0000000000..e1ad3dc1df --- /dev/null +++ b/wiretap/ascend.y @@ -0,0 +1,515 @@ +%{ +/* ascend.y + * + * $Id$ + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* + Example 'pridisp' output data - one paragraph/frame: + +PRI-XMIT-27: (task "l1Task" at 0x10216fe0, time: 560194.01) 4 octets @ 0x1027c5b0 + [0000]: 00 01 01 a9 .... +PRI-RCV-27: (task "idle task" at 0x10123570, time: 560194.01) 4 octets @ 0x1027fb00 + [0000]: 00 01 01 dd + + Example 'pridisp' output data - two paragraphs/frame for XMIT case only: + +PRI-XMIT-19/1: (task "l1Task" at 0x10216840, time: 274759.98) 4 octets @ 0x1027f230 + [0000]: 00 01 30 d8 ..0. +PRI-XMIT-19/2 (task "l1Task" at 0x10216840, time: 274759.98) 11 octets @ 0x1027f234 + [0000]: 08 02 8c bf 02 18 04 e9 82 83 8f ........ ... + + Example 'ether-disp' output data: + +ETHER3ND RECV: (task "_sarTask" at 0x802c6eb0, time: 259848.03) 775 octets @ 0xa8fb2020 + [0000]: 00 d0 52 04 e7 1e 08 00 20 ae 51 b5 08 00 45 00 ..R..... .Q...E. + [0010]: 02 f9 05 e6 40 00 3f 11 6e 39 87 fe c4 95 3c 3c ....@.?. n9....<< + [0020]: 3c 05 13 c4 13 c4 02 e5 ef ed 49 4e 56 49 54 45 <....... ..INVITE + [0030]: 20 73 69 70 3a 35 32 30 37 33 40 36 30 2e 36 30 sip:520 73@60.60 + [0040]: 2e 36 30 2e 35 20 53 49 50 2f 32 2e 30 0d 0a 56 .60.5 SI P/2.0..V + [0050]: 69 61 3a 20 53 49 50 2f 32 2e 30 2f 55 44 50 20 ia: SIP/ 2.0/UDP + [0060]: 31 33 35 2e 135. + + Example 'wandsess' output data: + +RECV-iguana:241:(task: B02614C0, time: 1975432.85) 49 octets @ 8003BD94 + [0000]: FF 03 00 3D C0 06 CA 22 2F 45 00 00 28 6A 3B 40 + [0010]: 00 3F 03 D7 37 CE 41 62 12 CF 00 FB 08 20 27 00 + [0020]: 50 E4 08 DD D7 7C 4C 71 92 50 10 7D 78 67 C8 00 + [0030]: 00 +XMIT-iguana:241:(task: B04E12C0, time: 1975432.85) 53 octets @ 8009EB16 + [0000]: FF 03 00 3D C0 09 1E 31 21 45 00 00 2C 2D BD 40 + [0010]: 00 7A 06 D8 B1 CF 00 FB 08 CE 41 62 12 00 50 20 + [0020]: 29 7C 4C 71 9C 9A 6A 93 A4 60 12 22 38 3F 10 00 + [0030]: 00 02 04 05 B4 + + Example 'wdd' output data: + +Date: 01/12/1990. Time: 12:22:33 +Cause an attempt to place call to 14082750382 +WD_DIALOUT_DISP: chunk 2515EE type IP. +(task: 251790, time: 994953.28) 44 octets @ 2782B8 + [0000]: 00 C0 7B 71 45 6C 00 60 08 16 AA 51 08 00 45 00 + [0010]: 00 2C 66 1C 40 00 80 06 53 F6 AC 14 00 18 CC 47 + [0020]: C8 45 0A 31 00 50 3B D9 5B 75 00 00 + + The following output comes from a MAX with Software 7.2.3: + +RECV-187:(task: B050B480, time: 18042248.03) 100 octets @ 800012C0 + [0000]: FF 03 00 21 45 00 00 60 E3 49 00 00 7F 11 FD 7B + [0010]: C0 A8 F7 05 8A C8 18 51 00 89 00 89 00 4C C7 C1 + [0020]: CC 8E 40 00 00 01 00 00 00 00 00 01 20 45 4A 45 + [0030]: 42 45 43 45 48 43 4E 46 43 46 41 43 41 43 41 43 + [0040]: 41 43 41 43 41 43 41 43 41 43 41 42 4E 00 00 20 + [0050]: 00 01 C0 0C 00 20 00 01 00 04 93 E0 00 06 60 00 + [0060]: C0 A8 F7 05 +XMIT-187:(task: B0292CA0, time: 18042248.04) 60 octets @ 800AD576 + [0000]: FF 03 00 21 45 00 00 38 D7 EE 00 00 0F 01 11 2B + [0010]: 0A FF FF FE C0 A8 F7 05 03 0D 33 D3 00 00 00 00 + [0020]: 45 00 00 60 E3 49 00 00 7E 11 FE 7B C0 A8 F7 05 + [0030]: 8A C8 18 51 00 89 00 89 00 4C C7 C1 +RECV-187:(task: B0292CA0, time: 18042251.92) 16 octets @ 800018E8 + [0000]: FF 03 C0 21 09 01 00 0C DE 61 96 4B 00 30 94 92 + + In TAOS 8.0, Lucent slightly changed the format as follows: + + Example 'wandisp' output data (TAOS 8.0.3): (same format is used + for 'wanopen' and 'wannext' command) + +RECV-14: (task "idle task" at 0xb05e6e00, time: 1279.01) 29 octets @ 0x8000e0fc + [0000]: ff 03 c0 21 01 01 00 19 01 04 05 f4 11 04 05 f4 ...!.... ........ + [0010]: 13 09 03 00 c0 7b 9a 9f 2d 17 04 10 00 .....{.. -.... +XMIT-14: (task "idle task" at 0xb05e6e00, time: 1279.02) 38 octets @ 0x8007fd56 + [0000]: ff 03 c0 21 01 01 00 22 00 04 00 00 01 04 05 f4 ...!..." ........ + [0010]: 03 05 c2 23 05 11 04 05 f4 13 09 03 00 c0 7b 80 ...#.... ......{. + [0020]: 7c ef 17 04 0e 00 |..... +XMIT-14: (task "idle task" at 0xb05e6e00, time: 1279.02) 29 octets @ 0x8007fa36 + [0000]: ff 03 c0 21 02 01 00 19 01 04 05 f4 11 04 05 f4 ...!.... ........ + [0010]: 13 09 03 00 c0 7b 9a 9f 2d 17 04 10 00 .....{.. -.... + + Example 'wandsess' output data (TAOS 8.0.3): + +RECV-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.50) 20 octets @ 0x8000d198 + [0000]: ff 03 00 3d c0 00 00 04 80 fd 02 01 00 0a 11 06 ...=.... ........ + [0010]: 00 01 01 03 .... +XMIT-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.51) 26 octets @ 0x800806b6 + [0000]: ff 03 00 3d c0 00 00 00 80 21 01 01 00 10 02 06 ...=.... .!...... + [0010]: 00 2d 0f 01 03 06 89 64 03 08 .-.....d .. +XMIT-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.51) 20 octets @ 0x8007f716 + [0000]: ff 03 00 3d c0 00 00 01 80 fd 01 01 00 0a 11 06 ...=.... ........ + [0010]: 00 01 01 03 .... + + The changes since TAOS 7.X are: + + 1) White space is added before "(task". + 2) Task has a name, indicated by a subsequent string surrounded by a + double-quote. + 3) Address expressed in hex number has a preceeding "0x". + 4) Hex numbers are in lower case. + 5) There is a character display corresponding to hex data in each line. + + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "wtap-int.h" +#include "buffer.h" +#include "ascendtext.h" +#include "ascend-int.h" +#include "file_wrappers.h" + +#define NO_USER "" + +int yyparse(void); +void yyerror(const char *); + +const gchar *ascend_parse_error; + +static unsigned int bcur; +static guint32 start_time, secs, usecs, caplen, wirelen; +static ascend_pkthdr *header; +struct ascend_phdr *pseudo_header; +static guint8 *pkt_data; +static gint64 first_hexbyte; +static FILE_T *fh_ptr; + +%} + +%union { +gchar *s; +guint32 d; +guint8 b; +} + +%token STRING KEYWORD WDD_DATE WDD_CHUNK COUNTER SLASH_SUFFIX +%token WDS_PREFIX ISDN_PREFIX ETHER_PREFIX DECNUM HEXNUM +%token HEXBYTE + +%type string dataln datagroup +%type wds_prefix isdn_prefix ether_prefix decnum hexnum +%type byte bytegroup + +%% + +data_packet: + | ether_hdr datagroup + | deferred_isdn_hdr datagroup deferred_isdn_hdr datagroup + | isdn_hdr datagroup + | wds_hdr datagroup + | wds8_hdr datagroup + | wdp7_hdr datagroup + | wdp8_hdr datagroup + | wdd_date wdd_hdr datagroup + | wdd_hdr datagroup +; + +isdn_prefix: ISDN_PREFIX; + +ether_prefix: ETHER_PREFIX; + +wds_prefix: WDS_PREFIX; + +string: STRING; + +decnum: DECNUM; + +hexnum: HEXNUM; + +/* + pridisp special case - I-frame header printed separately from contents, + one frame across two messages. + +PRI-XMIT-0/1: (task "l1Task" at 0x80152b20, time: 283529.65) 4 octets @ +0x80128220 + [0000]: 00 01 ae b2 .... +PRI-XMIT-0/2 (task "l1Task" at 0x80152b20, time: 283529.65) 10 octets @ +0x80128224 + [0000]: 08 02 d7 e3 02 18 03 a9 83 8a ........ + +*/ +deferred_isdn_hdr: isdn_prefix decnum SLASH_SUFFIX KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen += $11; + caplen += $11; + secs = $9; + usecs = $10; + if (pseudo_header != NULL) { + pseudo_header->type = $1; + pseudo_header->sess = $2; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $7; + } + /* because we have two data groups */ + first_hexbyte = 0; +} +; + +/* +PRI-XMIT-19: (task "l1Task" at 0x10216840, time: 274758.67) 4 octets @ 0x1027c1c0 + ... or ... +PRI-RCV-27: (task "idle task" at 0x10123570, time: 560194.01) 4 octets @ 0x1027fb00 +*/ +isdn_hdr: isdn_prefix decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $10; + caplen = $10; + secs = $8; + usecs = $9; + if (pseudo_header != NULL) { + pseudo_header->type = $1; + pseudo_header->sess = $2; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $6; + } + first_hexbyte = 0; +} +; + +/* +ETHER3ND XMIT: (task "_sarTask" at 0x802c6eb0, time: 259848.11) 414 octets @ 0xa +885f80e +*/ +ether_hdr: ether_prefix string KEYWORD string KEYWORD hexnum KEYWORD decnum decnum + decnum KEYWORD HEXNUM { + wirelen = $10; + caplen = $10; + secs = $8; + usecs = $9; + if (pseudo_header != NULL) { + pseudo_header->type = $1; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $6; + } +} +; + +/* RECV-iguana:241:(task: B02614C0, time: 1975432.85) 49 octets @ 8003BD94 */ +/* 1 2 3 4 5 6 7 8 9 10 11 */ +wds_hdr: wds_prefix string decnum KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $9; + caplen = $9; + secs = $7; + usecs = $8; + if (pseudo_header != NULL) { + /* pseudo_header->user is set in ascend_scanner.l */ + pseudo_header->type = $1; + pseudo_header->sess = $3; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $5; + } +} +; + +/* RECV-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.50) 20 octets @ 0x8000d198 */ +/* 1 2 3 4 5 6 7 8 9 10 11 12 13 */ +wds8_hdr: wds_prefix string decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $11; + caplen = $11; + secs = $9; + usecs = $10; + if (pseudo_header != NULL) { + /* pseudo_header->user is set in ascend_scanner.l */ + pseudo_header->type = $1; + pseudo_header->sess = $3; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $7; + } +} +; + +/* RECV-187:(task: B050B480, time: 18042248.03) 100 octets @ 800012C0 */ +/* 1 2 3 4 5 6 7 8 9 10 */ +wdp7_hdr: wds_prefix decnum KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $8; + caplen = $8; + secs = $6; + usecs = $7; + if (pseudo_header != NULL) { + /* pseudo_header->user is set in ascend_scanner.l */ + pseudo_header->type = $1; + pseudo_header->sess = $2; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $4; + } +} +; + +/* XMIT-44: (task "freedm_task" at 0xe051fd10, time: 6258.66) 29 octets @ 0x606d1f00 */ +/* 1 2 3 4 5 6 7 8 9 10 11 12 */ +wdp8_hdr: wds_prefix decnum KEYWORD string KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $10; + caplen = $10; + secs = $8; + usecs = $9; + if (pseudo_header != NULL) { + /* pseudo_header->user is set in ascend_scanner.l */ + pseudo_header->type = $1; + pseudo_header->sess = $2; + pseudo_header->call_num[0] = '\0'; + pseudo_header->chunk = 0; + pseudo_header->task = $6; + } +} +; + +/* +Date: 01/12/1990. Time: 12:22:33 +Cause an attempt to place call to 14082750382 +*/ +/* 1 2 3 4 5 6 7 8 9 10*/ +wdd_date: WDD_DATE decnum decnum decnum KEYWORD decnum decnum decnum KEYWORD string { + /* + * Supply the date/time value to the code above us; it will use the + * first date/time value supplied as the capture start date/time. + */ + struct tm wddt; + + wddt.tm_sec = $8; + wddt.tm_min = $7; + wddt.tm_hour = $6; + wddt.tm_mday = $3; + wddt.tm_mon = $2 - 1; + wddt.tm_year = ($4 > 1970) ? $4 - 1900 : 70; + wddt.tm_isdst = -1; + + start_time = (guint32) mktime(&wddt); +} +; + +/* +WD_DIALOUT_DISP: chunk 2515EE type IP. +(task: 251790, time: 994953.28) 44 octets @ 2782B8 +*/ +/* 1 2 3 4 5 6 7 8 9 10 11*/ +wdd_hdr: WDD_CHUNK hexnum KEYWORD KEYWORD hexnum KEYWORD decnum decnum decnum KEYWORD HEXNUM { + wirelen = $9; + caplen = $9; + secs = $7; + usecs = $8; + if (pseudo_header != NULL) { + /* pseudo_header->call_num is set in ascend_scanner.l */ + pseudo_header->type = ASCEND_PFX_WDD; + pseudo_header->user[0] = '\0'; + pseudo_header->sess = 0; + pseudo_header->chunk = $2; + pseudo_header->task = $5; + } +} +; + +byte: HEXBYTE { + /* remember the position of the data group in the trace, to tip + off ascend_seek() as to where to look for the next header. */ + if (first_hexbyte == 0) + first_hexbyte = file_tell(*fh_ptr); + + if (bcur < caplen) { + pkt_data[bcur] = $1; + bcur++; + } + + /* arbitrary safety maximum... */ + if (bcur >= ASCEND_MAX_PKT_LEN) + YYACCEPT; +} +; + +/* XXX There must be a better way to do this... */ +bytegroup: byte + | byte byte + | byte byte byte + | byte byte byte byte + | byte byte byte byte byte + | byte byte byte byte byte byte + | byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte + | byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte +; + +dataln: COUNTER bytegroup; + +datagroup: dataln + | dataln dataln + | dataln dataln dataln + | dataln dataln dataln dataln + | dataln dataln dataln dataln dataln + | dataln dataln dataln dataln dataln dataln + | dataln dataln dataln dataln dataln dataln dataln + | dataln dataln dataln dataln dataln dataln dataln dataln +; + +%% + +void +init_parse_ascend() +{ + at_eof = 0; + start_time = 0; /* we haven't see a date/time yet */ +} + +/* Parse the capture file. Return the offset of the next packet, or zero + if there is none. */ +int +parse_ascend(FILE_T fh, guint8 *pd, struct ascend_phdr *phdr, + ascend_pkthdr *hdr, gint64 *start_of_data) +{ + /* yydebug = 1; */ + int retval; + ascend_init_lexer(fh); + pkt_data = pd; + pseudo_header = phdr; + header = hdr; + fh_ptr = &fh; + + bcur = 0; + first_hexbyte = 0; + wirelen = 0; + caplen = 0; + + /* + * Not all packets in a "wdd" dump necessarily have a "Cause an + * attempt to place call to" header (I presume this can happen if + * there was a call in progress when the packet was sent or + * received), so we won't necessarily have the phone number for + * the packet. + * + * XXX - we could assume, in the sequential pass, that it's the + * phone number from the last call, and remember that for use + * when doing random access. + */ + pseudo_header->call_num[0] = '\0'; + + retval = yyparse(); + + caplen = bcur; + + /* did we see any data (hex bytes)? if so, tip off ascend_seek() + as to where to look for the next packet, if any. If we didn't, + maybe this record was broken. Advance so we don't get into + an infinite loop reading a broken trace. */ + if (first_hexbyte) + *start_of_data = first_hexbyte; + + /* if we got at least some data, return success even if the parser + reported an error. This is because the debug header gives the number + of bytes on the wire, not actually how many bytes are in the trace. + We won't know where the data ends until we run into the next packet. */ + if (caplen) { + if (header) { + header->start_time = start_time; + header->secs = secs; + header->usecs = usecs; + header->caplen = caplen; + header->len = wirelen; + } + + return 1; + } + + /* Didn't see any data. Still, perhaps the parser was happy. */ + if (retval) + return 0; + else + return 1; +} + +void +yyerror (const char *s) +{ + ascend_parse_error = s; +} diff --git a/wiretap/ascend_scanner.l b/wiretap/ascend_scanner.l new file mode 100644 index 0000000000..e669db287e --- /dev/null +++ b/wiretap/ascend_scanner.l @@ -0,0 +1,359 @@ +/* + * We don't read from the terminal. + */ +%option never-interactive + +/* + * Prefix scanner routines with "ascend" rather than "yy", so this scanner + * can coexist with other scanners. + */ +%option prefix="ascend" + +%{ +/* ascend_scanner.l + * + * $Id$ + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_IO_H +#include /* for isatty() on win32 */ +#endif + +#include "wtap-int.h" +#include "ascendtext.h" +#include "ascend.h" +#include "ascend-int.h" +#include "file_wrappers.h" +#include "ascend_scanner_lex.h" + +FILE_T yy_fh; +extern char *ascend_ra_ptr; +extern char *ascend_ra_last; +#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); \ +result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); } + +int at_eof; +int mul, scratch; + +#define NO_USER "" + +#ifndef HAVE_UNISTD_H +#define YY_NO_UNISTD_H +#endif + + +%} + +D [0-9] +H [A-Fa-f0-9] + +PPP_XPFX PPP-OUT +PPP_RPFX PPP-IN +ISDN_XPFX PRI-XMIT- +ISDN_RPFX PRI-RCV- +WAN_XPFX XMIT[\-:]* +WAN_RPFX RECV[\-:]* +ETHER_PFX ETHER + +WDD_DATE "Date:" +WDD_TIME "Time:" +WDD_CAUSE "Cause an attempt to place call to " +WDD_CALLNUM [^\n\r\t ]+ +WDD_CHUNK "WD_DIALOUT_DISP: chunk" +WDD_TYPE "type "[^\n\r\t ]+ + +%s sc_gen_task +%s sc_gen_time_s +%s sc_gen_time_u +%s sc_gen_octets +%s sc_gen_counter +%s sc_gen_byte + +%s sc_wds_user +%s sc_wds_sess + +%s sc_wdd_date_d +%s sc_wdd_date_m +%s sc_wdd_date_y +%s sc_wdd_time +%s sc_wdd_time_h +%s sc_wdd_time_m +%s sc_wdd_time_s +%s sc_wdd_cause +%s sc_wdd_callnum +%s sc_wdd_chunk +%s sc_wdd_chunknum +%s sc_wdd_type + +%s sc_chardisp + +%s sc_isdn_call +%s sc_ether_direction + +%% + +{ETHER_PFX} { + BEGIN(sc_ether_direction); + ascendlval.d = ASCEND_PFX_ETHER; + return ETHER_PREFIX; +} + +{ISDN_XPFX} { + BEGIN(sc_isdn_call); + ascendlval.d = ASCEND_PFX_ISDN_X; + return ISDN_PREFIX; +} + +{ISDN_RPFX} { + BEGIN(sc_isdn_call); + ascendlval.d = ASCEND_PFX_ISDN_R; + return ISDN_PREFIX; +} + +{WAN_XPFX} { + BEGIN(sc_wds_user); + ascendlval.d = ASCEND_PFX_WDS_X; + return WDS_PREFIX; +} + +{WAN_RPFX} { + BEGIN(sc_wds_user); + ascendlval.d = ASCEND_PFX_WDS_R; + return WDS_PREFIX; +} + +{PPP_XPFX} { + BEGIN(sc_wds_user); + ascendlval.d = ASCEND_PFX_WDS_X; + return WDS_PREFIX; +} + +{PPP_RPFX} { + BEGIN(sc_wds_user); + ascendlval.d = ASCEND_PFX_WDS_R; + return WDS_PREFIX; +} + +[^\(]+ { + BEGIN(sc_gen_task); + return STRING; +} + +[^\/\(:]+ { + BEGIN(sc_gen_task); + return DECNUM; +} + +[^:]+ { + char *atcopy = g_strdup(ascendtext); + char colon = input(); + char after = input(); + int retval = STRING; + + unput(after); unput(colon); + + if (after != '(' && after != ' ') { + BEGIN(sc_wds_sess); + if (pseudo_header != NULL) { + g_strlcpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN); + } + } else { /* We have a version 7 file */ + BEGIN(sc_gen_task); + if (pseudo_header != NULL) { + g_strlcpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN); + } + ascendlval.d = strtol(ascendtext, NULL, 10); + retval = DECNUM; + } + g_free (atcopy); + return retval; +} + +{D}* { + BEGIN(sc_gen_task); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +(0x|0X)?{H}+ { + BEGIN(sc_gen_time_s); + ascendlval.d = strtoul(ascendtext, NULL, 16); + return HEXNUM; +} + +\"[A-Za-z0-9_ ]+\" { + return STRING; +} + +{D}+ { + BEGIN(sc_gen_time_u); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{D}+ { + char *atcopy = g_strdup(ascendtext); + BEGIN(sc_gen_octets); + /* only want the most significant 2 digits. convert to usecs */ + if (strlen(atcopy) > 2) + atcopy[2] = '\0'; + ascendlval.d = strtol(atcopy, NULL, 10) * 10000; + g_free(atcopy); + return DECNUM; +} + +{D}+ { + BEGIN(sc_gen_counter); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +"["{H}{4}"]:" { + BEGIN(sc_gen_byte); + return COUNTER; +} + +{H}{2} { + ascendlval.b = (guint8)strtol(ascendtext, NULL, 16); + return HEXBYTE; +} + +" "{4} { + BEGIN(sc_chardisp); +} + +.* { + BEGIN(sc_gen_byte); +} + +{WDD_DATE} { + BEGIN(sc_wdd_date_d); + return WDD_DATE; +} + +{D}{2} { + BEGIN(sc_wdd_date_m); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{D}{2} { + BEGIN(sc_wdd_date_y); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{D}{4} { + BEGIN(sc_wdd_time); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{WDD_TIME} { + BEGIN(sc_wdd_time_h); + return KEYWORD; +} + +{D}{2} { + BEGIN(sc_wdd_time_m); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{D}{2} { + BEGIN(sc_wdd_time_s); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{D}{2} { + BEGIN(sc_wdd_cause); + ascendlval.d = strtol(ascendtext, NULL, 10); + return DECNUM; +} + +{WDD_CAUSE} { + BEGIN(sc_wdd_callnum); + return KEYWORD; +} + +{WDD_CALLNUM} { + BEGIN(sc_wdd_chunk); + if (pseudo_header != NULL) { + g_strlcpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN); + } + return STRING; +} + +{WDD_CHUNK} { + BEGIN(sc_wdd_chunknum); + return WDD_CHUNK; +} + +{H}+ { + BEGIN(sc_wdd_type); + ascendlval.d = strtoul(ascendtext, NULL, 16); + return HEXNUM; +} + +{WDD_TYPE} { + BEGIN(sc_gen_task); + return KEYWORD; +} + +\/{D}+ { + return SLASH_SUFFIX; +} + +(0x|0X)?{H}+ { return HEXNUM; } + +task:|task|at|time:|octets { return KEYWORD; } + +<> { at_eof++; yyterminate(); } + +(.|\n) ; + +%% + +void ascend_init_lexer(FILE_T fh) +{ + yyrestart(0); + yy_fh = fh; + BEGIN(INITIAL); +} + +/* + * We want to stop processing when we get to the end of the input. + * (%option noyywrap is not used because if used then + * some flex versions (eg: 2.5.35) generate code which causes + * warnings by the Windows VC compiler). + */ + +int yywrap(void) { + return 1; +} diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c new file mode 100644 index 0000000000..f8597ae245 --- /dev/null +++ b/wiretap/ascendtext.c @@ -0,0 +1,343 @@ +/* ascendtext.c + * + * $Id$ + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "wtap-int.h" +#include "buffer.h" +#include "ascendtext.h" +#include "ascend-int.h" +#include "file_wrappers.h" +#include + +#include + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include + +/* Last updated: Feb 03 2005: Josh Bailey (joshbailey@lucent.com). + + This module reads the text hex dump output of various TAOS + (Lucent/Ascend Max, Max TNT, APX, etc) debug commands, including: + + * pridisplay traces primary rate ISDN + * ether-display traces Ethernet packets (dangerous! CPU intensive) + * wanopening, wandisplay, wannext, wandsess + traces PPP or other WAN connections + + Please see ascend.y for examples. + + Detailed documentation on TAOS products is at http://support.lucent.com. + + Support for other commands will be added on an ongoing basis. */ + +typedef struct _ascend_magic_string { + guint type; + const gchar *strptr; +} ascend_magic_string; + +#define ASCEND_MAGIC_STRINGS 11 +#define ASCEND_DATE "Date:" + +/* these magic strings signify the headers of a supported debug commands */ +static const ascend_magic_string ascend_magic[] = { + { ASCEND_PFX_ISDN_X, "PRI-XMIT-" }, + { ASCEND_PFX_ISDN_R, "PRI-RCV-" }, + { ASCEND_PFX_WDS_X, "XMIT-" }, + { ASCEND_PFX_WDS_R, "RECV-" }, + { ASCEND_PFX_WDS_X, "XMIT:" }, + { ASCEND_PFX_WDS_R, "RECV:" }, + { ASCEND_PFX_WDS_X, "PPP-OUT" }, + { ASCEND_PFX_WDS_R, "PPP-IN" }, + { ASCEND_PFX_WDD, ASCEND_DATE }, + { ASCEND_PFX_WDD, "WD_DIALOUT_DISP:" }, + { ASCEND_PFX_ETHER, "ETHER" }, +}; + +static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset); +static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, + union wtap_pseudo_header *pseudo_head, guint8 *pd, int len, + int *err, gchar **err_info); +static void ascend_close(wtap *wth); + +/* Seeks to the beginning of the next packet, and returns the + byte offset at which the header for that packet begins. + Returns -1 on failure. */ +static gint64 ascend_seek(wtap *wth, int *err) +{ + int byte; + gint64 date_off = -1, cur_off, packet_off; + size_t string_level[ASCEND_MAGIC_STRINGS]; + guint string_i = 0, type = 0; + guint excessive_read_count = 262144; + + memset(&string_level, 0, sizeof(string_level)); + + while (((byte = file_getc(wth->fh)) != EOF)) { + excessive_read_count--; + + if (!excessive_read_count) { + return -1; + } + + for (string_i = 0; string_i < ASCEND_MAGIC_STRINGS; string_i++) { + const gchar *strptr = ascend_magic[string_i].strptr; + size_t len = strlen(strptr); + + if (byte == *(strptr + string_level[string_i])) { + string_level[string_i]++; + if (string_level[string_i] >= len) { + cur_off = file_tell(wth->fh); + if (cur_off == -1) { + /* Error. */ + *err = file_error(wth->fh); + return -1; + } + + /* Date: header is a special case. Remember the offset, + but keep looking for other headers. */ + if (strcmp(strptr, ASCEND_DATE) == 0) { + date_off = cur_off - len; + } else { + if (date_off == -1) { + /* Back up over the header we just read; that's where a read + of this packet should start. */ + packet_off = cur_off - len; + } else { + /* This packet has a date/time header; a read of it should + start at the beginning of *that* header. */ + packet_off = date_off; + } + + type = ascend_magic[string_i].type; + goto found; + } + } + } else { + string_level[string_i] = 0; + } + } + } + + if (byte != EOF || file_eof(wth->fh)) { + /* Either we didn't find the offset, or we got an EOF. */ + *err = 0; + } else { + /* We (presumably) got an error (there's no equivalent to "ferror()" + in zlib, alas, so we don't have a wrapper to check for an error). */ + *err = file_error(wth->fh); + } + return -1; + +found: + /* + * Move to where the read for this packet should start, and return + * that seek offset. + */ + if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1) + return -1; + + wth->pseudo_header.ascend.type = type; + + return packet_off; +} + +int ascend_open(wtap *wth, int *err, gchar **err_info _U_) +{ + gint64 offset; + struct stat statbuf; + guint8 buf[ASCEND_MAX_PKT_LEN]; + ascend_pkthdr header; + gint64 dummy_seek_start; + + /* We haven't yet allocated a data structure for our private stuff; + set the pointer to null, so that "ascend_seek()" knows not to + fill it in. */ + wth->capture.ascend = NULL; + + offset = ascend_seek(wth, err); + if (offset == -1) { + if (*err == 0) + return 0; + else + return -1; + } + + /* Do a trial parse of the first packet just found to see if we might really have an Ascend file */ + init_parse_ascend(); + if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, &dummy_seek_start)) { + return 0; + } + + wth->data_offset = offset; + wth->file_type = WTAP_FILE_ASCEND; + + switch(wth->pseudo_header.ascend.type) { + case ASCEND_PFX_ISDN_X: + case ASCEND_PFX_ISDN_R: + wth->file_encap = WTAP_ENCAP_ISDN; + break; + + case ASCEND_PFX_ETHER: + wth->file_encap = WTAP_ENCAP_ETHERNET; + break; + + default: + wth->file_encap = WTAP_ENCAP_ASCEND; + } + + wth->snapshot_length = ASCEND_MAX_PKT_LEN; + wth->subtype_read = ascend_read; + wth->subtype_seek_read = ascend_seek_read; + wth->subtype_close = ascend_close; + wth->capture.ascend = g_malloc(sizeof(ascend_t)); + + /* The first packet we want to read is the one that "ascend_seek()" + just found; start searching for it at the offset at which it + found it. */ + wth->capture.ascend->next_packet_seek_start = offset; + + /* MAXen and Pipelines report the time since reboot. In order to keep + from reporting packet times near the epoch, we subtract the first + packet's timestamp from the capture file's ctime, which gives us an + offset that we can apply to each packet. + */ + if (fstat(wth->fd, &statbuf) == -1) { + *err = errno; + g_free(wth->capture.ascend); + return -1; + } + wth->capture.ascend->inittime = statbuf.st_ctime; + wth->capture.ascend->adjusted = 0; + wth->tsprecision = WTAP_FILE_TSPREC_USEC; + + init_parse_ascend(); + + return 1; +} + +static void config_pseudo_header(union wtap_pseudo_header *pseudo_head) +{ + switch(pseudo_head->ascend.type) { + case ASCEND_PFX_ISDN_X: + pseudo_head->isdn.uton = TRUE; + pseudo_head->isdn.channel = 0; + break; + + case ASCEND_PFX_ISDN_R: + pseudo_head->isdn.uton = FALSE; + pseudo_head->isdn.channel = 0; + break; + + case ASCEND_PFX_ETHER: + pseudo_head->eth.fcs_len = 0; + break; + } +} + +/* Read the next packet; called from wtap_read(). */ +static gboolean ascend_read(wtap *wth, int *err, gchar **err_info, + gint64 *data_offset) +{ + gint64 offset; + guint8 *buf = buffer_start_ptr(wth->frame_buffer); + ascend_pkthdr header; + + /* parse_ascend() will advance the point at which to look for the next + packet's header, to just after the last packet's header (ie. at the + start of the last packet's data). We have to get past the last + packet's header because we might mistake part of it for a new header. */ + if (file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start, + SEEK_SET, err) == -1) + return FALSE; + + offset = ascend_seek(wth, err); + if (offset == -1) + return FALSE; + if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, &(wth->capture.ascend->next_packet_seek_start))) { + *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); + return FALSE; + } + + buffer_assure_space(wth->frame_buffer, wth->snapshot_length); + + config_pseudo_header(&wth->pseudo_header); + + if (! wth->capture.ascend->adjusted) { + wth->capture.ascend->adjusted = 1; + if (header.start_time != 0) { + /* + * Capture file contained a date and time. + * We do this only if this is the very first packet we've seen - + * i.e., if "wth->capture.ascend->adjusted" is false - because + * if we get a date and time after the first packet, we can't + * go back and adjust the time stamps of the packets we've already + * processed, and basing the time stamps of this and following + * packets on the time stamp from the file text rather than the + * ctime of the capture file means times before this and after + * this can't be compared. + */ + wth->capture.ascend->inittime = header.start_time; + } + if (wth->capture.ascend->inittime > header.secs) + wth->capture.ascend->inittime -= header.secs; + } + wth->phdr.ts.secs = header.secs + wth->capture.ascend->inittime; + wth->phdr.ts.nsecs = header.usecs * 1000; + wth->phdr.caplen = header.caplen; + wth->phdr.len = header.len; + wth->data_offset = offset; + + *data_offset = offset; + return TRUE; +} + +static gboolean ascend_seek_read(wtap *wth, gint64 seek_off, + union wtap_pseudo_header *pseudo_head, guint8 *pd, int len, + int *err, gchar **err_info) +{ + /* don't care for length. */ + (void) len; + + if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) + return FALSE; + if (! parse_ascend(wth->random_fh, pd, &pseudo_head->ascend, NULL, &(wth->capture.ascend->next_packet_seek_start))) { + *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup((ascend_parse_error != NULL) ? ascend_parse_error : "parse error"); + return FALSE; + } + + config_pseudo_header(pseudo_head); + return TRUE; +} + +static void ascend_close(wtap *wth) +{ + g_free(wth->capture.ascend); +} diff --git a/wiretap/ascendtext.h b/wiretap/ascendtext.h new file mode 100644 index 0000000000..f2bcd7fb43 --- /dev/null +++ b/wiretap/ascendtext.h @@ -0,0 +1,33 @@ +/* ascend.h + * + * $Id$ + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __ASCENDTEXT_H__ +#define __ASCENDTEXT_H__ + +#define ASCEND_MAX_DATA_ROWS 8 +#define ASCEND_MAX_DATA_COLS 16 +#define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS) + +int ascend_open(wtap *wth, int *err, gchar **err_info); + +#endif diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 98e06e9b18..8d431b61a7 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -47,7 +47,7 @@ #include "airopeek9.h" #include "ngsniffer.h" #include "radcom.h" -#include "ascend.h" +#include "ascendtext.h" #include "nettl.h" #include "libpcap.h" #include "snoop.h" diff --git a/wiretap/libwiretap.vcproj b/wiretap/libwiretap.vcproj index 5191c74a94..9779aa6a46 100644 --- a/wiretap/libwiretap.vcproj +++ b/wiretap/libwiretap.vcproj @@ -72,7 +72,7 @@ >