summaryrefslogtreecommitdiff
path: root/wiretap/netxray.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-05-04 16:56:18 +0000
committerGuy Harris <guy@alum.mit.edu>2012-05-04 16:56:18 +0000
commit33bb54a9452f4be53377a185195a63194016241a (patch)
tree9308829e2105b6e51e0dc5cc0af2295d8d97a0a3 /wiretap/netxray.c
parentf65cb5f27bab6310e847f88cd763eb08bff1c93b (diff)
downloadwireshark-33bb54a9452f4be53377a185195a63194016241a.tar.gz
file_seek() used to be a wrapper around fseek() or gzseek(), both of
which could use lseek() and were thus expensive due to system call overhead. To avoid making a system call for every packet on a sequential read, we maintained a data_offset field in the wtap structure for sequential reads. It's now a routine that just returns information from the FILE_T data structure, so it's cheap. Use it, rather than maintaining the data_offset field. Readers for some file formats need to maintain file offset themselves; have them do so in their private data structures. svn path=/trunk/; revision=42423
Diffstat (limited to 'wiretap/netxray.c')
-rw-r--r--wiretap/netxray.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index 13178ba825..f2685e9001 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -387,7 +387,6 @@ int netxray_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof magic;
if (memcmp(magic, netxray_magic, sizeof magic) == 0) {
is_old = FALSE;
@@ -406,7 +405,6 @@ int netxray_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr;
if (is_old) {
version_major = 0;
@@ -901,11 +899,10 @@ int netxray_open(wtap *wth, int *err, gchar **err_info)
netxray->end_offset = pletohl(&hdr.end_offset);
/* Seek to the beginning of the data records. */
- if (file_seek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, netxray->start_offset, SEEK_SET, err) == -1) {
g_free(netxray);
return -1;
}
- wth->data_offset = pletohl(&hdr.start_offset);
return 1;
}
@@ -923,12 +920,19 @@ static gboolean netxray_read(wtap *wth, int *err, gchar **err_info,
guint padding;
reread:
+ /*
+ * Return the offset of the record header, so we can reread it
+ * if we go back to this frame.
+ */
+ *data_offset = file_tell(wth->fh);
+
/* Have we reached the end of the packet data? */
- if (wth->data_offset == netxray->end_offset) {
+ if (*data_offset == netxray->end_offset) {
/* Yes. */
*err = 0; /* it's just an EOF, not an error */
return FALSE;
}
+
/* Read record header. */
hdr_size = netxray_read_rec_header(wth, wth->fh, &hdr, err, err_info);
if (hdr_size == 0) {
@@ -973,7 +977,6 @@ reread:
if (file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE,
SEEK_SET, err) == -1)
return FALSE;
- wth->data_offset = CAPTUREFILE_HEADER_SIZE;
goto reread;
}
@@ -982,13 +985,6 @@ reread:
}
/*
- * Return the offset of the record header, so we can reread it
- * if we go back to this frame.
- */
- *data_offset = wth->data_offset;
- wth->data_offset += hdr_size;
-
- /*
* Read the packet data.
*/
if (netxray->version_major == 0)
@@ -999,7 +995,6 @@ reread:
pd = buffer_start_ptr(wth->frame_buffer);
if (!netxray_read_rec_data(wth->fh, pd, packet_size, err, err_info))
return FALSE;
- wth->data_offset += packet_size;
/*
* Set the pseudo-header.