aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-09-02 00:14:06 +0000
committerGuy Harris <guy@alum.mit.edu>1999-09-02 00:14:06 +0000
commitc135be4e5367ebb5763576900a4b08beead2fc91 (patch)
tree2c93eb9a0daf955a752110670933867d6d1f342e /wiretap
parentb87ec88778a35e86426ef25b7643ec23b937fe2c (diff)
When skipping over the padding at the end of a record in a capture file,
don't seek around it - some implementations of the standard I/O library routines (e.g., the ones in Solaris 2.5.1, at least) appear not to be clever enough to handle seeks that occur within the buffer by moving the current buffer position; instead, they do a seek on the underlying file descriptor *and* appear to throw out the buffer, forcing them to do another read. Instead, read it into a buffer. svn path=/trunk/; revision=626
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/snoop.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index 9b854146a3..8208b79e0f 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -1,6 +1,6 @@
/* snoop.c
*
- * $Id: snoop.c,v 1.9 1999/08/28 01:19:45 guy Exp $
+ * $Id: snoop.c,v 1.10 1999/09/02 00:14:06 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -136,6 +136,9 @@ static int snoop_read(wtap *wth, int *err)
int bytes_read;
struct snooprec_hdr hdr;
int data_offset;
+ char padbuf[4];
+ int padbytes;
+ int bytes_to_read;
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
@@ -185,10 +188,30 @@ static int snoop_read(wtap *wth, int *err)
wth->phdr.len = ntohl(hdr.orig_len);
wth->phdr.pkt_encap = wth->file_encap;
- /* Skip over the padding. */
- fseek(wth->fh, ntohl(hdr.rec_len) - (sizeof hdr + packet_size),
- SEEK_CUR);
- wth->data_offset += ntohl(hdr.rec_len) - (sizeof hdr + packet_size);
+ /*
+ * Skip over the padding (don't "fseek()", as the standard
+ * I/O library on some platforms discards buffered data if
+ * you do that, which means it does a lot more reads).
+ * There's probably not much padding (it's probably padded only
+ * to a 4-byte boundary), so we probably need only do one read.
+ */
+ padbytes = ntohl(hdr.rec_len) - (sizeof hdr + packet_size);
+ while (padbytes != 0) {
+ bytes_to_read = padbytes;
+ if (bytes_to_read > sizeof padbuf)
+ bytes_to_read = sizeof padbuf;
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = fread(padbuf, 1, bytes_to_read, wth->fh);
+ if (bytes_read != bytes_to_read) {
+ if (ferror(wth->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ wth->data_offset += bytes_read;
+ padbytes -= bytes_read;
+ }
return data_offset;
}