2001-10-19 20:18:48 +00:00
|
|
|
/* dbs-etherwatch.c
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-10-19 20:18:48 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2003-01-17 23:54:19 +00:00
|
|
|
* Copyright (c) 2001 by Marc Milgram <ethereal@mmilgram.NOSPAMmail.net>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2001-10-19 20:18:48 +00:00
|
|
|
* 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.
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2001-10-19 20:18:48 +00:00
|
|
|
* 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.
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
2001-10-19 20:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wtap-int.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "dbs-etherwatch.h"
|
|
|
|
#include "file_wrappers.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
/* This module reads the text output of the 'DBS-ETHERTRACE' command in VMS
|
|
|
|
* It was initially based on vms.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-12-07 01:18:17 +00:00
|
|
|
Example 'ETHERWATCH' output data (with "printable" characters in the
|
|
|
|
"printable characters" section of the output replaced by "." if they have
|
|
|
|
the 8th bit set, so as not to upset compilers that are expecting text
|
|
|
|
in comments to be in a particular character encoding that can't handle
|
|
|
|
those values):
|
2001-10-19 20:18:48 +00:00
|
|
|
ETHERWATCH X5-008
|
|
|
|
42 names and addresses were loaded
|
|
|
|
Reading recorded data from PERSISTENCE
|
|
|
|
------------------------------------------------------------------------------
|
2002-03-04 00:25:35 +00:00
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
2001-10-19 20:18:48 +00:00
|
|
|
Protocol 08-00 00 00-00-00-00-00, 60 byte buffer at 10-OCT-2001 10:20:45.16
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..<8...........]- 0-[45 00 00 3C 38 93 00 00 1D 06 D2 12 80 93 11 1A]
|
|
|
|
[.........(......]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 90 00 00 00 00]
|
|
|
|
[................]- 32-[A0 02 FF FF 95 BD 00 00 02 04 05 B4 03 03 04 01]
|
|
|
|
[............ ]- 48-[01 01 08 0A 90 90 E5 14 00 00 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
------------------------------------------------------------------------------
|
2002-03-04 00:25:35 +00:00
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
2001-10-19 20:18:48 +00:00
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..(8......%....]- 0-[45 00 00 28 38 94 00 00 1D 06 D2 25 80 93 11 1A]
|
|
|
|
[.........(..Z.4w]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 91 5A 1C 34 77]
|
|
|
|
[P.#(.s..........]- 32-[50 10 23 28 C1 73 00 00 02 04 05 B4 03 03 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
[.. ]- 48-[02 04]
|
2003-12-29 00:36:12 +00:00
|
|
|
|
|
|
|
|
2006-05-28 15:56:15 +00:00
|
|
|
Alternative HEX only output, slightly more efficient and all wireshark needs:
|
2003-12-29 00:36:12 +00:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
|
|
|
0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A 80 93 80 D6]
|
|
|
|
20-[02 D2 02 03 00 28 A4 BF 5A 1C 34 79 50 10 23 28 C1 43 00 00]
|
|
|
|
40-[03 30 30 30 30 30 00 00 03 30]
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Magic text to check for DBS-ETHERWATCH-ness of file */
|
|
|
|
static const char dbs_etherwatch_hdr_magic[] =
|
|
|
|
{ 'E', 'T', 'H', 'E', 'R', 'W', 'A', 'T', 'C', 'H', ' ', ' '};
|
|
|
|
#define DBS_ETHERWATCH_HDR_MAGIC_SIZE \
|
|
|
|
(sizeof dbs_etherwatch_hdr_magic / sizeof dbs_etherwatch_hdr_magic[0])
|
|
|
|
|
|
|
|
/* Magic text for start of packet */
|
|
|
|
static const char dbs_etherwatch_rec_magic[] =
|
|
|
|
{'F', 'r', 'o', 'm', ' '};
|
|
|
|
#define DBS_ETHERWATCH_REC_MAGIC_SIZE \
|
|
|
|
(sizeof dbs_etherwatch_rec_magic / sizeof dbs_etherwatch_rec_magic[0])
|
|
|
|
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
/*
|
|
|
|
* XXX - is this the biggest packet we can get?
|
|
|
|
*/
|
|
|
|
#define DBS_ETHERWATCH_MAX_PACKET_LEN 16384
|
|
|
|
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 *data_offset);
|
|
|
|
static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
|
2012-10-16 21:50:57 +00:00
|
|
|
struct wtap_pkthdr *phdr, guint8 *pd, int len,
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
int *err, gchar **err_info);
|
2003-12-29 00:36:12 +00:00
|
|
|
static int parse_dbs_etherwatch_packet(wtap *wth, FILE_T fh, guint8* buf,
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
int *err, gchar **err_info);
|
2003-12-29 00:36:12 +00:00
|
|
|
static guint parse_single_hex_dump_line(char* rec, guint8 *buf,
|
|
|
|
int byte_offset);
|
|
|
|
static guint parse_hex_dump(char* dump, guint8 *buf, char seperator, char end);
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
/* Seeks to the beginning of the next packet, and returns the
|
2011-04-21 09:41:52 +00:00
|
|
|
byte offset. Returns -1 on failure, and sets "*err" to the error
|
|
|
|
and "*err_info" to null or an additional error string. */
|
|
|
|
static gint64 dbs_etherwatch_seek_next_packet(wtap *wth, int *err,
|
|
|
|
gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
|
|
|
int byte;
|
|
|
|
unsigned int level = 0;
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 cur_off;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
while ((byte = file_getc(wth->fh)) != EOF) {
|
|
|
|
if (byte == dbs_etherwatch_rec_magic[level]) {
|
|
|
|
level++;
|
|
|
|
if (level >= DBS_ETHERWATCH_REC_MAGIC_SIZE) {
|
2002-03-04 00:25:35 +00:00
|
|
|
/* note: we're leaving file pointer right after the magic characters */
|
|
|
|
cur_off = file_tell(wth->fh);
|
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(wth->fh, err_info);
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return cur_off + 1;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
level = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-12-27 22:59:39 +00:00
|
|
|
/* EOF or error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DBS_ETHERWATCH_HEADER_LINES_TO_CHECK 200
|
|
|
|
#define DBS_ETHERWATCH_LINE_LENGTH 240
|
|
|
|
|
|
|
|
/* Look through the first part of a file to see if this is
|
|
|
|
* a DBS Ethertrace text trace file.
|
|
|
|
*
|
2002-03-04 00:25:35 +00:00
|
|
|
* Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
|
2011-04-21 09:41:52 +00:00
|
|
|
* if we get an I/O error, "*err" will be set to a non-zero value and
|
|
|
|
* "*err_info" will be set to null or an error string.
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2011-04-21 09:41:52 +00:00
|
|
|
static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err,
|
|
|
|
gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
|
|
|
char buf[DBS_ETHERWATCH_LINE_LENGTH];
|
|
|
|
int line, byte;
|
2009-03-07 05:13:12 +00:00
|
|
|
gsize reclen;
|
|
|
|
unsigned int i, level;
|
2002-08-28 20:30:45 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
buf[DBS_ETHERWATCH_LINE_LENGTH-1] = 0;
|
|
|
|
|
|
|
|
for (line = 0; line < DBS_ETHERWATCH_HEADER_LINES_TO_CHECK; line++) {
|
2012-12-27 22:59:39 +00:00
|
|
|
if (file_gets(buf, DBS_ETHERWATCH_LINE_LENGTH, wth->fh) == NULL) {
|
|
|
|
/* EOF or error. */
|
|
|
|
*err = file_error(wth->fh, err_info);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
reclen = strlen(buf);
|
|
|
|
if (reclen < DBS_ETHERWATCH_HDR_MAGIC_SIZE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
level = 0;
|
|
|
|
for (i = 0; i < reclen; i++) {
|
|
|
|
byte = buf[i];
|
|
|
|
if (byte == dbs_etherwatch_hdr_magic[level]) {
|
|
|
|
level++;
|
|
|
|
if (level >=
|
|
|
|
DBS_ETHERWATCH_HDR_MAGIC_SIZE) {
|
|
|
|
return TRUE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-04 00:25:35 +00:00
|
|
|
else
|
2012-12-27 22:59:39 +00:00
|
|
|
level = 0;
|
2002-03-04 00:25:35 +00:00
|
|
|
}
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2002-03-04 00:25:35 +00:00
|
|
|
*err = 0;
|
2001-10-19 20:18:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-21 09:41:52 +00:00
|
|
|
int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
|
|
|
/* Look for DBS ETHERWATCH header */
|
2011-04-21 09:41:52 +00:00
|
|
|
if (!dbs_etherwatch_check_file_type(wth, err, err_info)) {
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
return 0;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
wth->file_encap = WTAP_ENCAP_ETHERNET;
|
2001-10-19 20:18:48 +00:00
|
|
|
wth->file_type = WTAP_FILE_DBS_ETHERWATCH;
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
wth->snapshot_length = 0; /* not known */
|
2001-10-19 20:18:48 +00:00
|
|
|
wth->subtype_read = dbs_etherwatch_read;
|
|
|
|
wth->subtype_seek_read = dbs_etherwatch_seek_read;
|
2006-07-04 18:32:32 +00:00
|
|
|
wth->tsprecision = WTAP_FILE_TSPREC_CSEC;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-03 11:00:49 +00:00
|
|
|
/* Find the next packet and parse it; called from wtap_read(). */
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 *data_offset)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 offset;
|
2001-10-19 20:18:48 +00:00
|
|
|
guint8 *buf;
|
|
|
|
int pkt_len;
|
|
|
|
|
|
|
|
/* Find the next packet */
|
2011-04-21 09:41:52 +00:00
|
|
|
offset = dbs_etherwatch_seek_next_packet(wth, err, err_info);
|
2002-03-04 00:25:35 +00:00
|
|
|
if (offset < 1)
|
2001-10-19 20:18:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Make sure we have enough room for the packet */
|
Have Wiretap set the snapshot length to 0 if it can't be derived from
reading the capture file. Have callers of "wtap_snapshot_length()"
treat a value of 0 as "unknown", and default to WTAP_MAX_PACKET_SIZE (so
that, when writing a capture file in a format that *does* store the
snapshot length, we can at least put *something* in the file).
If we don't know the snapshot length of the current capture file, don't
display a value in the summary window.
Don't use "cfile.snap" as the snapshot length option when capturing -
doing so causes Ethereal to default, when capturing, to the snapshot
length of the last capture file that you read in, rather than to the
snapshot length of the last capture you did (or the initial default of
"no snapshot length").
Redo the "Capture Options" dialog box to group options into sections
with frames around them, and add units to the snapshot length, maximum
file size, and capture duration options, as per a suggestion by Ulf
Lamping. Also add units to the capture count option.
Make the snapshot length, capture count, maximum file size, and capture
duration options into a combination of a check box and a spin button.
If the check box is not checked, the limit in question is inactive
(snapshot length of 65535, no max packet count, no max file size, no max
capture duration); if it's checked, the spinbox specifies the limit.
Default all of the check boxes to "not checked" and all of the spin
boxes to small values.
Use "gtk_toggle_button_get_active()" rather than directly fetching the
state of a check box.
svn path=/trunk/; revision=4709
2002-02-08 10:07:41 +00:00
|
|
|
buffer_assure_space(wth->frame_buffer, DBS_ETHERWATCH_MAX_PACKET_LEN);
|
2001-10-19 20:18:48 +00:00
|
|
|
buf = buffer_start_ptr(wth->frame_buffer);
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse the packet */
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
pkt_len = parse_dbs_etherwatch_packet(wth, wth->fh, buf, err, err_info);
|
2003-12-29 00:36:12 +00:00
|
|
|
if (pkt_len == -1)
|
2002-03-05 05:58:41 +00:00
|
|
|
return FALSE;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2003-12-31 01:07:09 +00:00
|
|
|
/*
|
|
|
|
* We don't have an FCS in this frame.
|
|
|
|
*/
|
2012-10-16 21:50:57 +00:00
|
|
|
wth->phdr.pseudo_header.eth.fcs_len = 0;
|
2003-12-31 01:07:09 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
*data_offset = offset;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used to read packets in random-access fashion */
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean
|
2006-11-05 22:46:44 +00:00
|
|
|
dbs_etherwatch_seek_read (wtap *wth, gint64 seek_off,
|
2012-10-16 21:50:57 +00:00
|
|
|
struct wtap_pkthdr *phdr,
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
guint8 *pd, int len, int *err, gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
2012-10-16 21:50:57 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
|
2001-10-19 20:18:48 +00:00
|
|
|
int pkt_len;
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
pkt_len = parse_dbs_etherwatch_packet(NULL, wth->random_fh, pd, err,
|
|
|
|
err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
if (pkt_len != len) {
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
if (pkt_len != -1) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup_printf("dbs_etherwatch: packet length %d doesn't match requested length %d",
|
|
|
|
pkt_len, len);
|
|
|
|
}
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2003-12-31 01:07:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't have an FCS in this frame.
|
|
|
|
*/
|
|
|
|
pseudo_header->eth.fcs_len = 0;
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
return TRUE;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a packet */
|
|
|
|
/*
|
|
|
|
Packet header:
|
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
|
|
|
From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
|
|
|
|
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
|
|
|
|
*/
|
|
|
|
#define MAC_ADDR_LENGTH 6 /* Length MAC address */
|
|
|
|
#define DEST_MAC_PREFIX "] to " /* Prefix to the dest. MAC address */
|
|
|
|
#define PROTOCOL_LENGTH 2 /* Length protocol */
|
|
|
|
#define PROTOCOL_POS 9 /* Position protocol */
|
|
|
|
#define SAP_LENGTH 2 /* Length DSAP+SSAP */
|
|
|
|
#define SAP_POS 9 /* Position DSAP+SSAP */
|
|
|
|
#define CTL_UNNUMB_LENGTH 1 /* Length unnumbered control field */
|
|
|
|
#define CTL_NUMB_LENGTH 2 /* Length numbered control field */
|
|
|
|
#define CTL_POS 15 /* Position control field */
|
|
|
|
#define PID_LENGTH 5 /* Length PID */
|
|
|
|
#define PID_POS 18 /* Position PID */
|
|
|
|
#define LENGTH_POS 33 /* Position length */
|
|
|
|
#define HEX_HDR_SPR '-' /* Seperator char header hex values */
|
|
|
|
#define HEX_HDR_END ' ' /* End char hdr. hex val. except PID */
|
|
|
|
#define HEX_PID_END ',' /* End char PID hex value */
|
|
|
|
#define IEEE802_LEN_LEN 2 /* Length of the IEEE 802 len. field */
|
|
|
|
/*
|
|
|
|
To check whether it is Ethernet II or IEEE 802 we check the values of the
|
|
|
|
control field and PID, when they are all 0's we assume it is Ethernet II
|
|
|
|
else IEEE 802. In IEEE 802 the DSAP and SSAP are behind protocol, the
|
|
|
|
length in the IEEE data we have to construct.
|
|
|
|
*/
|
|
|
|
#define ETH_II_CHECK_POS 15
|
|
|
|
#define ETH_II_CHECK_STR "00 00-00-00-00-00,"
|
|
|
|
/*
|
|
|
|
To check whether it IEEE 802.3 with SNAP we check that both the DSAP & SSAP
|
|
|
|
values are 0xAA and the control field 0x03.
|
|
|
|
*/
|
|
|
|
#define SNAP_CHECK_POS 9
|
|
|
|
#define SNAP_CHECK_STR "AA-AA 03"
|
|
|
|
/*
|
|
|
|
To check whether the control field is 1 or two octets we check if it is
|
|
|
|
unnumbered. Unnumbered has length 1, numbered 2.
|
|
|
|
*/
|
|
|
|
#define CTL_UNNUMB_MASK 0x03
|
|
|
|
#define CTL_UNNUMB_VALUE 0x03
|
2001-10-19 20:18:48 +00:00
|
|
|
static int
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
parse_dbs_etherwatch_packet(wtap *wth, FILE_T fh, guint8* buf, int *err,
|
|
|
|
gchar **err_info)
|
2001-10-19 20:18:48 +00:00
|
|
|
{
|
|
|
|
char line[DBS_ETHERWATCH_LINE_LENGTH];
|
|
|
|
int num_items_scanned;
|
2003-12-29 00:36:12 +00:00
|
|
|
int eth_hdr_len, pkt_len, csec;
|
|
|
|
int length_pos, length_from, length;
|
2004-10-01 12:31:52 +00:00
|
|
|
struct tm tm;
|
2011-02-16 00:44:12 +00:00
|
|
|
char mon[4] = "xxx";
|
2004-01-24 16:48:12 +00:00
|
|
|
gchar *p;
|
2009-04-24 12:16:01 +00:00
|
|
|
static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
|
2003-12-29 00:36:12 +00:00
|
|
|
int count, line_count;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
eth_hdr_len = 0;
|
2012-05-16 16:29:12 +00:00
|
|
|
memset(&tm, 0, sizeof(tm));
|
2001-10-19 20:18:48 +00:00
|
|
|
/* Our file pointer should be on the first line containing the
|
|
|
|
* summary information for a packet. Read in that line and
|
|
|
|
* extract the useful information
|
|
|
|
*/
|
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(fh, err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Get the destination address */
|
|
|
|
p = strstr(line, DEST_MAC_PREFIX);
|
|
|
|
if(!p) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: destination address not found");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p += strlen(DEST_MAC_PREFIX);
|
|
|
|
if(parse_hex_dump(p, &buf[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END)
|
|
|
|
!= MAC_ADDR_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: destination address not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += MAC_ADDR_LENGTH;
|
|
|
|
|
|
|
|
/* Get the source address */
|
|
|
|
/*
|
|
|
|
* Since the first part of the line is already skipped in order to find
|
|
|
|
* the start of the record we cannot index, just look for the first
|
|
|
|
* 'HEX' character
|
|
|
|
*/
|
|
|
|
p = line;
|
2004-02-09 00:06:30 +00:00
|
|
|
while(!isxdigit((guchar)*p)) {
|
2003-12-29 00:36:12 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if(parse_hex_dump(p, &buf[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != MAC_ADDR_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: source address not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += MAC_ADDR_LENGTH;
|
|
|
|
|
|
|
|
/* Read the next line of the record header */
|
2001-10-19 20:18:48 +00:00
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(fh, err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Check the lines is as least as long as the length position */
|
|
|
|
if(strlen(line) < LENGTH_POS) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: line too short");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_items_scanned = sscanf(line + LENGTH_POS,
|
2011-04-07 23:16:05 +00:00
|
|
|
"%9d byte buffer at %2d-%3s-%4d %2d:%2d:%2d.%9d",
|
2003-12-29 00:36:12 +00:00
|
|
|
&pkt_len,
|
2004-10-01 12:31:52 +00:00
|
|
|
&tm.tm_mday, mon,
|
|
|
|
&tm.tm_year, &tm.tm_hour, &tm.tm_min,
|
|
|
|
&tm.tm_sec, &csec);
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
if (num_items_scanned != 8) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: header line not valid");
|
2001-10-19 20:18:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-05-16 16:29:12 +00:00
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Determine whether it is Ethernet II or IEEE 802 */
|
|
|
|
if(strncmp(&line[ETH_II_CHECK_POS], ETH_II_CHECK_STR,
|
|
|
|
strlen(ETH_II_CHECK_STR)) == 0) {
|
|
|
|
/* Ethernet II */
|
|
|
|
/* Get the Protocol */
|
|
|
|
if(parse_hex_dump(&line[PROTOCOL_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != PROTOCOL_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += PROTOCOL_LENGTH;
|
|
|
|
} else {
|
|
|
|
/* IEEE 802 */
|
|
|
|
/* Remember where to put the length in the header */
|
|
|
|
length_pos = eth_hdr_len;
|
|
|
|
/* Leave room in the header for the length */
|
|
|
|
eth_hdr_len += IEEE802_LEN_LEN;
|
|
|
|
/* Remember how much of the header should not be added to the length */
|
|
|
|
length_from = eth_hdr_len;
|
|
|
|
/* Get the DSAP + SSAP */
|
|
|
|
if(parse_hex_dump(&line[SAP_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != SAP_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += SAP_LENGTH;
|
|
|
|
/* Get the (first part of the) control field */
|
|
|
|
if(parse_hex_dump(&line[CTL_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_HDR_END) != CTL_UNNUMB_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Determine whether the control is numbered, and thus longer */
|
|
|
|
if((buf[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) {
|
|
|
|
/* Get the rest of the control field, the first octet in the PID */
|
|
|
|
if(parse_hex_dump(&line[PID_POS],
|
|
|
|
&buf[eth_hdr_len + CTL_UNNUMB_LENGTH], HEX_HDR_END,
|
|
|
|
HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += CTL_NUMB_LENGTH;
|
|
|
|
} else {
|
|
|
|
eth_hdr_len += CTL_UNNUMB_LENGTH;
|
|
|
|
}
|
|
|
|
/* Determine whether it is SNAP */
|
|
|
|
if(strncmp(&line[SNAP_CHECK_POS], SNAP_CHECK_STR,
|
|
|
|
strlen(SNAP_CHECK_STR)) == 0) {
|
|
|
|
/* Get the PID */
|
|
|
|
if(parse_hex_dump(&line[PID_POS], &buf[eth_hdr_len], HEX_HDR_SPR,
|
|
|
|
HEX_PID_END) != PID_LENGTH) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eth_hdr_len += PID_LENGTH;
|
|
|
|
}
|
|
|
|
/* Write the length in the header */
|
|
|
|
length = eth_hdr_len - length_from + pkt_len;
|
|
|
|
buf[length_pos] = (length) >> 8;
|
|
|
|
buf[length_pos+1] = (length) & 0xFF;
|
|
|
|
}
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
if (wth) {
|
2012-02-25 23:24:34 +00:00
|
|
|
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
p = strstr(months, mon);
|
|
|
|
if (p)
|
2009-03-07 05:13:12 +00:00
|
|
|
tm.tm_mon = (int)(p - months) / 3;
|
2004-10-01 12:31:52 +00:00
|
|
|
tm.tm_year -= 1900;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2004-10-01 12:31:52 +00:00
|
|
|
tm.tm_isdst = -1;
|
2005-08-24 21:31:56 +00:00
|
|
|
wth->phdr.ts.secs = mktime(&tm);
|
|
|
|
wth->phdr.ts.nsecs = csec * 10000000;
|
2003-12-29 00:36:12 +00:00
|
|
|
wth->phdr.caplen = eth_hdr_len + pkt_len;
|
|
|
|
wth->phdr.len = eth_hdr_len + pkt_len;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse the hex dump */
|
2006-07-04 18:32:32 +00:00
|
|
|
count = 0;
|
2003-12-29 00:36:12 +00:00
|
|
|
while (count < pkt_len) {
|
2001-10-19 20:18:48 +00:00
|
|
|
if (file_gets(line, DBS_ETHERWATCH_LINE_LENGTH, fh) == NULL) {
|
2011-04-21 09:41:52 +00:00
|
|
|
*err = file_error(fh, err_info);
|
2001-10-19 20:18:48 +00:00
|
|
|
if (*err == 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
if (!(line_count = parse_single_hex_dump_line(line,
|
|
|
|
&buf[eth_hdr_len + count], count))) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: packet data value not valid");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
count += line_count;
|
|
|
|
if (count > pkt_len) {
|
2011-12-13 09:53:50 +00:00
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
*err_info = g_strdup("dbs_etherwatch: packet data value has too many bytes");
|
2003-12-29 00:36:12 +00:00
|
|
|
return -1;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
return eth_hdr_len + pkt_len;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a hex dump line */
|
2001-10-19 20:18:48 +00:00
|
|
|
/*
|
2003-12-29 00:36:12 +00:00
|
|
|
/DISPLAY=BOTH output:
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
2007-12-07 01:18:17 +00:00
|
|
|
[E..(8...........]- 0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A]
|
|
|
|
[.........(..Z.4y]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 BF 5A 1C 34 79]
|
|
|
|
[P.#(.C...00000..]- 32-[50 10 23 28 C1 43 00 00 03 30 30 30 30 30 00 00]
|
2001-10-19 20:18:48 +00:00
|
|
|
[.0 ]- 48-[03 30]
|
2003-12-29 00:36:12 +00:00
|
|
|
|
|
|
|
/DISPLAY=HEXADECIMAL output:
|
|
|
|
|
|
|
|
1 2 3 4
|
|
|
|
0123456789012345678901234567890123456789012345
|
|
|
|
0-[45 00 00 28 38 9B 00 00 1D 06 D2 1E 80 93 11 1A 80 93 80 D6]
|
|
|
|
20-[02 D2 02 03 00 28 A4 BF 5A 1C 34 79 50 10 23 28 C1 43 00 00]
|
|
|
|
40-[03 30 30 30 30 30 00 00 03 30]
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
#define TYPE_CHECK_POS 2 /* Position to check the type of hex dump */
|
|
|
|
#define TYPE_CHECK_BOTH '[' /* Value at pos. that indicates BOTH type */
|
|
|
|
#define COUNT_POS_BOTH 21 /* Count position BOTH type */
|
|
|
|
#define COUNT_POS_HEX 1 /* Count position HEX type */
|
|
|
|
#define COUNT_SIZE 5 /* Length counter */
|
|
|
|
#define HEX_DUMP_START '[' /* Start char */
|
|
|
|
#define HEX_DUMP_SPR ' ' /* Seperator char */
|
|
|
|
#define HEX_DUMP_END ']' /* End char */
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
/* Take a string representing one line from a hex dump and converts the
|
|
|
|
* text to binary data. We check the printed offset with the offset
|
|
|
|
* we are passed to validate the record. We place the bytes in the buffer
|
|
|
|
* at the specified offset.
|
|
|
|
*
|
2003-12-29 00:36:12 +00:00
|
|
|
* Returns length parsed if a good hex dump, 0 if bad.
|
2001-10-19 20:18:48 +00:00
|
|
|
*/
|
2003-12-29 00:36:12 +00:00
|
|
|
static guint
|
|
|
|
parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset) {
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
int pos, i;
|
2003-12-29 00:36:12 +00:00
|
|
|
int value;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
|
|
|
|
2006-07-04 18:32:32 +00:00
|
|
|
/* Check that the record is as least as long as the check offset */
|
2003-12-29 00:36:12 +00:00
|
|
|
for(i = 0; i < TYPE_CHECK_POS; i++)
|
|
|
|
{
|
|
|
|
if(rec[i] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2006-07-04 18:32:32 +00:00
|
|
|
/* determine the format and thus the counter offset and hex dump length */
|
|
|
|
if(rec[TYPE_CHECK_POS] == TYPE_CHECK_BOTH)
|
|
|
|
{
|
|
|
|
pos = COUNT_POS_BOTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = COUNT_POS_HEX;
|
2012-05-16 16:29:12 +00:00
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
|
2006-07-04 18:32:32 +00:00
|
|
|
/* Check that the record is as least as long as the start position */
|
2003-12-29 00:36:12 +00:00
|
|
|
while(i < pos)
|
|
|
|
{
|
|
|
|
if(rec[i] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
/* Get the byte_offset directly from the record */
|
2003-12-29 00:36:12 +00:00
|
|
|
value = 0;
|
|
|
|
for(i = 0; i < COUNT_SIZE; i++) {
|
2004-02-09 00:06:30 +00:00
|
|
|
if(!isspace((guchar)rec[pos])) {
|
|
|
|
if(isdigit((guchar)rec[pos])) {
|
2003-12-29 00:36:12 +00:00
|
|
|
value *= 10;
|
|
|
|
value += rec[pos] - '0';
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
2002-08-28 20:30:45 +00:00
|
|
|
|
2001-10-19 20:18:48 +00:00
|
|
|
if (value != byte_offset) {
|
2003-12-29 00:36:12 +00:00
|
|
|
return 0;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* find the start of the hex dump */
|
|
|
|
while(rec[pos] != HEX_DUMP_START) {
|
|
|
|
if(rec[pos] == '\0') {
|
|
|
|
return 0;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
pos++;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|
2003-12-29 00:36:12 +00:00
|
|
|
pos++;
|
|
|
|
return parse_hex_dump(&rec[pos], buf, HEX_DUMP_SPR, HEX_DUMP_END);
|
|
|
|
}
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse a hex dump */
|
|
|
|
static guint
|
|
|
|
parse_hex_dump(char* dump, guint8 *buf, char seperator, char end) {
|
|
|
|
int pos, count;
|
2001-10-19 20:18:48 +00:00
|
|
|
|
2003-12-29 00:36:12 +00:00
|
|
|
/* Parse the hex dump */
|
|
|
|
pos = 0;
|
|
|
|
count = 0;
|
|
|
|
while(dump[pos] != end) {
|
|
|
|
/* Check the hex value */
|
2004-02-09 00:06:30 +00:00
|
|
|
if(!(isxdigit((guchar)dump[pos]) &&
|
|
|
|
isxdigit((guchar)dump[pos + 1]))) {
|
2003-12-29 00:36:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Get the hex value value */
|
2004-02-09 00:06:30 +00:00
|
|
|
if(isdigit((guchar)dump[pos])) {
|
2003-12-29 00:36:12 +00:00
|
|
|
buf[count] = (dump[pos] - '0') << 4;
|
|
|
|
} else {
|
|
|
|
buf[count] = (toupper(dump[pos]) - 'A' + 10) << 4;
|
|
|
|
}
|
|
|
|
pos++;
|
2004-02-09 00:06:30 +00:00
|
|
|
if(isdigit((guchar)dump[pos])) {
|
2003-12-29 00:36:12 +00:00
|
|
|
buf[count] += dump[pos] - '0';
|
|
|
|
} else {
|
|
|
|
buf[count] += toupper(dump[pos]) - 'A' + 10;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
count++;
|
2006-07-04 18:32:32 +00:00
|
|
|
/* Skip the seperator characters */
|
2003-12-29 00:36:12 +00:00
|
|
|
while(dump[pos] == seperator) {
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
2001-10-19 20:18:48 +00:00
|
|
|
}
|