Check for errors in seeks, "tell"s, and "stat()"s/"fstat()"s.

For file types where we allocate private data, add "close" routines
where they were missing, to free the private data.  Also fix up the code
to clean up after some errors by freeing private data where that wasn't
being done.

Get rid of unused arguments to "wtap_dump_open_finish()".

Fix indentation.

svn path=/trunk/; revision=4857
This commit is contained in:
Guy Harris 2002-03-04 00:25:35 +00:00
parent 7fef8be5ec
commit d54bd0bd6b
17 changed files with 424 additions and 162 deletions

View File

@ -1,6 +1,6 @@
/* ascend.c /* ascend.c
* *
* $Id: ascend.c,v 1.26 2001/11/13 23:55:43 gram Exp $ * $Id: ascend.c,v 1.27 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -29,6 +29,8 @@
#include "ascend-int.h" #include "ascend-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
#include <errno.h>
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
@ -112,8 +114,7 @@ static void ascend_close(wtap *wth);
it sets "wth->capture.ascend->next_packet_seek_start" to the point it sets "wth->capture.ascend->next_packet_seek_start" to the point
at which the seek pointer should be set before this routine is called at which the seek pointer should be set before this routine is called
to find the packet *after* the packet it finds. */ to find the packet *after* the packet it finds. */
/* XXX - Handle I/O errors. */ static long ascend_seek(wtap *wth, int max_seek, int *err)
static long ascend_seek(wtap *wth, int max_seek)
{ {
int byte, bytes_read = 0; int byte, bytes_read = 0;
long date_off = -1, cur_off, packet_off; long date_off = -1, cur_off, packet_off;
@ -125,6 +126,11 @@ static long ascend_seek(wtap *wth, int max_seek)
if (x_level >= ASCEND_X_SIZE) { if (x_level >= ASCEND_X_SIZE) {
/* At what offset are we now? */ /* At what offset are we now? */
cur_off = file_tell(wth->fh); cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
/* Back up over the header we just read; that's where a read /* Back up over the header we just read; that's where a read
of this packet should start. */ of this packet should start. */
@ -139,6 +145,11 @@ static long ascend_seek(wtap *wth, int max_seek)
if (r_level >= ASCEND_R_SIZE) { if (r_level >= ASCEND_R_SIZE) {
/* At what offset are we now? */ /* At what offset are we now? */
cur_off = file_tell(wth->fh); cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
/* Back up over the header we just read; that's where a read /* Back up over the header we just read; that's where a read
of this packet should start. */ of this packet should start. */
@ -152,7 +163,14 @@ static long ascend_seek(wtap *wth, int max_seek)
w1_level++; w1_level++;
if (w1_level >= ASCEND_W1_SIZE) { if (w1_level >= ASCEND_W1_SIZE) {
/* Get the offset at which the "Date:" header started. */ /* Get the offset at which the "Date:" header started. */
date_off = file_tell(wth->fh) - ASCEND_W1_SIZE; cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
date_off = cur_off - ASCEND_W1_SIZE;
} }
} else { } else {
w1_level = 0; w1_level = 0;
@ -162,6 +180,12 @@ static long ascend_seek(wtap *wth, int max_seek)
if (w2_level >= ASCEND_W2_SIZE) { if (w2_level >= ASCEND_W2_SIZE) {
/* At what offset are we now? */ /* At what offset are we now? */
cur_off = file_tell(wth->fh); cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
if (date_off != -1) { if (date_off != -1) {
/* This packet has a date/time header; a read of it should /* This packet has a date/time header; a read of it should
start at the beginning of *that* header. */ start at the beginning of *that* header. */
@ -179,6 +203,14 @@ static long ascend_seek(wtap *wth, int max_seek)
} }
bytes_read++; bytes_read++;
} }
if (byte != EOF || file_eof(wth->fh)) {
/* Either we didn't find the offset, or we got an EOF. */
*err = 0;
} else {
/* We (presumably) got an error (there's no equivalent to "ferror()"
in zlib, alas, so we don't have a wrapper to check for an error). */
*err = file_error(wth->fh);
}
return -1; return -1;
found: found:
@ -195,11 +227,13 @@ found:
* Move to where the read for this packet should start, and return * Move to where the read for this packet should start, and return
* that seek offset. * that seek offset.
*/ */
file_seek(wth->fh, packet_off, SEEK_SET); if (file_seek(wth->fh, packet_off, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
return packet_off; return packet_off;
} }
/* XXX - return -1 on I/O error and actually do something with 'err'. */
int ascend_open(wtap *wth, int *err) int ascend_open(wtap *wth, int *err)
{ {
long offset; long offset;
@ -210,9 +244,12 @@ int ascend_open(wtap *wth, int *err)
fill it in. */ fill it in. */
wth->capture.ascend = NULL; wth->capture.ascend = NULL;
offset = ascend_seek(wth, ASCEND_MAX_SEEK); offset = ascend_seek(wth, ASCEND_MAX_SEEK, err);
if (offset == -1) { if (offset == -1) {
return 0; if (*err == 0)
return 0;
else
return -1;
} }
wth->data_offset = offset; wth->data_offset = offset;
@ -234,7 +271,11 @@ int ascend_open(wtap *wth, int *err)
packet's timestamp from the capture file's ctime, which gives us an packet's timestamp from the capture file's ctime, which gives us an
offset that we can apply to each packet. offset that we can apply to each packet.
*/ */
fstat(wtap_fd(wth), &statbuf); if (fstat(wtap_fd(wth), &statbuf) == -1) {
*err = errno;
g_free(wth->capture.ascend);
return -1;
}
wth->capture.ascend->inittime = statbuf.st_ctime; wth->capture.ascend->inittime = statbuf.st_ctime;
wth->capture.ascend->adjusted = 0; wth->capture.ascend->adjusted = 0;
@ -254,12 +295,14 @@ static gboolean ascend_read(wtap *wth, int *err, long *data_offset)
give us the correct location of the packet. Instead, we seek to the give us the correct location of the packet. Instead, we seek to the
offset after the header of the previous packet and try to find the next offset after the header of the previous packet and try to find the next
packet. */ packet. */
file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start, SEEK_SET); if (file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start,
offset = ascend_seek(wth, ASCEND_MAX_SEEK); SEEK_SET) == -1) {
if (offset == -1) { *err = file_error(wth->fh);
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE; return FALSE;
} }
offset = ascend_seek(wth, ASCEND_MAX_SEEK, err);
if (offset == -1)
return FALSE;
if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) { if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) {
*err = WTAP_ERR_BAD_RECORD; *err = WTAP_ERR_BAD_RECORD;
return FALSE; return FALSE;

View File

@ -1,6 +1,6 @@
/* csids.c /* csids.c
* *
* $Id: csids.c,v 1.10 2002/03/02 20:41:07 guy Exp $ * $Id: csids.c,v 1.11 2002/03/04 00:25:35 guy Exp $
* *
* Copyright (c) 2000 by Mike Hall <mlh@io.com> * Copyright (c) 2000 by Mike Hall <mlh@io.com>
* Copyright (c) 2000 by Cisco Systems * Copyright (c) 2000 by Cisco Systems
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -40,13 +40,14 @@
* of data following for that packet. * of data following for that packet.
* *
* For a time there was an error in iplogging and the ip length, flags, and id * For a time there was an error in iplogging and the ip length, flags, and id
* were byteswapped. We will check for this and handle it before handing to ethereal. * were byteswapped. We will check for this and handle it before handing to
* * ethereal.
*/ */
static gboolean csids_read(wtap *wth, int *err, long *data_offset); static gboolean csids_read(wtap *wth, int *err, long *data_offset);
static int csids_seek_read(wtap *wth, long seek_off, static int csids_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
static void csids_close(wtap *wth);
struct csids_header { struct csids_header {
guint32 seconds; /* seconds since epoch */ guint32 seconds; /* seconds since epoch */
@ -122,17 +123,21 @@ int csids_open(wtap *wth, int *err)
byteswap = FALSE; byteswap = FALSE;
} }
/* no file header. So reset the fh to 0 so we can read the first packet */
if (file_seek(wth->fh, 0, SEEK_SET) == -1) {
*err = file_error( wth->fh );
return -1;
}
wth->data_offset = 0; wth->data_offset = 0;
wth->capture.csids = g_malloc(sizeof(csids_t)); wth->capture.csids = g_malloc(sizeof(csids_t));
wth->capture.csids->byteswapped = byteswap; wth->capture.csids->byteswapped = byteswap;
wth->file_encap = WTAP_ENCAP_RAW_IP; wth->file_encap = WTAP_ENCAP_RAW_IP;
wth->file_type = WTAP_FILE_CSIDS; wth->file_type = WTAP_FILE_CSIDS;
wth->snapshot_length = 0; /* not known */ wth->snapshot_length = 0; /* not known */
wth->subtype_read = csids_read; wth->subtype_read = csids_read;
wth->subtype_seek_read = csids_seek_read; wth->subtype_seek_read = csids_seek_read;
wth->subtype_close = csids_close;
/* no file header. So reset the fh to 0 so we can read the first packet */
file_seek(wth->fh, 0, SEEK_SET);
return 1; return 1;
} }
@ -242,5 +247,8 @@ csids_seek_read (wtap *wth,
return 0; return 0;
} }
static void
csids_close(wtap *wth)
{
g_free(wth->capture.csids);
}

View File

@ -1,6 +1,6 @@
/* dbs-etherwatch.c /* dbs-etherwatch.c
* *
* $Id: dbs-etherwatch.c,v 1.4 2002/03/02 20:41:07 guy Exp $ * $Id: dbs-etherwatch.c,v 1.5 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com> * Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -43,14 +43,14 @@ ETHERWATCH X5-008
42 names and addresses were loaded 42 names and addresses were loaded
Reading recorded data from PERSISTENCE Reading recorded data from PERSISTENCE
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
>From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB] From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
Protocol 08-00 00 00-00-00-00-00, 60 byte buffer at 10-OCT-2001 10:20:45.16 Protocol 08-00 00 00-00-00-00-00, 60 byte buffer at 10-OCT-2001 10:20:45.16
[E..<8.....Ò.....]- 0-[45 00 00 3C 38 93 00 00 1D 06 D2 12 80 93 11 1A] [E..<8.....Ò.....]- 0-[45 00 00 3C 38 93 00 00 1D 06 D2 12 80 93 11 1A]
[...Ö.Ò...(¤.....]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 90 00 00 00 00] [...Ö.Ò...(¤.....]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 90 00 00 00 00]
[.....½.....´....]- 32-[A0 02 FF FF 95 BD 00 00 02 04 05 B4 03 03 04 01] [.....½.....´....]- 32-[A0 02 FF FF 95 BD 00 00 02 04 05 B4 03 03 04 01]
[......å..... ]- 48-[01 01 08 0A 90 90 E5 14 00 00 00 00] [......å..... ]- 48-[01 01 08 0A 90 90 E5 14 00 00 00 00]
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
>From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB] From 00-D0-C0-D2-4D-60 [MF1] to AA-00-04-00-FC-94 [PSERVB]
Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17 Protocol 08-00 00 00-00-00-00-00, 50 byte buffer at 10-OCT-2001 10:20:45.17
[E..(8.....Ò%....]- 0-[45 00 00 28 38 94 00 00 1D 06 D2 25 80 93 11 1A] [E..(8.....Ò%....]- 0-[45 00 00 28 38 94 00 00 1D 06 D2 25 80 93 11 1A]
[...Ö.Ò...(¤.Z.4w]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 91 5A 1C 34 77] [...Ö.Ò...(¤.Z.4w]- 16-[80 93 80 D6 02 D2 02 03 00 28 A4 91 5A 1C 34 77]
@ -84,24 +84,38 @@ static int parse_dbs_etherwatch_rec_hdr(wtap *wth, FILE_T fh, int *err);
/* Seeks to the beginning of the next packet, and returns the /* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure. */ byte offset. Returns -1 on failure, and sets "*err" to the error. */
/* XXX - Handle I/O errors. */ static long dbs_etherwatch_seek_next_packet(wtap *wth, int *err)
static long dbs_etherwatch_seek_next_packet(wtap *wth)
{ {
int byte; int byte;
unsigned int level = 0; unsigned int level = 0;
long cur_off;
while ((byte = file_getc(wth->fh)) != EOF) { while ((byte = file_getc(wth->fh)) != EOF) {
if (byte == dbs_etherwatch_rec_magic[level]) { if (byte == dbs_etherwatch_rec_magic[level]) {
level++; level++;
if (level >= DBS_ETHERWATCH_REC_MAGIC_SIZE) { if (level >= DBS_ETHERWATCH_REC_MAGIC_SIZE) {
/* note: we're leaving file pointer right after the magic characters */ /* note: we're leaving file pointer right after the magic characters */
return file_tell(wth->fh) + 1; cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
return cur_off + 1;
} }
} else { } else {
level = 0; level = 0;
} }
} }
if (file_eof(wth->fh)) {
/* We got an EOF. */
*err = 0;
} else {
/* We (presumably) got an error (there's no equivalent to "ferror()"
in zlib, alas, so we don't have a wrapper to check for an error). */
*err = file_error(wth->fh);
}
return -1; return -1;
} }
@ -111,9 +125,10 @@ static long dbs_etherwatch_seek_next_packet(wtap *wth)
/* Look through the first part of a file to see if this is /* Look through the first part of a file to see if this is
* a DBS Ethertrace text trace file. * a DBS Ethertrace text trace file.
* *
* Returns TRUE if it is, FALSE if it isn't. * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
* if we get an I/O error, "*err" will be set to a non-zero value.
*/ */
static gboolean dbs_etherwatch_check_file_type(wtap *wth) static gboolean dbs_etherwatch_check_file_type(wtap *wth, int *err)
{ {
char buf[DBS_ETHERWATCH_LINE_LENGTH]; char buf[DBS_ETHERWATCH_LINE_LENGTH];
int line, byte; int line, byte;
@ -142,19 +157,28 @@ static gboolean dbs_etherwatch_check_file_type(wtap *wth)
level = 0; level = 0;
} }
} }
else else {
/* EOF or error. */
if (file_eof(wth->fh))
*err = 0;
else
*err = file_error(wth->fh);
return FALSE; return FALSE;
}
} }
*err = 0;
return FALSE; return FALSE;
} }
/* XXX - return -1 on I/O error and actually do something with 'err'. */
int dbs_etherwatch_open(wtap *wth, int *err) int dbs_etherwatch_open(wtap *wth, int *err)
{ {
/* Look for DBS ETHERWATCH header */ /* Look for DBS ETHERWATCH header */
if (!dbs_etherwatch_check_file_type(wth)) { if (!dbs_etherwatch_check_file_type(wth, err)) {
return 0; if (*err == 0)
return 0;
else
return -1;
} }
wth->data_offset = 0; wth->data_offset = 0;
@ -175,11 +199,9 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, long *data_offset)
int pkt_len; int pkt_len;
/* Find the next packet */ /* Find the next packet */
offset = dbs_etherwatch_seek_next_packet(wth); offset = dbs_etherwatch_seek_next_packet(wth, err);
if (offset < 1) { if (offset < 1)
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE; return FALSE;
}
/* Parse the header */ /* Parse the header */
pkt_len = parse_dbs_etherwatch_rec_hdr(wth, wth->fh, err); pkt_len = parse_dbs_etherwatch_rec_hdr(wth, wth->fh, err);

View File

@ -1,6 +1,6 @@
/* file.c /* file.c
* *
* $Id: file.c,v 1.82 2002/03/02 20:41:07 guy Exp $ * $Id: file.c,v 1.83 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -227,7 +227,15 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
to start reading at the beginning. to start reading at the beginning.
Initialize the data offset while we're at it. */ Initialize the data offset while we're at it. */
file_seek(wth->fh, 0, SEEK_SET); if (file_seek(wth->fh, 0, SEEK_SET) == -1) {
/* I/O error - give up */
*err = file_error(wth->fh);
if (wth->random_fh != NULL)
file_close(wth->random_fh);
file_close(wth->fh);
g_free(wth);
return NULL;
}
wth->data_offset = 0; wth->data_offset = 0;
switch ((*open_routines[i])(wth, err)) { switch ((*open_routines[i])(wth, err)) {
@ -451,8 +459,7 @@ gboolean wtap_dump_can_write_encap(int filetype, int encap)
static gboolean wtap_dump_open_check(int filetype, int encap, int *err); static gboolean wtap_dump_open_check(int filetype, int encap, int *err);
static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen, static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen,
int *err); int *err);
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, int *err);
int encap, int snaplen, int *err);
wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap, wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
int snaplen, int *err) int snaplen, int *err)
@ -480,7 +487,7 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
} }
wdh->fh = fh; wdh->fh = fh;
if (!wtap_dump_open_finish(wdh, filetype, encap, snaplen, err)) { if (!wtap_dump_open_finish(wdh, filetype, err)) {
/* Get rid of the file we created; we couldn't finish /* Get rid of the file we created; we couldn't finish
opening it. */ opening it. */
unlink(filename); unlink(filename);
@ -515,7 +522,7 @@ wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen,
} }
wdh->fh = fh; wdh->fh = fh;
if (!wtap_dump_open_finish(wdh, filetype, encap, snaplen, err)) if (!wtap_dump_open_finish(wdh, filetype, err))
return NULL; return NULL;
return wdh; return wdh;
} }
@ -559,8 +566,7 @@ static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen,
return wdh; return wdh;
} }
static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, int *err)
int encap, int snaplen, int *err)
{ {
/* Now try to open the file for writing. */ /* Now try to open the file for writing. */
if (!(*dump_open_table[filetype].dump_open)(wdh, err)) { if (!(*dump_open_table[filetype].dump_open)(wdh, err)) {

View File

@ -1,6 +1,6 @@
/* file_wrappers.h /* file_wrappers.h
* *
* $Id: file_wrappers.h,v 1.7 2002/02/06 09:58:30 guy Exp $ * $Id: file_wrappers.h,v 1.8 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -25,6 +25,7 @@
#define __FILE_H__ #define __FILE_H__
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#define file_open gzopen #define file_open gzopen
#define filed_open gzdopen #define filed_open gzdopen
extern long file_seek(void *stream, long offset, int whence); extern long file_seek(void *stream, long offset, int whence);
@ -35,6 +36,7 @@ extern long file_tell(void *stream);
#define file_getc gzgetc #define file_getc gzgetc
#define file_gets(buf, len, file) gzgets((file), (buf), (len)) #define file_gets(buf, len, file) gzgets((file), (buf), (len))
extern int file_error(void *fh); extern int file_error(void *fh);
#define file_eof gzeof
#else /* No zLib */ #else /* No zLib */
#define file_open fopen #define file_open fopen
@ -47,6 +49,8 @@ extern int file_error(FILE *fh);
#define file_tell ftell #define file_tell ftell
#define file_getc fgetc #define file_getc fgetc
#define file_gets fgets #define file_gets fgets
#define file_eof feof
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#endif /* __FILE_H__ */ #endif /* __FILE_H__ */

View File

@ -1,6 +1,6 @@
/* i4btrace.c /* i4btrace.c
* *
* $Id: i4btrace.c,v 1.16 2002/02/08 10:07:40 guy Exp $ * $Id: i4btrace.c,v 1.17 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org> * Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -40,6 +40,7 @@ static void i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr);
static int i4b_read_rec_data(FILE_T fh, u_char *pd, int length, int *err); static int i4b_read_rec_data(FILE_T fh, u_char *pd, int length, int *err);
static void i4b_set_pseudo_header(wtap *wth, i4b_trace_hdr_t *hdr, static void i4b_set_pseudo_header(wtap *wth, i4b_trace_hdr_t *hdr,
union wtap_pseudo_header *pseudo_header); union wtap_pseudo_header *pseudo_header);
static void i4btrace_close(wtap *wth);
/* /*
* Test some fields in the header to see if they make sense. * Test some fields in the header to see if they make sense.
@ -89,7 +90,10 @@ int i4btrace_open(wtap *wth, int *err)
byte_swapped = TRUE; byte_swapped = TRUE;
} }
file_seek(wth->fh, 0, SEEK_SET); if (file_seek(wth->fh, 0, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset = 0; wth->data_offset = 0;
/* Get capture start time */ /* Get capture start time */
@ -98,6 +102,7 @@ int i4btrace_open(wtap *wth, int *err)
wth->capture.i4btrace = g_malloc(sizeof(i4btrace_t)); wth->capture.i4btrace = g_malloc(sizeof(i4btrace_t));
wth->subtype_read = i4btrace_read; wth->subtype_read = i4btrace_read;
wth->subtype_seek_read = i4btrace_seek_read; wth->subtype_seek_read = i4btrace_seek_read;
wth->subtype_close = i4btrace_close;
wth->snapshot_length = 0; /* not known */ wth->snapshot_length = 0; /* not known */
wth->capture.i4btrace->bchannel_prot[0] = -1; wth->capture.i4btrace->bchannel_prot[0] = -1;
@ -332,3 +337,9 @@ i4b_set_pseudo_header(wtap *wth, i4b_trace_hdr_t *hdr,
break; break;
} }
} }
static void
i4btrace_close(wtap *wth)
{
g_free(wth->capture.i4btrace);
}

View File

@ -1,6 +1,6 @@
/* lanalyzer.c /* lanalyzer.c
* *
* $Id: lanalyzer.c,v 1.30 2001/11/13 23:55:43 gram Exp $ * $Id: lanalyzer.c,v 1.31 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -90,7 +90,11 @@ int lanalyzer_open(wtap *wth, int *err)
/* Read records until we find the start of packets */ /* Read records until we find the start of packets */
while (1) { while (1) {
file_seek(wth->fh, record_length, SEEK_CUR); if (file_seek(wth->fh, record_length, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.lanalyzer);
return -1;
}
wth->data_offset += record_length; wth->data_offset += record_length;
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(LE_record_type, 1, 2, wth->fh); bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
@ -180,7 +184,11 @@ int lanalyzer_open(wtap *wth, int *err)
case REC_TRACE_PACKET_DATA: case REC_TRACE_PACKET_DATA:
/* Go back header number ob ytes so that lanalyzer_read /* Go back header number ob ytes so that lanalyzer_read
* can read this header */ * can read this header */
file_seek(wth->fh, -bytes_read, SEEK_CUR); if (file_seek(wth->fh, -bytes_read, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.lanalyzer);
return -1;
}
wth->data_offset -= bytes_read; wth->data_offset -= bytes_read;
return 1; return 1;

View File

@ -1,6 +1,6 @@
/* libpcap.c /* libpcap.c
* *
* $Id: libpcap.c,v 1.67 2002/03/02 20:41:07 guy Exp $ * $Id: libpcap.c,v 1.68 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -38,7 +38,6 @@
#define BIT_SWAPPED_MAC_ADDRS #define BIT_SWAPPED_MAC_ADDRS
#endif #endif
/* Try to read the first two records of the capture file. */ /* Try to read the first two records of the capture file. */
typedef enum { typedef enum {
THIS_FORMAT, /* the reads succeeded, assume it's this format */ THIS_FORMAT, /* the reads succeeded, assume it's this format */
@ -594,6 +593,7 @@ int libpcap_open(wtap *wth, int *err)
* Well, we couldn't even read it. * Well, we couldn't even read it.
* Give up. * Give up.
*/ */
g_free(wth->capture.pcap);
return -1; return -1;
case THIS_FORMAT: case THIS_FORMAT:
@ -601,7 +601,11 @@ int libpcap_open(wtap *wth, int *err)
* Well, it looks as if it might be 991029. * Well, it looks as if it might be 991029.
* Put the seek pointer back, and return success. * Put the seek pointer back, and return success.
*/ */
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
return 1; return 1;
case OTHER_FORMAT: case OTHER_FORMAT:
@ -619,7 +623,11 @@ int libpcap_open(wtap *wth, int *err)
* it as 990915. * it as 990915.
*/ */
wth->file_type = WTAP_FILE_PCAP_SS990915; wth->file_type = WTAP_FILE_PCAP_SS990915;
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
} else { } else {
/* /*
* Well, we have the standard magic number. * Well, we have the standard magic number.
@ -634,6 +642,7 @@ int libpcap_open(wtap *wth, int *err)
* Well, we couldn't even read it. * Well, we couldn't even read it.
* Give up. * Give up.
*/ */
g_free(wth->capture.pcap);
return -1; return -1;
case THIS_FORMAT: case THIS_FORMAT:
@ -642,7 +651,11 @@ int libpcap_open(wtap *wth, int *err)
* libpcap file. * libpcap file.
* Put the seek pointer back, and return success. * Put the seek pointer back, and return success.
*/ */
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
return 1; return 1;
case OTHER_FORMAT: case OTHER_FORMAT:
@ -658,7 +671,11 @@ int libpcap_open(wtap *wth, int *err)
* ss990417. * ss990417.
*/ */
wth->file_type = WTAP_FILE_PCAP_SS990417; wth->file_type = WTAP_FILE_PCAP_SS990417;
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
switch (libpcap_try(wth, err)) { switch (libpcap_try(wth, err)) {
case BAD_READ: case BAD_READ:
@ -666,6 +683,7 @@ int libpcap_open(wtap *wth, int *err)
* Well, we couldn't even read it. * Well, we couldn't even read it.
* Give up. * Give up.
*/ */
g_free(wth->capture.pcap);
return -1; return -1;
case THIS_FORMAT: case THIS_FORMAT:
@ -673,7 +691,11 @@ int libpcap_open(wtap *wth, int *err)
* Well, it looks as if it might be ss990417. * Well, it looks as if it might be ss990417.
* Put the seek pointer back, and return success. * Put the seek pointer back, and return success.
*/ */
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
return 1; return 1;
case OTHER_FORMAT: case OTHER_FORMAT:
@ -691,7 +713,11 @@ int libpcap_open(wtap *wth, int *err)
* and treat it as a Nokia file. * and treat it as a Nokia file.
*/ */
wth->file_type = WTAP_FILE_PCAP_NOKIA; wth->file_type = WTAP_FILE_PCAP_NOKIA;
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.pcap);
return -1;
}
} }
return 1; return 1;
@ -741,7 +767,10 @@ static libpcap_try_t libpcap_try(wtap *wth, int *err)
* Now skip over the first record's data, under the assumption * Now skip over the first record's data, under the assumption
* that the header is sane. * that the header is sane.
*/ */
file_seek(wth->fh, first_rec_hdr.hdr.incl_len, SEEK_CUR); if (file_seek(wth->fh, first_rec_hdr.hdr.incl_len, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return BAD_READ;
}
/* /*
* Now attempt to read the second record's header. * Now attempt to read the second record's header.

View File

@ -1,6 +1,6 @@
/* netmon.c /* netmon.c
* *
* $Id: netmon.c,v 1.48 2002/02/27 08:57:25 guy Exp $ * $Id: netmon.c,v 1.49 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -266,9 +266,13 @@ int netmon_open(wtap *wth, int *err)
*err = WTAP_ERR_UNSUPPORTED; *err = WTAP_ERR_UNSUPPORTED;
return -1; return -1;
} }
if (file_seek(wth->fh, frame_table_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.netmon);
return -1;
}
frame_table = g_malloc(frame_table_length); frame_table = g_malloc(frame_table_length);
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
file_seek(wth->fh, frame_table_offset, SEEK_SET);
bytes_read = file_read(frame_table, 1, frame_table_length, wth->fh); bytes_read = file_read(frame_table, 1, frame_table_length, wth->fh);
if ((guint32)bytes_read != frame_table_length) { if ((guint32)bytes_read != frame_table_length) {
*err = file_error(wth->fh); *err = file_error(wth->fh);
@ -327,7 +331,10 @@ static gboolean netmon_read(wtap *wth, int *err, long *data_offset)
rec_offset = netmon->frame_table[netmon->current_frame]; rec_offset = netmon->frame_table[netmon->current_frame];
if (wth->data_offset != rec_offset) { if (wth->data_offset != rec_offset) {
wth->data_offset = rec_offset; wth->data_offset = rec_offset;
file_seek(wth->fh, wth->data_offset, SEEK_SET); if (file_seek(wth->fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return FALSE;
}
} }
netmon->current_frame++; netmon->current_frame++;
@ -566,7 +573,10 @@ gboolean netmon_dump_open(wtap_dumper *wdh, int *err)
haven't yet written any packets. As we'll have to rewrite haven't yet written any packets. As we'll have to rewrite
the header when we've written out all the packets, we just the header when we've written out all the packets, we just
skip over the header for now. */ skip over the header for now. */
fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET); if (fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET) == -1) {
*err = errno;
return FALSE;
}
wdh->dump.netmon = g_malloc(sizeof(netmon_dump_t)); wdh->dump.netmon = g_malloc(sizeof(netmon_dump_t));
wdh->dump.netmon->frame_table_offset = CAPTUREFILE_HEADER_SIZE; wdh->dump.netmon->frame_table_offset = CAPTUREFILE_HEADER_SIZE;

View File

@ -1,6 +1,6 @@
/* nettl.c /* nettl.c
* *
* $Id: nettl.c,v 1.22 2002/02/08 10:07:40 guy Exp $ * $Id: nettl.c,v 1.23 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -95,17 +95,23 @@ int nettl_open(wtap *wth, int *err)
return 0; return 0;
} }
file_seek(wth->fh, 0x63, SEEK_SET); if (file_seek(wth->fh, 0x63, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset = 0x63; wth->data_offset = 0x63;
bytes_read = file_read(os_vers, 1, 2, wth->fh); bytes_read = file_read(os_vers, 1, 2, wth->fh);
if (bytes_read != 2) { if (bytes_read != 2) {
*err = file_error(wth->fh); *err = file_error(wth->fh);
if (*err != 0) if (*err != 0)
return -1; return -1;
return 0; return 0;
} }
file_seek(wth->fh, 0x80, SEEK_SET); if (file_seek(wth->fh, 0x80, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset = 0x80; wth->data_offset = 0x80;
/* This is an nettl file */ /* This is an nettl file */

View File

@ -1,6 +1,6 @@
/* netxray.c /* netxray.c
* *
* $Id: netxray.c,v 1.46 2002/03/02 20:41:07 guy Exp $ * $Id: netxray.c,v 1.47 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -224,7 +224,11 @@ int netxray_open(wtap *wth, int *err)
wth->capture.netxray->end_offset = pletohl(&hdr.end_offset); wth->capture.netxray->end_offset = pletohl(&hdr.end_offset);
/* Seek to the beginning of the data records. */ /* Seek to the beginning of the data records. */
file_seek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET); if (file_seek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET) == -1) {
*err = file_error(wth->fh);
g_free(wth->capture.netxray);
return -1;
}
wth->data_offset = pletohl(&hdr.start_offset); wth->data_offset = pletohl(&hdr.start_offset);
return 1; return 1;
@ -275,7 +279,11 @@ reread:
if (!wth->capture.netxray->wrapped) { if (!wth->capture.netxray->wrapped) {
/* Yes. Remember that we did. */ /* Yes. Remember that we did. */
wth->capture.netxray->wrapped = 1; wth->capture.netxray->wrapped = 1;
file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET); if (file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE,
SEEK_SET) == -1) {
*err = file_error(wth->fh);
return FALSE;
}
wth->data_offset = CAPTUREFILE_HEADER_SIZE; wth->data_offset = CAPTUREFILE_HEADER_SIZE;
goto reread; goto reread;
} }
@ -364,7 +372,10 @@ gboolean netxray_dump_open_1_1(wtap_dumper *wdh, int *err)
haven't yet written any packets. As we'll have to rewrite haven't yet written any packets. As we'll have to rewrite
the header when we've written out all the packets, we just the header when we've written out all the packets, we just
skip over the header for now. */ skip over the header for now. */
fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET); if (fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET) == -1) {
*err = errno;
return FALSE;
}
wdh->dump.netxray = g_malloc(sizeof(netxray_dump_t)); wdh->dump.netxray = g_malloc(sizeof(netxray_dump_t));
wdh->dump.netxray->first_frame = TRUE; wdh->dump.netxray->first_frame = TRUE;

