aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ngsniffer.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-03-05 05:58:41 +0000
committerGuy Harris <guy@alum.mit.edu>2002-03-05 05:58:41 +0000
commite300f4db52ddfcdfbf8a53d69d88e037365cb7a3 (patch)
treeedc94f3db1aa4b8d5dfc6192d153023fb32d9a0d /wiretap/ngsniffer.c
parenta7553a55864b398593c9e3c922d91ae804e0d732 (diff)
Have "wtap_seek_read()" return 0 on success and -1 on failure, and take
an "err" argument that points to an "int" into which to put an error code if it fails. Check for errors in one call to it, and note that we should do so in other places. In the "wtap_seek_read()" call in the TCP graphing code, don't overwrite "cfile.pseudo_header", and make the buffer into which we read the data WTAP_MAX_PACKET_SIZE bytes, as it should be. In some of the file readers for text files, check for errors from the "parse the record header" and "parse the hex dump" routines when reading sequentially. In "csids_seek_read()", fix some calls to "file_error()" to check the error on the random stream (that being what we're reading). svn path=/trunk/; revision=4874
Diffstat (limited to 'wiretap/ngsniffer.c')
-rw-r--r--wiretap/ngsniffer.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index 099058ac60..c0d1d9e6a6 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -1,6 +1,6 @@
/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.74 2002/03/04 00:25:35 guy Exp $
+ * $Id: ngsniffer.c,v 1.75 2002/03/05 05:58:40 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -286,7 +286,8 @@ static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 };
static int skip_header_records(wtap *wth, int *err, gint16 version);
static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset);
static int ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err);
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
guint16 *typep, guint16 *lengthp, int *err);
static int ngsniffer_read_frame2(wtap *wth, gboolean is_random,
@@ -872,28 +873,33 @@ found:
}
static int ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size)
+ union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ int *err)
{
int ret;
- int err; /* XXX - return this */
guint16 type, length;
struct frame2_rec frame2;
struct frame4_rec frame4;
struct frame6_rec frame6;
- ng_file_seek_rand(wth, seek_off, SEEK_SET, &err);
+ if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err) == -1)
+ return -1;
- ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, &err);
+ ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err);
if (ret <= 0) {
/* Read error or EOF */
- return ret;
+ if (ret == 0) {
+ /* EOF means "short read" in random-access mode */
+ *err = WTAP_ERR_SHORT_READ;
+ }
+ return -1;
}
switch (type) {
case REC_FRAME2:
/* Read the f_frame2_struct */
- ret = ngsniffer_read_frame2(wth, TRUE, &frame2, &err);
+ ret = ngsniffer_read_frame2(wth, TRUE, &frame2, err);
if (ret < 0) {
/* Read error */
return ret;
@@ -906,7 +912,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off,
case REC_FRAME4:
/* Read the f_frame4_struct */
- ret = ngsniffer_read_frame4(wth, TRUE, &frame4, &err);
+ ret = ngsniffer_read_frame4(wth, TRUE, &frame4, err);
length -= sizeof frame4; /* we already read that much */
@@ -915,7 +921,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off,
case REC_FRAME6:
/* Read the f_frame6_struct */
- ret = ngsniffer_read_frame6(wth, TRUE, &frame6, &err);
+ ret = ngsniffer_read_frame6(wth, TRUE, &frame6, err);
length -= sizeof frame6; /* we already read that much */
@@ -939,7 +945,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off,
/*
* Got the pseudo-header (if any), now get the data.
*/
- return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, &err);
+ return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err);
}
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,