1999-08-02 02:26:22 +00:00
|
|
|
/* radcom.c
|
1999-09-23 05:03:32 +00:00
|
|
|
*
|
2002-07-29 06:09:59 +00:00
|
|
|
* $Id: radcom.c,v 1.38 2002/07/29 06:09:59 guy Exp $
|
1999-08-02 02:26:22 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
1999-08-02 02:26:22 +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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
1999-08-02 02:26:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
#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-08-02 02:26:22 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "radcom.h"
|
|
|
|
|
|
|
|
struct frame_date {
|
|
|
|
guint16 year;
|
|
|
|
guint8 month;
|
|
|
|
guint8 day;
|
|
|
|
guint32 sec; /* seconds since midnight */
|
|
|
|
guint32 usec;
|
|
|
|
};
|
|
|
|
|
1999-09-01 23:53:58 +00:00
|
|
|
struct unaligned_frame_date {
|
|
|
|
char year[2];
|
|
|
|
char month;
|
|
|
|
char day;
|
|
|
|
char sec[4]; /* seconds since midnight */
|
|
|
|
char usec[4];
|
|
|
|
};
|
|
|
|
|
1999-11-18 21:48:53 +00:00
|
|
|
static guint8 radcom_magic[8] = {
|
1999-08-02 02:26:22 +00:00
|
|
|
0x42, 0xD2, 0x00, 0x34, 0x12, 0x66, 0x22, 0x88
|
|
|
|
};
|
|
|
|
|
1999-09-01 23:53:58 +00:00
|
|
|
/* RADCOM record header - followed by frame data (perhaps including FCS).
|
|
|
|
The first two bytes of "xxz" appear to equal "length", as do the
|
|
|
|
second two bytes; if a RADCOM box can be told not to save all of
|
|
|
|
the captured packet, might one or the other of those be the
|
|
|
|
captured length of the packet? */
|
|
|
|
struct radcomrec_hdr {
|
|
|
|
char xxx[4]; /* unknown */
|
|
|
|
char length[2]; /* packet length */
|
|
|
|
char xxy[5]; /* unknown */
|
|
|
|
struct unaligned_frame_date date; /* date/time stamp of packet */
|
|
|
|
char xxz[6]; /* unknown */
|
|
|
|
char dce; /* DCE/DTE flag (and other flags?) */
|
|
|
|
char xxw[9]; /* unknown */
|
|
|
|
};
|
|
|
|
|
2001-10-04 08:30:36 +00:00
|
|
|
static gboolean radcom_read(wtap *wth, int *err, long *data_offset);
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean radcom_seek_read(wtap *wth, long seek_off,
|
2002-07-29 06:09:59 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guchar *pd, int length,
|
2002-03-05 05:58:41 +00:00
|
|
|
int *err);
|
2000-05-19 08:18:17 +00:00
|
|
|
static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr,
|
2000-05-18 09:09:50 +00:00
|
|
|
int *err);
|
2002-07-29 06:09:59 +00:00
|
|
|
static gboolean radcom_read_rec_data(FILE_T fh, guchar *pd, int length,
|
2002-03-05 08:40:27 +00:00
|
|
|
int *err);
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
|
|
|
|
int radcom_open(wtap *wth, int *err)
|
1999-08-02 02:26:22 +00:00
|
|
|
{
|
|
|
|
int bytes_read;
|
|
|
|
char magic[8];
|
|
|
|
struct frame_date start_date;
|
1999-08-31 00:25:19 +00:00
|
|
|
guint32 sec;
|
1999-08-02 02:26:22 +00:00
|
|
|
struct tm tm;
|
|
|
|
char byte;
|
2000-11-13 23:00:55 +00:00
|
|
|
char encap_magic[4] = {0x00, 0x42, 0x43, 0x09};
|
1999-08-02 02:26:22 +00:00
|
|
|
char search_encap[7];
|
|
|
|
|
1999-08-20 08:00:24 +00:00
|
|
|
/* Read in the string that should be at the start of a RADCOM file */
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(magic, 1, 8, wth->fh);
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != 8) {
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err != 0)
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 21:48:53 +00:00
|
|
|
if (memcmp(magic, radcom_magic, 8) != 0) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 0x8B, SEEK_SET, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset = 0x8B;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(&byte, 1, 1, wth->fh);
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != 1) {
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err != 0)
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 1;
|
1999-08-02 02:26:22 +00:00
|
|
|
while (byte) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(&byte, 1, 1, wth->fh);
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != 1) {
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err != 0)
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 1;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get capture start time */
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(&start_date, 1, sizeof(struct frame_date), wth->fh);
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != sizeof(struct frame_date)) {
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err != 0)
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += sizeof(struct frame_date);
|
1999-08-02 02:26:22 +00:00
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
/* This is a radcom file */
|
|
|
|
wth->file_type = WTAP_FILE_RADCOM;
|
|
|
|
wth->subtype_read = radcom_read;
|
2000-05-18 09:09:50 +00:00
|
|
|
wth->subtype_seek_read = radcom_seek_read;
|
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 */
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
|
1999-08-30 20:40:13 +00:00
|
|
|
tm.tm_year = pletohs(&start_date.year)-1900;
|
1999-08-02 02:26:22 +00:00
|
|
|
tm.tm_mon = start_date.month-1;
|
|
|
|
tm.tm_mday = start_date.day;
|
1999-08-31 00:25:19 +00:00
|
|
|
sec = pletohl(&start_date.sec);
|
|
|
|
tm.tm_hour = sec/3600;
|
|
|
|
tm.tm_min = (sec%3600)/60;
|
|
|
|
tm.tm_sec = sec%60;
|
1999-08-02 02:26:22 +00:00
|
|
|
tm.tm_isdst = -1;
|
|
|
|
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += sizeof(struct frame_date);
|
1999-08-02 02:26:22 +00:00
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
2000-11-13 23:00:55 +00:00
|
|
|
bytes_read = file_read(search_encap, 1, 4, wth->fh);
|
|
|
|
if (bytes_read != 4) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
goto read_error;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
2000-11-13 23:00:55 +00:00
|
|
|
wth->data_offset += 4;
|
|
|
|
while (memcmp(encap_magic, search_encap, 4)) {
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, -3, SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
2000-11-13 23:00:55 +00:00
|
|
|
wth->data_offset -= 3;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
2000-11-13 23:00:55 +00:00
|
|
|
bytes_read = file_read(search_encap, 1, 4, wth->fh);
|
|
|
|
if (bytes_read != 4) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
goto read_error;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
2000-11-13 23:00:55 +00:00
|
|
|
wth->data_offset += 4;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 12, SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 12;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(search_encap, 1, 4, wth->fh);
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != 4) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
goto read_error;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 4;
|
1999-08-02 02:26:22 +00:00
|
|
|
if (!memcmp(search_encap, "LAPB", 4))
|
|
|
|
wth->file_encap = WTAP_ENCAP_LAPB;
|
|
|
|
else if (!memcmp(search_encap, "Ethe", 4))
|
|
|
|
wth->file_encap = WTAP_ENCAP_ETHERNET;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
else {
|
|
|
|
g_message("pcap: network type \"%.4s\" unknown", search_encap);
|
2000-02-19 08:00:08 +00:00
|
|
|
*err = WTAP_ERR_UNSUPPORTED_ENCAP;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1999-08-02 02:26:22 +00:00
|
|
|
|
1999-09-22 01:26:50 +00:00
|
|
|
/*bytes_read = file_read(&next_date, 1, sizeof(struct frame_date), wth->fh);
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-08-02 02:26:22 +00:00
|
|
|
if (bytes_read != sizeof(struct frame_date)) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
goto read_error;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (memcmp(&start_date, &next_date, 4)) {
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(&next_date, 1, sizeof(struct frame_date),
|
1999-08-02 02:26:22 +00:00
|
|
|
wth->fh);
|
|
|
|
if (bytes_read != sizeof(struct frame_date)) {
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
goto read_error;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
1999-08-28 01:19:45 +00:00
|
|
|
if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 294, SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 294;
|
1999-08-28 01:19:45 +00:00
|
|
|
} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, 297, SEEK_CUR, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
1999-08-30 20:40:13 +00:00
|
|
|
wth->data_offset += 297;
|
1999-08-28 01:19:45 +00:00
|
|
|
}
|
1999-08-02 02:26:22 +00:00
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
read_error:
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
2000-04-15 21:12:37 +00:00
|
|
|
if (*err != 0)
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the next packet */
|
2001-10-04 08:30:36 +00:00
|
|
|
static gboolean radcom_read(wtap *wth, int *err, long *data_offset)
|
1999-08-02 02:26:22 +00:00
|
|
|
{
|
2000-05-18 09:09:50 +00:00
|
|
|
int ret;
|
1999-09-01 23:53:58 +00:00
|
|
|
struct radcomrec_hdr hdr;
|
1999-08-02 02:26:22 +00:00
|
|
|
guint16 length;
|
1999-08-31 00:25:19 +00:00
|
|
|
guint32 sec;
|
2000-05-18 09:09:50 +00:00
|
|
|
int bytes_read;
|
1999-08-02 02:26:22 +00:00
|
|
|
struct tm tm;
|
1999-09-01 23:53:58 +00:00
|
|
|
char fcs[2];
|
1999-08-02 02:26:22 +00:00
|
|
|
|
1999-09-01 23:53:58 +00:00
|
|
|
/* 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 = radcom_read_rec_header(wth->fh, &hdr, err);
|
|
|
|
if (ret <= 0) {
|
|
|
|
/* Read error or EOF */
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1999-08-02 02:26:22 +00:00
|
|
|
}
|
1999-09-01 23:53:58 +00:00
|
|
|
wth->data_offset += sizeof hdr;
|
|
|
|
length = pletohs(&hdr.length);
|
2000-09-07 05:34:23 +00:00
|
|
|
if (length == 0) return FALSE;
|
1999-08-02 02:26:22 +00:00
|
|
|
|
Have the per-capture-file-type open routines "wtap_open_offline()" calls
return 1 on success, -1 if they got an error, and 0 if the file isn't of
the type that file is checking for, and supply an error code if they
return -1; have "wtap_open_offline()" use that error code. Also, have
the per-capture-file-type open routines treat errors accessing the file
as errors, and return -1, rather than just returning 0 so that we try
another file type.
Have the per-capture-file-type read routines "wtap_loop()" calls return
-1 and supply an error code on error (and not, as they did in some
cases, call "g_error()" and abort), and have "wtap_loop()", if the read
routine returned an error, return FALSE (and pass an error-code-pointer
argument onto the read routines, so they fill it in), and return TRUE on
success.
Add some new error codes for them to return.
Now that "wtap_loop()" can return a success/failure indication and an
error code, in "read_cap_file()" put up a message box if we get an error
reading the file, and return the error code.
Handle the additional errors we can get when opening a capture file.
If the attempt to open a capture file succeeds, but the attempt to read
it fails, don't treat that as a complete failure - we may have managed
to read some of the capture file, and we should display what we managed
to read.
svn path=/trunk/; revision=516
1999-08-19 05:31:38 +00:00
|
|
|
if (wth->file_encap == WTAP_ENCAP_LAPB)
|
|
|
|
length -= 2; /* FCS */
|
1999-08-02 02:26:22 +00:00
|
|
|
|
|
|
|
wth->phdr.len = length;
|
|
|
|
wth->phdr.caplen = length;
|
|
|
|
|
1999-09-01 23:53:58 +00:00
|
|
|
tm.tm_year = pletohs(&hdr.date.year)-1900;
|
|
|
|
tm.tm_mon = hdr.date.month-1;
|
|
|
|
tm.tm_mday = hdr.date.day;
|
|
|
|
sec = pletohl(&hdr.date.sec);
|
1999-08-31 00:25:19 +00:00
|
|
|
tm.tm_hour = sec/3600;
|
|
|
|
tm.tm_min = (sec%3600)/60;
|
|
|
|
tm.tm_sec = sec%60;
|
1999-08-02 02:26:22 +00:00
|
|
|
tm.tm_isdst = -1;
|
|
|
|
wth->phdr.ts.tv_sec = mktime(&tm);
|
1999-09-01 23:53:58 +00:00
|
|
|
wth->phdr.ts.tv_usec = pletohl(&hdr.date.usec);
|
2002-04-09 08:15:04 +00:00
|
|
|
wth->pseudo_header.x25.flags = (hdr.dce & 0x1) ? 0x00 : FROM_DCE;
|
1999-08-02 02:26:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
|
|
|
buffer_assure_space(wth->frame_buffer, length);
|
2002-03-05 08:40:27 +00:00
|
|
|
if (!radcom_read_rec_data(wth->fh,
|
|
|
|
buffer_start_ptr(wth->frame_buffer), length, err))
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE; /* Read error */
|
1999-08-28 01:19:45 +00:00
|
|
|
wth->data_offset += length;
|
1999-08-02 02:26:22 +00:00
|
|
|
|
|
|
|
wth->phdr.pkt_encap = wth->file_encap;
|
|
|
|
|
1999-08-28 01:19:45 +00:00
|
|
|
if (wth->file_encap == WTAP_ENCAP_LAPB) {
|
1999-09-01 23:53:58 +00:00
|
|
|
/* Read the FCS.
|
|
|
|
XXX - should we put it in the pseudo-header? */
|
|
|
|
errno = WTAP_ERR_CANT_READ;
|
1999-09-22 01:26:50 +00:00
|
|
|
bytes_read = file_read(&fcs, 1, sizeof fcs, wth->fh);
|
1999-09-01 23:53:58 +00:00
|
|
|
if (bytes_read != sizeof fcs) {
|
1999-10-05 07:06:08 +00:00
|
|
|
*err = file_error(wth->fh);
|
|
|
|
if (*err == 0)
|
1999-09-01 23:53:58 +00:00
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1999-09-01 23:53:58 +00:00
|
|
|
}
|
|
|
|
wth->data_offset += sizeof fcs;
|
1999-08-28 01:19:45 +00:00
|
|
|
}
|
1999-08-02 02:26:22 +00:00
|
|
|
|
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
|
|
|
radcom_seek_read(wtap *wth, long seek_off,
|
2002-07-29 06:09:59 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct radcomrec_hdr hdr;
|
|
|
|
|
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. */
|
2002-03-05 05:58:41 +00:00
|
|
|
ret = radcom_read_rec_header(wth->random_fh, &hdr, err);
|
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
|
|
|
}
|
|
|
|
|
2002-04-09 08:15:04 +00:00
|
|
|
pseudo_header->x25.flags = (hdr.dce & 0x1) ? 0x00 : FROM_DCE;
|
2000-05-18 09:09:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the packet data.
|
|
|
|
*/
|
2002-03-05 05:58:41 +00:00
|
|
|
return radcom_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
|
|
|
radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
errno = WTAP_ERR_CANT_READ;
|
|
|
|
bytes_read = file_read(hdr, 1, sizeof *hdr, fh);
|
|
|
|
if (bytes_read != sizeof *hdr) {
|
|
|
|
*err = file_error(fh);
|
|
|
|
if (*err != 0)
|
|
|
|
return -1;
|
|
|
|
if (bytes_read != 0) {
|
|
|
|
*err = WTAP_ERR_SHORT_READ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean
|
2002-07-29 06:09:59 +00:00
|
|
|
radcom_read_rec_data(FILE_T fh, guchar *pd, int length, int *err)
|
2000-05-18 09:09:50 +00:00
|
|
|
{
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
errno = WTAP_ERR_CANT_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-08-02 02:26:22 +00:00
|
|
|
}
|