View File

@ -1,6 +1,6 @@
/* ngsniffer.c /* ngsniffer.c
* *
* $Id: ngsniffer.c,v 1.73 2002/03/02 20:41:07 guy Exp $ * $Id: ngsniffer.c,v 1.74 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -316,8 +316,8 @@ static int ng_file_read(void *buffer, size_t elementsize, size_t numelements,
wtap *wth, gboolean is_random, int *err); wtap *wth, gboolean is_random, int *err);
static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream,
int *err); int *err);
static long ng_file_seek_seq(wtap *wth, long offset, int whence); static long ng_file_seek_seq(wtap *wth, long offset, int whence, int *err);
static long ng_file_seek_rand(wtap *wth, long offset, int whence); static long ng_file_seek_rand(wtap *wth, long offset, int whence, int *err);
int ngsniffer_open(wtap *wth, int *err) int ngsniffer_open(wtap *wth, int *err)
{ {
@ -456,8 +456,12 @@ int ngsniffer_open(wtap *wth, int *err)
* or REC_EOF after this? If not, we can get rid of the loop in * or REC_EOF after this? If not, we can get rid of the loop in
* "ngsniffer_read()". * "ngsniffer_read()".
*/ */
if (wth->random_fh != NULL) if (wth->random_fh != NULL) {
file_seek(wth->random_fh, wth->data_offset, SEEK_SET); if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET) == -1) {
*err = file_error(wth->random_fh);
return -1;
}
}
/* This is a ngsniffer file */ /* This is a ngsniffer file */
wth->capture.ngsniffer = g_malloc(sizeof(ngsniffer_t)); wth->capture.ngsniffer = g_malloc(sizeof(ngsniffer_t));
@ -559,7 +563,10 @@ skip_header_records(wtap *wth, int *err, gint16 version)
* which implies data. Seek backwards over the * which implies data. Seek backwards over the
* two bytes we read, and return. * two bytes we read, and return.
*/ */
file_seek(wth->fh, -2, SEEK_CUR); if (file_seek(wth->fh, -2, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
return 0; return 0;
} }
@ -603,8 +610,11 @@ skip_header_records(wtap *wth, int *err, gint16 version)
* Skip the rest of the record. * Skip the rest of the record.
*/ */
if (length > sizeof buffer) { if (length > sizeof buffer) {
file_seek(wth->fh, length - sizeof buffer, if (file_seek(wth->fh, length - sizeof buffer,
SEEK_CUR); SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
} }
/* /*
@ -637,7 +647,10 @@ skip_header_records(wtap *wth, int *err, gint16 version)
} else { } else {
/* Nope, just skip over the data. */ /* Nope, just skip over the data. */
file_seek(wth->fh, length, SEEK_CUR); if (file_seek(wth->fh, length, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
} }
wth->data_offset += length; wth->data_offset += length;
} }
@ -779,7 +792,8 @@ static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset)
* it is but can't handle it. Skip past the data * it is but can't handle it. Skip past the data
* portion, and keep looping. * portion, and keep looping.
*/ */
ng_file_seek_seq(wth, length, SEEK_CUR); if (ng_file_seek_seq(wth, length, SEEK_CUR, err) == -1)
return FALSE;
wth->data_offset += length; wth->data_offset += length;
} }
@ -867,7 +881,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off,
struct frame4_rec frame4; struct frame4_rec frame4;
struct frame6_rec frame6; struct frame6_rec frame6;
ng_file_seek_rand(wth, seek_off, SEEK_SET); ng_file_seek_rand(wth, seek_off, SEEK_SET, &err);
ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, &err); ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, &err);
if (ret <= 0) { if (ret <= 0) {
@ -1682,15 +1696,19 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err)
/* Seek in the sequential data stream; we can only seek forward, and we /* Seek in the sequential data stream; we can only seek forward, and we
do it on compressed files by skipping forward. */ do it on compressed files by skipping forward. */
static long static long
ng_file_seek_seq(wtap *wth, long offset, int whence) ng_file_seek_seq(wtap *wth, long offset, int whence, int *err)
{ {
long delta; long ret;
char buf[65536]; long delta;
long amount_to_read; char buf[65536];
int err; long amount_to_read;
if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
return file_seek(wth->fh, offset, whence); ret = file_seek(wth->fh, offset, whence);
if (ret == -1)
*err = file_error(wth->fh);
return ret;
}
switch (whence) { switch (whence) {
@ -1714,7 +1732,7 @@ ng_file_seek_seq(wtap *wth, long offset, int whence)
amount_to_read = delta; amount_to_read = delta;
if ((unsigned long)amount_to_read > sizeof buf) if ((unsigned long)amount_to_read > sizeof buf)
amount_to_read = sizeof buf; amount_to_read = sizeof buf;
if (ng_file_read(buf, 1, amount_to_read, wth, FALSE, &err) < 0) if (ng_file_read(buf, 1, amount_to_read, wth, FALSE, err) < 0)
return -1; /* error */ return -1; /* error */
delta -= amount_to_read; delta -= amount_to_read;
} }
@ -1730,16 +1748,20 @@ ng_file_seek_seq(wtap *wth, long offset, int whence)
position within the blob we have in memory (whether it's the blob we position within the blob we have in memory (whether it's the blob we
already had in memory or, if necessary, the one we read in). */ already had in memory or, if necessary, the one we read in). */
static long static long
ng_file_seek_rand(wtap *wth, long offset, int whence) ng_file_seek_rand(wtap *wth, long offset, int whence, int *err)
{ {
ngsniffer_t *ngsniffer; long ret;
long delta; ngsniffer_t *ngsniffer;
int err; long delta;
GList *new, *next; GList *new, *next;
blob_info_t *next_blob, *new_blob; blob_info_t *next_blob, *new_blob;
if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
return file_seek(wth->random_fh, offset, whence); ret = file_seek(wth->random_fh, offset, whence);
if (ret == -1)
*err = file_error(wth->random_fh);
return ret;
}
ngsniffer = wth->capture.ngsniffer; ngsniffer = wth->capture.ngsniffer;
@ -1814,8 +1836,10 @@ ng_file_seek_rand(wtap *wth, long offset, int whence)
/* Seek in the compressed file to the offset in the compressed file /* Seek in the compressed file to the offset in the compressed file
of the beginning of that blob. */ of the beginning of that blob. */
if (file_seek(wth->random_fh, new_blob->blob_comp_offset, SEEK_SET) == -1) if (file_seek(wth->random_fh, new_blob->blob_comp_offset, SEEK_SET) == -1) {
*err = file_error(wth->random_fh);
return -1; return -1;
}
/* Make the blob we found the current one. */ /* Make the blob we found the current one. */
ngsniffer->current_blob = new; ngsniffer->current_blob = new;
@ -1826,7 +1850,7 @@ ng_file_seek_rand(wtap *wth, long offset, int whence)
ngsniffer->rand.comp_offset = new_blob->blob_comp_offset; ngsniffer->rand.comp_offset = new_blob->blob_comp_offset;
/* Now fill the buffer. */ /* Now fill the buffer. */
if (read_blob(wth->random_fh, &ngsniffer->rand, &err) < 0) if (read_blob(wth->random_fh, &ngsniffer->rand, err) < 0)
return -1; return -1;
/* Set "delta" to the amount to move within this blob; it had /* Set "delta" to the amount to move within this blob; it had

View File

@ -1,6 +1,6 @@
/* pppdump.c /* pppdump.c
* *
* $Id: pppdump.c,v 1.14 2002/03/02 20:41:07 guy Exp $ * $Id: pppdump.c,v 1.15 2002/03/04 00:25:35 guy Exp $
* *
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
* *
@ -17,8 +17,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -195,6 +195,11 @@ pppdump_open(wtap *wth, int *err)
my_file_type: my_file_type:
if (file_seek(wth->fh, 5, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
state = wth->capture.generic = g_malloc(sizeof(pppdump_t)); state = wth->capture.generic = g_malloc(sizeof(pppdump_t));
state->timestamp = pntohl(&buffer[1]); state->timestamp = pntohl(&buffer[1]);
state->tenths = 0; state->tenths = 0;
@ -202,7 +207,6 @@ pppdump_open(wtap *wth, int *err)
init_state(state); init_state(state);
state->offset = 5; state->offset = 5;
file_seek(wth->fh, 5, SEEK_SET);
wth->file_encap = WTAP_ENCAP_PPP_WITH_PHDR; wth->file_encap = WTAP_ENCAP_PPP_WITH_PHDR;
wth->file_type = WTAP_FILE_PPPDUMP; wth->file_type = WTAP_FILE_PPPDUMP;
@ -589,10 +593,10 @@ pppdump_close(wtap *wth)
} }
if (state->pids) { /* should always be TRUE */ if (state->pids) { /* should always be TRUE */
unsigned int i; unsigned int i;
for (i = 0; i < g_ptr_array_len(state->pids); i++) { for (i = 0; i < g_ptr_array_len(state->pids); i++) {
g_free(g_ptr_array_index(state->pids, i)); g_free(g_ptr_array_index(state->pids, i));
} }
g_ptr_array_free(state->pids, TRUE); g_ptr_array_free(state->pids, TRUE);
} }

View File

@ -1,6 +1,6 @@
/* radcom.c /* radcom.c
* *
* $Id: radcom.c,v 1.32 2002/02/08 10:07:41 guy Exp $ * $Id: radcom.c,v 1.33 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -99,7 +99,10 @@ int radcom_open(wtap *wth, int *err)
return 0; return 0;
} }
file_seek(wth->fh, 0x8B, SEEK_SET); if (file_seek(wth->fh, 0x8B, SEEK_SET) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset = 0x8B; wth->data_offset = 0x8B;
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&byte, 1, 1, wth->fh); bytes_read = file_read(&byte, 1, 1, wth->fh);
@ -148,7 +151,10 @@ int radcom_open(wtap *wth, int *err)
tm.tm_sec = sec%60; tm.tm_sec = sec%60;
tm.tm_isdst = -1; tm.tm_isdst = -1;
file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR); if (file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset += sizeof(struct frame_date); wth->data_offset += sizeof(struct frame_date);
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
@ -158,7 +164,10 @@ int radcom_open(wtap *wth, int *err)
} }
wth->data_offset += 4; wth->data_offset += 4;
while (memcmp(encap_magic, search_encap, 4)) { while (memcmp(encap_magic, search_encap, 4)) {
file_seek(wth->fh, -3, SEEK_CUR); if (file_seek(wth->fh, -3, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset -= 3; wth->data_offset -= 3;
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(search_encap, 1, 4, wth->fh); bytes_read = file_read(search_encap, 1, 4, wth->fh);
@ -167,7 +176,10 @@ int radcom_open(wtap *wth, int *err)
} }
wth->data_offset += 4; wth->data_offset += 4;
} }
file_seek(wth->fh, 12, SEEK_CUR); if (file_seek(wth->fh, 12, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset += 12; wth->data_offset += 12;
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(search_encap, 1, 4, wth->fh); bytes_read = file_read(search_encap, 1, 4, wth->fh);
@ -192,7 +204,10 @@ int radcom_open(wtap *wth, int *err)
} }
while (memcmp(&start_date, &next_date, 4)) { while (memcmp(&start_date, &next_date, 4)) {
file_seek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR); if (file_seek(wth->fh, 1-sizeof(struct frame_date), SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
errno = WTAP_ERR_CANT_READ; errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&next_date, 1, sizeof(struct frame_date), bytes_read = file_read(&next_date, 1, sizeof(struct frame_date),
wth->fh); wth->fh);
@ -202,10 +217,16 @@ int radcom_open(wtap *wth, int *err)
}*/ }*/
if (wth->file_encap == WTAP_ENCAP_ETHERNET) { if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
file_seek(wth->fh, 294, SEEK_CUR); if (file_seek(wth->fh, 294, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset += 294; wth->data_offset += 294;
} else if (wth->file_encap == WTAP_ENCAP_LAPB) { } else if (wth->file_encap == WTAP_ENCAP_LAPB) {
file_seek(wth->fh, 297, SEEK_CUR); if (file_seek(wth->fh, 297, SEEK_CUR) == -1) {
*err = file_error(wth->fh);
return -1;
}
wth->data_offset += 297; wth->data_offset += 297;
} }

View File

@ -1,6 +1,6 @@
/* toshiba.c /* toshiba.c
* *
* $Id: toshiba.c,v 1.20 2002/02/08 10:07:41 guy Exp $ * $Id: toshiba.c,v 1.21 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -118,24 +118,38 @@ static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err); union wtap_pseudo_header *pseudo_header, int *err);
/* Seeks to the beginning of the next packet, and returns the /* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure. */ byte offset. Returns -1 on failure, and sets "*err" to the error. */
/* XXX - Handle I/O errors. */ static long toshiba_seek_next_packet(wtap *wth, int *err)
static long toshiba_seek_next_packet(wtap *wth)
{ {
int byte; int byte;
guint level = 0; guint level = 0;
long cur_off;
while ((byte = file_getc(wth->fh)) != EOF) { while ((byte = file_getc(wth->fh)) != EOF) {
if (byte == toshiba_rec_magic[level]) { if (byte == toshiba_rec_magic[level]) {
level++; level++;
if (level >= TOSHIBA_REC_MAGIC_SIZE) { if (level >= TOSHIBA_REC_MAGIC_SIZE) {
/* note: we're leaving file pointer right after the magic characters */ /* note: we're leaving file pointer right after the magic characters */
return file_tell(wth->fh) + 1; cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
return cur_off + 1;
} }
} else { } else {
level = 0; level = 0;
} }
} }
if (file_eof(wth->fh)) {
/* We got an EOF. */
*err = 0;
} else {
/* We (presumably) got an error (there's no equivalent to "ferror()"
in zlib, alas, so we don't have a wrapper to check for an error). */
*err = file_error(wth->fh);
}
return -1; return -1;
} }
@ -145,9 +159,10 @@ static long toshiba_seek_next_packet(wtap *wth)
/* Look through the first part of a file to see if this is /* Look through the first part of a file to see if this is
* a Toshiba trace file. * a Toshiba trace file.
* *
* Returns TRUE if it is, FALSE if it isn't. * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
* if we get an I/O error, "*err" will be set to a non-zero value.
*/ */
static gboolean toshiba_check_file_type(wtap *wth) static gboolean toshiba_check_file_type(wtap *wth, int *err)
{ {
char buf[TOSHIBA_LINE_LENGTH]; char buf[TOSHIBA_LINE_LENGTH];
guint i, reclen, level, line; guint i, reclen, level, line;
@ -178,19 +193,27 @@ static gboolean toshiba_check_file_type(wtap *wth)
} }
} }
else { else {
/* EOF or error. */
if (file_eof(wth->fh))
*err = 0;
else
*err = file_error(wth->fh);
return FALSE; return FALSE;
} }
} }
*err = 0;
return FALSE; return FALSE;
} }
/* XXX - return -1 on I/O error and actually do something with 'err'. */
int toshiba_open(wtap *wth, int *err) int toshiba_open(wtap *wth, int *err)
{ {
/* Look for Toshiba header */ /* Look for Toshiba header */
if (!toshiba_check_file_type(wth)) { if (!toshiba_check_file_type(wth, err)) {
return 0; if (*err == 0)
return 0;
else
return -1;
} }
wth->data_offset = 0; wth->data_offset = 0;
@ -211,11 +234,9 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset)
int pkt_len; int pkt_len;
/* Find the next packet */ /* Find the next packet */
offset = toshiba_seek_next_packet(wth); offset = toshiba_seek_next_packet(wth, err);
if (offset < 1) { if (offset < 1)
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE; return FALSE;
}
/* Parse the header */ /* Parse the header */
pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, pkt_len = parse_toshiba_rec_hdr(wth, wth->fh,

View File

@ -2,7 +2,7 @@
* File read and write routines for Visual Networks cap files. * File read and write routines for Visual Networks cap files.
* Copyright (c) 2001, Tom Nisbet tnisbet@visualnetworks.com * Copyright (c) 2001, Tom Nisbet tnisbet@visualnetworks.com
* *
* $Id: visual.c,v 1.2 2002/02/27 08:57:25 guy Exp $ * $Id: visual.c,v 1.3 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -421,7 +421,10 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err)
/* All of the fields in the file header aren't known yet so /* All of the fields in the file header aren't known yet so
just skip over it for now. It will be created after all just skip over it for now. It will be created after all
of the packets have been written. */ of the packets have been written. */
fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET); if (fseek(wdh->fh, CAPTUREFILE_HEADER_SIZE, SEEK_SET) == -1) {
*err = errno;
return FALSE;
}
return TRUE; return TRUE;
} }

