1999-10-18 01:51:34 +00:00
|
|
|
/* nettl.c
|
1999-10-31 19:23:37 +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
|
|
|
* $Id: nettl.c,v 1.34 2004/01/25 21:55:16 guy Exp $
|
1999-10-18 01:51:34 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
1999-10-18 01:51:34 +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
|
|
|
*
|
1999-10-18 01:51:34 +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
|
|
|
*
|
1999-10-18 01:51:34 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
1999-10-18 01:51:34 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2000-11-17 21:00:40 +00:00
|
|
|
#include <string.h>
|
2000-05-19 23:07:04 +00:00
|
|
|
#include "wtap-int.h"
|
2000-01-13 07:09:20 +00:00
|
|
|
#include "file_wrappers.h"
|
1999-10-18 01:51:34 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "nettl.h"
|
|
|
|
|
2002-07-29 06:09:59 +00:00
|
|
|
static guchar nettl_magic_hpux9[12] = {
|
2000-01-20 17:13:42 +00:00
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x00
|
|
|
|
};
|
2002-07-29 06:09:59 +00:00
|
|
|
static guchar nettl_magic_hpux10[12] = {
|
2000-01-20 17:13:42 +00:00
|
|
|
0x54, 0x52, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
|
1999-10-18 01:51:34 +00:00
|
|
|
};
|
|
|
|
|
2000-02-17 21:08:15 +00:00
|
|
|
/* HP nettl record header for the SX25L2 subsystem - The FCS is not included in the file. */
|
|
|
|
struct nettlrec_sx25l2_hdr {
|
|
|
|
guint8 xxa[8];
|
|
|
|
guint8 from_dce;
|
|
|
|
guint8 xxb[55];
|
2003-05-05 01:01:36 +00:00
|
|
|
guint8 caplen[2];
|
2000-02-17 21:08:15 +00:00
|
|
|
guint8 length[2];
|
|
|
|
guint8 xxc[4];
|
|
|
|
guint8 sec[4];
|
|
|
|
guint8 usec[4];
|
|
|
|
guint8 xxd[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* HP nettl record header for the NS_LS_IP subsystem */
|
2000-11-13 23:02:24 +00:00
|
|
|
/* This also works for BASE100 and GSC100BT */
|
2000-02-17 21:08:15 +00:00
|
|
|
struct nettlrec_ns_ls_ip_hdr {
|
|
|
|
guint8 xxa[28];
|
2003-05-05 01:01:36 +00:00
|
|
|
guint8 caplen[4];
|
2000-02-17 21:08:15 +00:00
|
|
|
guint8 length[4];
|
|
|
|
guint8 sec[4];
|
|
|
|
guint8 usec[4];
|
|
|
|
guint8 xxb[16];
|
1999-10-18 01:51:34 +00:00
|
|
|
};
|
|
|
|
|
2000-11-13 23:02:24 +00:00
|
|
|
|
1999-10-18 01:51:34 +00:00
|
|
|
/* header is followed by data and once again the total length (2 bytes) ! */
|
|
|
|
|
2002-05-17 09:53:20 +00:00
|
|
|
|
|
|
|
/* NL_LS_DRIVER :
|
|
|
|
The following shows what the header looks like for NS_LS_DRIVER
|
|
|
|
The capture was taken on HPUX11 and for a 100baseT interface.
|
|
|
|
|
|
|
|
000080 00 44 00 0b 00 00 00 02 00 00 00 00 20 00 00 00
|
|
|
|
000090 00 00 00 00 00 00 04 06 00 00 00 00 00 00 00 00
|
|
|
|
0000a0 00 00 00 74 00 00 00 74 3c e3 76 19 00 06 34 63
|
|
|
|
0000b0 ff ff ff ff 00 00 00 00 00 00 00 00 ff ff ff ff
|
|
|
|
0000c0 00 00 00 00 00 00 01 02 00 5c 00 5c ff ff ff ff
|
|
|
|
0000d0 3c e3 76 19 00 06 34 5a 00 0b 00 14 <here starts the MAC heder>
|
|
|
|
|
|
|
|
Each entry starts with 0x0044000b
|
|
|
|
|
|
|
|
The values 0x005c at position 0x0000c8 and 0x0000ca matches the number of bytes in
|
|
|
|
the packet up to the next entry, which starts with 0x00440b again. These probably
|
|
|
|
indicate the real and captured length of the packet (order unknown)
|
|
|
|
|
|
|
|
The values 0x00000074 at positions 0x0000a0 and 0x0000a4 seems to indicate
|
|
|
|
the same number as positions 0x0000c8 and 0x0000ca but added with 24.
|
|
|
|
Perhaps we have here two layers of headers.
|
2002-08-28 20:30:45 +00:00
|
|
|
The first layer is fixed and consists of all the bytes from 0x000084 up to and
|
2002-05-17 09:53:20 +00:00
|
|
|
including 0x0000c3 which is a generic header for all packets captured from any
|
|
|
|
device. This header might be of fixed size 64 bytes and there might be something in
|
|
|
|
it which indicates the type of the next header which is link type specific.
|
|
|
|
Following this header there is another header for the 100baseT interface which
|
|
|
|
in this case is 24 bytes long spanning positions 0x0000c4 to 0x0000db.
|
|
|
|
|
2002-08-28 20:30:45 +00:00
|
|
|
When someone reports that the loading of the captures breaks, we can compare
|
2002-05-17 09:53:20 +00:00
|
|
|
this header above with what he/she got to learn how to distinguish between different
|
|
|
|
types of link specific headers.
|
|
|
|
|
|
|
|
|
|
|
|
For now:
|
|
|
|
The first header seems to be
|
2002-05-22 10:53:17 +00:00
|
|
|
a normal nettlrec_ns_ls_ip_hdr
|
2002-05-17 09:53:20 +00:00
|
|
|
|
|
|
|
The header for 100baseT seems to be
|
|
|
|
0-3 unknown
|
2003-05-05 01:01:36 +00:00
|
|
|
4-5 captured length
|
|
|
|
6-7 actual length
|
2002-08-28 20:30:45 +00:00
|
|
|
8-11 unknown
|
2002-05-17 09:53:20 +00:00
|
|
|
12-15 secs
|
2003-05-05 01:01:36 +00:00
|
|
|
16-19 usecs
|
2002-05-17 09:53:20 +00:00
|
|
|
20-23 unknown
|
|
|
|
*/
|
|
|
|
struct nettlrec_ns_ls_drv_eth_hdr {
|
|
|
|
guint8 xxa[4];
|
2003-05-05 01:01:36 +00:00
|
|
|
guint8 caplen[2];
|
|
|
|
guint8 length[2];
|
2002-05-17 09:53:20 +00:00
|
|
|
guint8 xxb[4];
|
|
|
|
guint8 sec[4];
|
2003-05-05 01:01:36 +00:00
|
|
|
guint8 usec[4];
|
2002-05-17 09:53:20 +00:00
|
|
|
guint8 xxc[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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 nettl_read(wtap *wth, int *err, gchar **err_info,
|
|
|
|
long *data_offset);
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean nettl_seek_read(wtap *wth, long seek_off,
|
2002-07-29 06:09:59 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guchar *pd,
|
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 length, int *err, gchar **err_info);
|
2000-05-19 08:18:17 +00:00
|
|
|
static int nettl_read_rec_header(wtap *wth, FILE_T fh,
|
2000-05-19 23:07:04 +00:00
|
|
|
struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header,
|
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);
|
2002-07-29 06:09:59 +00:00
|
|
|
static gboolean nettl_read_rec_data(FILE_T fh, guchar *pd, int length,
|
2002-03-05 08:40:27 +00:00
|
|
|
int *err);
|
2000-03-22 07:06:59 +00:00
|
|
|
static void nettl_close(wtap *wth);
|
1999-10-18 01:51:34 +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
|
|
|
int nettl_open(wtap *wth, int *err, gchar **err_info _U_)
|
1999-10-18 01:51:34 +00:00
|
|
|
{
|
2000-03-01 10:25:14 +00:00
|
|
|
char magic[12], os_vers[2];
|
1999-10-18 01:51:34 +00:00
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
/* Read in the string that should be at the start of a HP file */
|
|
|
|
errno = WTAP_ERR_CANT_READ;
|
2000-01-20 17:13:42 +00:00
|
|
|
bytes_read = file_read(magic, 1, 12, wth->fh);
|
|
|
|
if (bytes_read != 12) {
|
1999-10-31 19:23:37 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err != 0)
|
1999-10-18 01:51:34 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-20 17:13:42 +00:00
|
|
|
if (memcmp(magic, nettl_magic_hpux9, 12) &&
|
|
|
|
memcmp(magic, nettl_magic_hpux10, 12)) {
|
1999-10-18 01:51:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 0x63, SEEK_SET, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
2000-03-01 10:25:14 +00:00
|
|
|
wth->data_offset = 0x63;
|
|
|
|
bytes_read = file_read(os_vers, 1, 2, wth->fh);
|
|
|
|
if (bytes_read != 2) {
|
2002-03-04 00:25:35 +00:00
|
|
|
*err = file_error(wth->fh);
|
2000-03-01 10:25:14 +00:00
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 0x80, SEEK_SET, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-10-18 01:51:34 +00:00
|
|
|
wth->data_offset = 0x80;
|
|
|
|
|
|
|
|
/* This is an nettl file */
|
|
|
|
wth->file_type = WTAP_FILE_NETTL;
|
|
|
|
wth->capture.nettl = g_malloc(sizeof(nettl_t));
|
2000-04-15 21:12:37 +00:00
|
|
|
if (os_vers[0] == '1' && os_vers[1] == '1')
|
|
|
|
wth->capture.nettl->is_hpux_11 = TRUE;
|
|
|
|
else
|
|
|
|
wth->capture.nettl->is_hpux_11 = FALSE;
|
1999-10-18 01:51:34 +00:00
|
|
|
wth->subtype_read = nettl_read;
|
2000-05-18 09:09:50 +00:00
|
|
|
wth->subtype_seek_read = nettl_seek_read;
|
2000-03-22 07:06:59 +00:00
|
|
|
wth->subtype_close = nettl_close;
|
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 available in header, only in frame */
|
1999-10-18 01:51:34 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the next 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
|
|
|
static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
|
|
|
|
long *data_offset)
|
1999-10-18 01:51:34 +00:00
|
|
|
{
|
2000-05-18 09:09:50 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Read record header. */
|
2000-09-07 05:34:23 +00:00
|
|
|
*data_offset = wth->data_offset;
|
2000-05-18 09:09:50 +00:00
|
|
|
ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->pseudo_header,
|
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, err_info);
|
2000-05-18 09:09:50 +00:00
|
|
|
if (ret <= 0) {
|
|
|
|
/* Read error or EOF */
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
2000-05-18 09:09:50 +00:00
|
|
|
}
|
|
|
|
wth->data_offset += ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
|
|
|
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
|
2002-03-05 08:40:27 +00:00
|
|
|
if (!nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
|
|
|
|
wth->phdr.caplen, err))
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE; /* Read error */
|
2000-05-18 09:09:50 +00:00
|
|
|
wth->data_offset += wth->phdr.caplen;
|
2000-09-07 05:34:23 +00:00
|
|
|
return TRUE;
|
2000-05-18 09:09:50 +00:00
|
|
|
}
|
|
|
|
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean
|
2001-10-04 08:30:36 +00:00
|
|
|
nettl_seek_read(wtap *wth, long seek_off,
|
2002-07-29 06:09:59 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guchar *pd,
|
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 length, int *err, gchar **err_info)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct wtap_pkthdr phdr;
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2000-05-18 09:09:50 +00:00
|
|
|
|
|
|
|
/* Read record header. */
|
|
|
|
ret = nettl_read_rec_header(wth, wth->random_fh, &phdr, pseudo_header,
|
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, err_info);
|
2000-05-18 09:09:50 +00:00
|
|
|
if (ret <= 0) {
|
|
|
|
/* Read error or EOF */
|
2002-03-05 05:58:41 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
/* EOF means "short read" in random-access mode */
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
}
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2000-05-18 09:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
2002-03-05 05:58:41 +00:00
|
|
|
return nettl_read_rec_data(wth->random_fh, pd, length, err);
|
2000-05-18 09:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-05-19 08:18:17 +00:00
|
|
|
nettl_read_rec_header(wtap *wth, FILE_T fh, 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
|
|
|
union wtap_pseudo_header *pseudo_header, int *err,
|
|
|
|
gchar **err_info)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int bytes_read;
|
2000-02-17 21:08:15 +00:00
|
|
|
struct nettlrec_sx25l2_hdr lapb_hdr;
|
|
|
|
struct nettlrec_ns_ls_ip_hdr ip_hdr;
|
2002-05-17 09:53:20 +00:00
|
|
|
struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr;
|
1999-10-18 01:51:34 +00:00
|
|
|
guint16 length;
|
2000-05-18 09:09:50 +00:00
|
|
|
int offset = 0;
|
2000-02-17 21:08:15 +00:00
|
|
|
guint8 encap[4];
|
2000-03-01 10:25:14 +00:00
|
|
|
guint8 dummy[4];
|
1999-10-18 01:51:34 +00:00
|
|
|
|
|
|
|
errno = WTAP_ERR_CANT_READ;
|
2000-05-18 09:09:50 +00:00
|
|
|
bytes_read = file_read(encap, 1, 4, fh);
|
2000-02-17 21:08:15 +00:00
|
|
|
if (bytes_read != 4) {
|
2000-05-18 09:09:50 +00:00
|
|
|
*err = file_error(fh);
|
1999-10-31 19:23:37 +00:00
|
|
|
if (*err != 0)
|
1999-10-18 01:51:34 +00:00
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-18 09:09:50 +00:00
|
|
|
offset += 4;
|
|
|
|
|
2000-02-17 21:08:15 +00:00
|
|
|
switch (encap[3]) {
|
2003-05-05 01:01:36 +00:00
|
|
|
case NETTL_SUBSYS_LAN100 :
|
2000-11-13 23:02:24 +00:00
|
|
|
case NETTL_SUBSYS_BASE100 :
|
|
|
|
case NETTL_SUBSYS_GSC100BT :
|
2003-05-05 01:01:36 +00:00
|
|
|
case NETTL_SUBSYS_PCI100BT :
|
|
|
|
case NETTL_SUBSYS_SPP100BT :
|
|
|
|
case NETTL_SUBSYS_GELAN :
|
|
|
|
case NETTL_SUBSYS_BTLAN :
|
|
|
|
case NETTL_SUBSYS_INTL100 :
|
|
|
|
case NETTL_SUBSYS_IGELAN :
|
2000-11-13 23:02:24 +00:00
|
|
|
case NETTL_SUBSYS_NS_LS_IP :
|
2002-05-22 10:53:17 +00:00
|
|
|
case NETTL_SUBSYS_NS_LS_LOOPBACK :
|
|
|
|
case NETTL_SUBSYS_NS_LS_TCP :
|
|
|
|
case NETTL_SUBSYS_NS_LS_UDP :
|
|
|
|
case NETTL_SUBSYS_NS_LS_ICMP :
|
2002-08-28 20:30:45 +00:00
|
|
|
if( (encap[3] == NETTL_SUBSYS_NS_LS_IP)
|
|
|
|
|| (encap[3] == NETTL_SUBSYS_NS_LS_LOOPBACK)
|
|
|
|
|| (encap[3] == NETTL_SUBSYS_NS_LS_UDP)
|
2002-05-22 10:53:17 +00:00
|
|
|
|| (encap[3] == NETTL_SUBSYS_NS_LS_TCP) ){
|
2002-08-28 20:30:45 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_RAW_IP;
|
2002-05-22 10:53:17 +00:00
|
|
|
} else if (encap[3] == NETTL_SUBSYS_NS_LS_ICMP) {
|
2002-08-28 20:30:45 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_UNKNOWN;
|
2000-11-13 23:02:24 +00:00
|
|
|
} else {
|
|
|
|
wth->file_encap = WTAP_ENCAP_ETHERNET;
|
2002-08-28 20:30:45 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
|
2003-10-01 07:11:49 +00:00
|
|
|
/* We assume there's no FCS in this frame. */
|
|
|
|
pseudo_header->eth.fcs_len = 0;
|
2000-02-17 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
2000-11-13 23:02:24 +00:00
|
|
|
bytes_read = file_read(&ip_hdr, 1, sizeof ip_hdr, fh);
|
|
|
|
if (bytes_read != sizeof ip_hdr) {
|
2000-05-18 09:09:50 +00:00
|
|
|
*err = file_error(fh);
|
2000-03-01 10:25:14 +00:00
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-11-13 23:02:24 +00:00
|
|
|
offset += sizeof ip_hdr;
|
|
|
|
|
|
|
|
/* The packet header in HP-UX 11 nettl traces is 4 octets longer than
|
|
|
|
* HP-UX 9 and 10 */
|
|
|
|
if (wth->capture.nettl->is_hpux_11) {
|
|
|
|
bytes_read = file_read(dummy, 1, 4, fh);
|
|
|
|
if (bytes_read != 4) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset += 4;
|
2000-02-17 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
2000-11-13 23:02:24 +00:00
|
|
|
length = pntohl(&ip_hdr.length);
|
|
|
|
if (length <= 0) return 0;
|
|
|
|
phdr->len = length;
|
2003-05-05 01:01:36 +00:00
|
|
|
length = pntohl(&ip_hdr.caplen);
|
2000-11-13 23:02:24 +00:00
|
|
|
phdr->caplen = length;
|
|
|
|
|
2002-08-28 20:30:45 +00:00
|
|
|
|
2000-11-13 23:02:24 +00:00
|
|
|
phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
|
2003-05-05 01:01:36 +00:00
|
|
|
phdr->ts.tv_usec = pntohl(&ip_hdr.usec);
|
2002-05-17 09:53:20 +00:00
|
|
|
break;
|
|
|
|
case NETTL_SUBSYS_NS_LS_DRIVER :
|
2002-05-22 10:53:17 +00:00
|
|
|
bytes_read = file_read(&ip_hdr, 1, sizeof ip_hdr, fh);
|
|
|
|
if (bytes_read != sizeof ip_hdr) {
|
2002-05-17 09:53:20 +00:00
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-05-22 10:53:17 +00:00
|
|
|
offset += sizeof ip_hdr;
|
|
|
|
|
|
|
|
/* The packet header in HP-UX 11 nettl traces is 4 octets longer than
|
|
|
|
* HP-UX 9 and 10 */
|
|
|
|
if (wth->capture.nettl->is_hpux_11) {
|
|
|
|
bytes_read = file_read(dummy, 1, 4, fh);
|
|
|
|
if (bytes_read != 4) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset += 4;
|
|
|
|
}
|
2002-05-17 09:53:20 +00:00
|
|
|
|
2003-05-05 01:01:36 +00:00
|
|
|
/* XXX we dont know how to identify this as ethernet frames, so
|
2002-05-17 09:53:20 +00:00
|
|
|
we assumes everything is. We will crash and burn for anything else */
|
|
|
|
/* for encapsulated 100baseT we do this */
|
2002-08-28 20:30:45 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
|
2003-10-01 07:11:49 +00:00
|
|
|
/* We assume there's no FCS in this frame. */
|
|
|
|
pseudo_header->eth.fcs_len = 0;
|
2002-05-17 09:53:20 +00:00
|
|
|
bytes_read = file_read(&drv_eth_hdr, 1, sizeof drv_eth_hdr, fh);
|
|
|
|
if (bytes_read != sizeof drv_eth_hdr) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset += sizeof drv_eth_hdr;
|
|
|
|
|
2003-05-05 01:01:36 +00:00
|
|
|
length = pntohs(&drv_eth_hdr.length);
|
2002-05-17 09:53:20 +00:00
|
|
|
if (length <= 0) return 0;
|
|
|
|
phdr->len = length;
|
2003-05-05 01:01:36 +00:00
|
|
|
length = pntohs(&drv_eth_hdr.caplen);
|
2002-05-17 09:53:20 +00:00
|
|
|
phdr->caplen = length;
|
|
|
|
|
2002-05-22 10:53:17 +00:00
|
|
|
phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
|
2003-05-05 01:01:36 +00:00
|
|
|
phdr->ts.tv_usec = pntohl(&ip_hdr.usec);
|
2000-11-13 23:02:24 +00:00
|
|
|
break;
|
|
|
|
case NETTL_SUBSYS_SX25L2 :
|
|
|
|
phdr->pkt_encap = WTAP_ENCAP_LAPB;
|
|
|
|
bytes_read = file_read(&lapb_hdr, 1, sizeof lapb_hdr, fh);
|
|
|
|
if (bytes_read != sizeof lapb_hdr) {
|
2000-05-18 09:09:50 +00:00
|
|
|
*err = file_error(fh);
|
2000-03-01 10:25:14 +00:00
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-11-13 23:02:24 +00:00
|
|
|
offset += sizeof lapb_hdr;
|
|
|
|
|
|
|
|
if (wth->capture.nettl->is_hpux_11) {
|
|
|
|
bytes_read = file_read(dummy, 1, 4, fh);
|
|
|
|
if (bytes_read != 4) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset += 4;
|
|
|
|
}
|
2000-03-01 10:25:14 +00:00
|
|
|
|
2000-11-13 23:02:24 +00:00
|
|
|
length = pntohs(&lapb_hdr.length);
|
|
|
|
if (length <= 0) return 0;
|
|
|
|
phdr->len = length;
|
|
|
|
phdr->caplen = length;
|
|
|
|
|
|
|
|
phdr->ts.tv_sec = pntohl(&lapb_hdr.sec);
|
|
|
|
phdr->ts.tv_usec = pntohl(&lapb_hdr.usec);
|
2002-04-09 08:15:04 +00:00
|
|
|
pseudo_header->x25.flags =
|
|
|
|
(lapb_hdr.from_dce & 0x20 ? FROM_DCE : 0x00);
|
2000-11-13 23:02:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
|
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("nettl: network type %u unknown or unsupported",
|
|
|
|
encap[3]);
|
2000-11-13 23:02:24 +00:00
|
|
|
return -1;
|
1999-10-18 01:51:34 +00:00
|
|
|
}
|
2000-05-18 09:09:50 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean
|
2002-07-29 06:09:59 +00:00
|
|
|
nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
bytes_read = file_read(pd, 1, length, fh);
|
|
|
|
|
|
|
|
if (bytes_read != length) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err == 0)
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2000-05-18 09:09:50 +00:00
|
|
|
}
|
2002-03-05 08:40:27 +00:00
|
|
|
return TRUE;
|
1999-10-18 01:51:34 +00:00
|
|
|
}
|
2000-03-22 07:06:59 +00:00
|
|
|
|
|
|
|
static void nettl_close(wtap *wth)
|
|
|
|
{
|
|
|
|
g_free(wth->capture.nettl);
|
|
|
|
}
|