View File

@ -1,6 +1,6 @@
/* vms.c /* vms.c
* *
* $Id: vms.c,v 1.7 2002/03/02 20:41:08 guy Exp $ * $Id: vms.c,v 1.8 2002/03/04 00:25:35 guy Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com> * Copyright (c) 2001 by Marc Milgram <mmilgram@arrayinc.com>
@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -80,12 +80,12 @@ static int parse_vms_rec_hdr(wtap *wth, FILE_T fh, int *err);
/* Seeks to the beginning of the next packet, and returns the /* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure. */ byte offset. Returns -1 on failure, and sets "*err" to the error. */
/* XXX - Handle I/O errors. */ static long vms_seek_next_packet(wtap *wth, int *err)
static long vms_seek_next_packet(wtap *wth)
{ {
int byte; int byte;
unsigned int level = 0; unsigned int level = 0;
long cur_off;
while ((byte = file_getc(wth->fh)) != EOF) { while ((byte = file_getc(wth->fh)) != EOF) {
if ((level == 3) && (byte != vms_rec_magic[level])) if ((level == 3) && (byte != vms_rec_magic[level]))
@ -93,13 +93,27 @@ static long vms_seek_next_packet(wtap *wth)
if (byte == vms_rec_magic[level]) { if (byte == vms_rec_magic[level]) {
level++; level++;
if (level >= VMS_REC_MAGIC_SIZE) { if (level >= VMS_REC_MAGIC_SIZE) {
/* note: we're leaving file pointer right after the magic characters */ /* note: we're leaving file pointer right after the magic characters */
return file_tell(wth->fh) + 1; cur_off = file_tell(wth->fh);
if (cur_off == -1) {
/* Error. */
*err = file_error(wth->fh);
return -1;
}
return cur_off + 1;
} }
} else { } else {
level = 0; level = 0;
} }
} }
if (file_eof(wth->fh)) {
/* We got an EOF. */
*err = 0;
} else {
/* We (presumably) got an error (there's no equivalent to "ferror()"
in zlib, alas, so we don't have a wrapper to check for an error). */
*err = file_error(wth->fh);
}
return -1; return -1;
} }
@ -109,12 +123,13 @@ static long vms_seek_next_packet(wtap *wth)
/* Look through the first part of a file to see if this is /* Look through the first part of a file to see if this is
* a VMS trace file. * a VMS trace file.
* *
* Returns TRUE if it is, FALSE if it isn't. * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
* if we get an I/O error, "*err" will be set to a non-zero value.
* *
* Leaves file handle at begining of line that contains the VMS Magic * Leaves file handle at begining of line that contains the VMS Magic
* identifier. * identifier.
*/ */
static gboolean vms_check_file_type(wtap *wth) static gboolean vms_check_file_type(wtap *wth, int *err)
{ {
char buf[VMS_LINE_LENGTH]; char buf[VMS_LINE_LENGTH];
int line, byte; int line, byte;
@ -125,6 +140,11 @@ static gboolean vms_check_file_type(wtap *wth)
for (line = 0; line < VMS_HEADER_LINES_TO_CHECK; line++) { for (line = 0; line < VMS_HEADER_LINES_TO_CHECK; line++) {
mpos = file_tell(wth->fh); mpos = file_tell(wth->fh);
if (mpos == -1) {
/* Error. */
*err = file_error(wth->fh);
return FALSE;
}
if (file_gets(buf, VMS_LINE_LENGTH, wth->fh) != NULL) { if (file_gets(buf, VMS_LINE_LENGTH, wth->fh) != NULL) {
reclen = strlen(buf); reclen = strlen(buf);
@ -139,7 +159,11 @@ static gboolean vms_check_file_type(wtap *wth)
if (byte == vms_hdr_magic[level]) { if (byte == vms_hdr_magic[level]) {
level++; level++;
if (level >= VMS_HDR_MAGIC_SIZE) { if (level >= VMS_HDR_MAGIC_SIZE) {
file_seek(wth->fh, mpos, SEEK_SET); if (file_seek(wth->fh, mpos, SEEK_SET) == -1) {
/* Error. */
*err = file_error(wth->fh);
return FALSE;
}
return TRUE; return TRUE;
} }
} }
@ -147,19 +171,28 @@ static gboolean vms_check_file_type(wtap *wth)
level = 0; level = 0;
} }
} }
else else {
/* EOF or error. */
if (file_eof(wth->fh))
*err = 0;
else
*err = file_error(wth->fh);
return FALSE; return FALSE;
}
} }
*err = 0;
return FALSE; return FALSE;
} }
/* XXX - return -1 on I/O error and actually do something with 'err'. */
int vms_open(wtap *wth, int *err) int vms_open(wtap *wth, int *err)
{ {
/* Look for VMS header */ /* Look for VMS header */
if (!vms_check_file_type(wth)) { if (!vms_check_file_type(wth, err)) {
return 0; if (*err == 0)
return 0;
else
return -1;
} }
wth->data_offset = 0; wth->data_offset = 0;
@ -180,11 +213,9 @@ static gboolean vms_read(wtap *wth, int *err, long *data_offset)
int pkt_len; int pkt_len;
/* Find the next packet */ /* Find the next packet */
offset = vms_seek_next_packet(wth); offset = vms_seek_next_packet(wth, err);
if (offset < 1) { if (offset < 1)
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE; return FALSE;
}
/* Parse the header */ /* Parse the header */
pkt_len = parse_vms_rec_hdr(wth, wth->fh, err); pkt_len = parse_vms_rec_hdr(wth, wth->fh, err);