aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
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
parentf65cb5f27bab6310e847f88cd763eb08bff1c93b (diff)
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')
-rw-r--r--wiretap/5views.c8
-rw-r--r--wiretap/aethra.c6
-rw-r--r--wiretap/airopeek9.c6
-rw-r--r--wiretap/ascendtext.c2
-rw-r--r--wiretap/ber.c9
-rw-r--r--wiretap/btsnoop.c6
-rw-r--r--wiretap/catapult_dct2000.c9
-rw-r--r--wiretap/commview.c7
-rw-r--r--wiretap/cosine.c2
-rw-r--r--wiretap/csids.c7
-rw-r--r--wiretap/daintree-sna.c5
-rw-r--r--wiretap/dbs-etherwatch.c2
-rw-r--r--wiretap/dct3trace.c3
-rw-r--r--wiretap/erf.c6
-rw-r--r--wiretap/etherpeek.c10
-rw-r--r--wiretap/eyesdn.c2
-rw-r--r--wiretap/file_access.c2
-rw-r--r--wiretap/hcidump.c4
-rw-r--r--wiretap/i4btrace.c5
-rw-r--r--wiretap/ipfix.c7
-rw-r--r--wiretap/iptrace.c11
-rw-r--r--wiretap/iseries.c3
-rw-r--r--wiretap/k12.c5
-rw-r--r--wiretap/k12text.l43
-rw-r--r--wiretap/lanalyzer.c13
-rw-r--r--wiretap/libpcap.c23
-rw-r--r--wiretap/mime_file.c3
-rw-r--r--wiretap/mpeg.c3
-rw-r--r--wiretap/netmon.c11
-rw-r--r--wiretap/netscaler.c20
-rw-r--r--wiretap/netscreen.c2
-rw-r--r--wiretap/nettl.c5
-rw-r--r--wiretap/network_instruments.c31
-rw-r--r--wiretap/netxray.c23
-rw-r--r--wiretap/ngsniffer.c106
-rw-r--r--wiretap/packetlogger.c5
-rw-r--r--wiretap/pcapng.c25
-rw-r--r--wiretap/radcom.c19
-rw-r--r--wiretap/snoop.c13
-rw-r--r--wiretap/tnef.c9
-rw-r--r--wiretap/toshiba.c2
-rw-r--r--wiretap/visual.c9
-rw-r--r--wiretap/vms.c2
-rw-r--r--wiretap/vwr.c9
-rw-r--r--wiretap/wtap-int.h2
45 files changed, 172 insertions, 333 deletions
diff --git a/wiretap/5views.c b/wiretap/5views.c
index 1ad604204f..f3cfda1865 100644
--- a/wiretap/5views.c
+++ b/wiretap/5views.c
@@ -134,8 +134,6 @@ int _5views_open(wtap *wth, int *err, gchar **err_info)
return 0;
}
- wth->data_offset+=bytes_read;
-
/* Check whether that's 5Views format or not */
if(Capture_Header.Info_Header.Signature != CST_5VW_INFO_HEADER_KEY)
{
@@ -189,7 +187,6 @@ int _5views_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset+=bytes_read;
/* This is a 5views capture file */
wth->file_type = WTAP_FILE_5VIEWS;
@@ -220,7 +217,6 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*/
return FALSE;
}
- wth->data_offset += bytes_read;
TimeStamped_Header.Key = pletohl(&TimeStamped_Header.Key);
if(TimeStamped_Header.Key != CST_5VW_RECORDS_HEADER_KEY) {
@@ -237,7 +233,6 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
if(TimeStamped_Header.RecSubType != CST_5VW_FRAME_RECORD) {
if (file_seek(wth->fh, TimeStamped_Header.RecSize, SEEK_CUR, err) == -1)
return FALSE;
- wth->data_offset += TimeStamped_Header.RecSize;
} else
break;
} while (1);
@@ -255,14 +250,13 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
buffer_assure_space(wth->frame_buffer, packet_size);
if (!_5views_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
packet_size, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
TimeStamped_Header.Utc = pletohl(&TimeStamped_Header.Utc);
TimeStamped_Header.NanoSecondes =
pletohl(&TimeStamped_Header.NanoSecondes);
diff --git a/wiretap/aethra.c b/wiretap/aethra.c
index 44e728c61d..08880823dd 100644
--- a/wiretap/aethra.c
+++ b/wiretap/aethra.c
@@ -142,7 +142,6 @@ int aethra_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr.magic;
if (memcmp(hdr.magic, aethra_magic, sizeof aethra_magic) != 0)
return 0;
@@ -157,7 +156,6 @@ int aethra_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr - sizeof hdr.magic;
wth->file_type = WTAP_FILE_AETHRA;
aethra = (aethra_t *)g_malloc(sizeof(aethra_t));
wth->priv = (void *)aethra;
@@ -205,7 +203,7 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
* of AETHRA_ISDN_LINK_LAPD record or get an end-of-file.
*/
for (;;) {
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* Read record header. */
if (!aethra_read_rec_header(wth->fh, &hdr, &wth->pseudo_header,
@@ -220,7 +218,6 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
rec_size, (unsigned int)(sizeof hdr - sizeof hdr.rec_size));
return FALSE;
}
- wth->data_offset += sizeof hdr;
/*
* XXX - if this is big, we might waste memory by
@@ -232,7 +229,6 @@ static gboolean aethra_read(wtap *wth, int *err, gchar **err_info,
if (!aethra_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
packet_size, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
}
#if 0
packet++;
diff --git a/wiretap/airopeek9.c b/wiretap/airopeek9.c
index b322e8bf04..a43303774c 100644
--- a/wiretap/airopeek9.c
+++ b/wiretap/airopeek9.c
@@ -301,8 +301,6 @@ int airopeek9_open(wtap *wth, int *err, gchar **err_info)
/*
* This is an EtherPeek or AiroPeek V9 file.
*/
- wth->data_offset = file_tell (wth->fh);
-
file_encap = airopeek9_encap[mediaSubType];
wth->file_type = WTAP_FILE_AIROPEEK_V9;
@@ -492,13 +490,12 @@ static gboolean airopeekv9_read(wtap *wth, int *err, gchar **err_info,
int hdrlen;
double t;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* Process the packet header. */
hdrlen = airopeekv9_process_header(wth->fh, &hdr_info, err, err_info);
if (hdrlen == 0)
return FALSE;
- wth->data_offset += hdrlen;
/*
* If sliceLength is 0, force it to be the actual length of the packet.
@@ -529,7 +526,6 @@ static gboolean airopeekv9_read(wtap *wth, int *err, gchar **err_info,
wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
hdr_info.sliceLength, wth->fh, err,
err_info);
- wth->data_offset += hdr_info.sliceLength;
/* recalculate and fill in packet time stamp */
t = (double) hdr_info.timestamp.lower +
diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c
index 569713e043..2795a23ca2 100644
--- a/wiretap/ascendtext.c
+++ b/wiretap/ascendtext.c
@@ -202,7 +202,6 @@ int ascend_open(wtap *wth, int *err, gchar **err_info)
return 0;
}
- wth->data_offset = offset;
wth->file_type = WTAP_FILE_ASCEND;
switch(wth->pseudo_header.ascend.type) {
@@ -322,7 +321,6 @@ static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
wth->phdr.ts.nsecs = header.usecs * 1000;
wth->phdr.caplen = header.caplen;
wth->phdr.len = header.len;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
diff --git a/wiretap/ber.c b/wiretap/ber.c
index df0b1687af..7b85309550 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -44,17 +44,20 @@
static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
+ gint64 offset;
guint8 *buf;
gint64 file_size;
int packet_size;
*err = 0;
+ offset = file_tell(wth->fh);
+
/* there is only ever one packet */
- if(wth->data_offset)
+ if (offset != 0)
return FALSE;
- *data_offset = wth->data_offset;
+ *data_offset = offset;
if ((file_size = wtap_file_size(wth, err)) == -1)
return FALSE;
@@ -76,8 +79,6 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info);
- wth->data_offset += packet_size;
-
wth->phdr.presence_flags = 0; /* yes, we have no bananas^Wtime stamp */
wth->phdr.caplen = packet_size;
diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c
index a8e6d80e73..c9397d556b 100644
--- a/wiretap/btsnoop.c
+++ b/wiretap/btsnoop.c
@@ -98,7 +98,6 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof magic;
if (memcmp(magic, btsnoop_magic, sizeof btsnoop_magic) != 0) {
return 0;
@@ -113,7 +112,6 @@ int btsnoop_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr;
/*
* Make sure it's a version we support.
@@ -169,7 +167,7 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
/* As the send/receive flag is stored in the middle of the capture header
but needs to go in the pseudo header for wiretap, the header needs to be reread
in the seek_read function*/
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* Read record header. */
errno = WTAP_ERR_CANT_READ;
@@ -180,7 +178,6 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += sizeof hdr;
packet_size = g_ntohl(hdr.incl_len);
orig_size = g_ntohl(hdr.orig_len);
@@ -201,7 +198,6 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
packet_size, err, err_info)) {
return FALSE; /* Read error */
}
- wth->data_offset += packet_size;
ts = GINT64_FROM_BE(hdr.ts_usec);
ts -= KUnixTimeBase;
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index 28240409f2..ef6769d998 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -281,7 +281,7 @@ static gboolean
catapult_dct2000_read(wtap *wth, int *err, gchar **err_info _U_,
gint64 *data_offset)
{
- gint64 offset = wth->data_offset;
+ gint64 offset = file_tell(wth->fh);
long dollar_offset, before_time_offset, after_time_offset;
packet_direction_t direction;
int encap;
@@ -309,7 +309,7 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info _U_,
gchar outhdr_name[MAX_OUTHDR_NAME+1];
/* Are looking for first packet after 2nd line */
- if (wth->data_offset == 0) {
+ if (file_tell(wth->fh) == 0) {
this_offset += (file_externals->firstline_length+1+
file_externals->secondline_length+1);
}
@@ -351,9 +351,6 @@ catapult_dct2000_read(wtap *wth, int *err, gchar **err_info _U_,
*/
*data_offset = this_offset;
- /* This is the position in the file where the next _read() will be called from */
- wth->data_offset = this_offset + line_length + 1;
-
/* Fill in timestamp (capture base + packet offset) */
wth->phdr.ts.secs = file_externals->start_secs + seconds;
if ((file_externals->start_usecs + useconds) >= 1000000) {
@@ -458,7 +455,7 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
union wtap_pseudo_header *pseudo_header, guint8 *pd,
int length, int *err, gchar **err_info)
{
- gint64 offset = wth->data_offset;
+ gint64 offset;
long dollar_offset, before_time_offset, after_time_offset;
static gchar linebuff[MAX_LINE_LENGTH+1];
gchar aal_header_chars[AAL_HEADER_CHARS];
diff --git a/wiretap/commview.c b/wiretap/commview.c
index a2415fdcd7..f3c3e3ecb1 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -124,7 +124,6 @@ int commview_open(wtap *wth, int *err, gchar **err_info)
wth->subtype_read = commview_read;
wth->subtype_seek_read = commview_seek_read;
- wth->data_offset = 0;
wth->file_type = WTAP_FILE_COMMVIEW;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
@@ -162,13 +161,11 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
struct tm tm;
int bytes_read;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
if(!commview_read_header(&cv_hdr, wth->fh, err, err_info))
return FALSE;
- wth->data_offset += COMMVIEW_HEADER_SIZE;
-
switch(cv_hdr.flags & FLAGS_MEDIUM) {
case MEDIUM_ETHERNET :
@@ -210,8 +207,6 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
tm.tm_sec = cv_hdr.seconds;
tm.tm_isdst = -1;
- wth->data_offset += cv_hdr.data_len;
-
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.len = cv_hdr.data_len;
diff --git a/wiretap/cosine.c b/wiretap/cosine.c
index 022667a357..9121861b3c 100644
--- a/wiretap/cosine.c
+++ b/wiretap/cosine.c
@@ -294,7 +294,6 @@ int cosine_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
return -1;
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_COSINE;
wth->file_type = WTAP_FILE_COSINE;
wth->snapshot_length = 0; /* not known */
@@ -334,7 +333,6 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
err_info)) == -1)
return FALSE;
- wth->data_offset = offset;
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
wth->phdr.caplen = caplen;
*data_offset = offset;
diff --git a/wiretap/csids.c b/wiretap/csids.c
index 23f97c5749..61722f6dcb 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -136,7 +136,6 @@ int csids_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return -1;
- wth->data_offset = 0;
csids = (csids_t *)g_malloc(sizeof(csids_t));
wth->priv = (void *)csids;
csids->byteswapped = byteswap;
@@ -159,7 +158,7 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
int bytesRead = 0;
struct csids_header hdr;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
bytesRead = file_read( &hdr, sizeof( struct csids_header) , wth->fh );
if( bytesRead != sizeof( struct csids_header) ) {
@@ -171,8 +170,6 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
hdr.seconds = pntohl(&hdr.seconds);
hdr.caplen = pntohs(&hdr.caplen);
- wth->data_offset += sizeof( struct csids_header );
-
/* Make sure we have enough room for the packet */
buffer_assure_space(wth->frame_buffer, hdr.caplen);
buf = buffer_start_ptr(wth->frame_buffer);
@@ -185,8 +182,6 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
- wth->data_offset += hdr.caplen;
-
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.len = hdr.caplen;
wth->phdr.caplen = hdr.caplen;
diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c
index d52135a8c1..e0b6b0fd8b 100644
--- a/wiretap/daintree-sna.c
+++ b/wiretap/daintree-sna.c
@@ -99,7 +99,6 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_)
/* get first line of file header */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0;
- wth->data_offset += strlen(readLine);
/* check magic text */
i = 0;
@@ -110,7 +109,6 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_)
/* read second header line */
if (file_gets(readLine, DAINTREE_MAX_LINE_SIZE, wth->fh)==NULL) return 0;
- wth->data_offset += strlen(readLine);
if (readLine[0] != COMMENT_LINE) return 0; /* daintree files have a two line header */
/* set up the pointers to the handlers for this file type */
@@ -135,7 +133,7 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
guint64 seconds;
char readData[READDATA_BUF_SIZE];
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* we've only seen file header lines starting with '#', but
* if others appear in the file, they are tossed */
@@ -144,7 +142,6 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*err = file_error(wth->fh, err_info);
return FALSE; /* all done */
}
- wth->data_offset += strlen(readLine);
} while (readLine[0] == COMMENT_LINE);
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c
index 7bc6ff1be6..b07677c480 100644
--- a/wiretap/dbs-etherwatch.c
+++ b/wiretap/dbs-etherwatch.c
@@ -201,7 +201,6 @@ int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type = WTAP_FILE_DBS_ETHERWATCH;
wth->snapshot_length = 0; /* not known */
@@ -239,7 +238,6 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
*/
wth->pseudo_header.eth.fcs_len = 0;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
}
diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c
index dfc916994a..dc8243cf8c 100644
--- a/wiretap/dct3trace.c
+++ b/wiretap/dct3trace.c
@@ -203,7 +203,6 @@ int dct3trace_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_GSM_UM;
wth->file_type = WTAP_FILE_DCT3TRACE;
wth->snapshot_length = 0; /* not known */
@@ -366,7 +365,7 @@ static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
buffer_assure_space(wth->frame_buffer, buf_len);
memcpy( buffer_start_ptr(wth->frame_buffer), buf, buf_len );
- wth->data_offset = *data_offset = offset;
+ *data_offset = offset;
return TRUE;
}
diff --git a/wiretap/erf.c b/wiretap/erf.c
index 213bd1af31..4f608c6988 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -262,8 +262,6 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
- wth->data_offset = 0;
-
/* This is an ERF file */
wth->file_type = WTAP_FILE_ERF;
wth->snapshot_length = 0; /* not available in header, only in frame */
@@ -287,7 +285,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
erf_header_t erf_header;
guint32 packet_size, bytes_read;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
do {
if (!erf_read_header(wth->fh,
@@ -295,13 +293,11 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info,
err, err_info, &bytes_read, &packet_size)) {
return FALSE;
}
- wth->data_offset += bytes_read;
buffer_assure_space(wth->frame_buffer, packet_size);
wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
(gint32)(packet_size), wth->fh, err, err_info);
- wth->data_offset += packet_size;
} while ( erf_header.type == ERF_TYPE_PAD );
diff --git a/wiretap/etherpeek.c b/wiretap/etherpeek.c
index fb5659c3fd..6f7dac635e 100644
--- a/wiretap/etherpeek.c
+++ b/wiretap/etherpeek.c
@@ -165,7 +165,6 @@ int etherpeek_open(wtap *wth, int *err, gchar **err_info)
g_assert(sizeof(ep_hdr.master) == ETHERPEEK_MASTER_HDR_SIZE);
wtap_file_read_unknown_bytes(
&ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err, err_info);
- wth->data_offset += sizeof(ep_hdr.master);
/*
* It appears that EtherHelp (a free application from WildPackets
@@ -193,7 +192,6 @@ int etherpeek_open(wtap *wth, int *err, gchar **err_info)
wtap_file_read_unknown_bytes(
&ep_hdr.secondary.v567,
sizeof(ep_hdr.secondary.v567), wth->fh, err, err_info);
- wth->data_offset += sizeof(ep_hdr.secondary.v567);
if ((0 != ep_hdr.secondary.v567.reserved[0]) ||
(0 != ep_hdr.secondary.v567.reserved[1]) ||
@@ -361,11 +359,10 @@ static gboolean etherpeek_read_v7(wtap *wth, int *err, gchar **err_info,
time_t tsecs;
guint32 tusecs;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err,
err_info);
- wth->data_offset += sizeof(ep_pkt);
/* Extract the fields from the packet */
#if 0
@@ -412,7 +409,6 @@ static gboolean etherpeek_read_v7(wtap *wth, int *err, gchar **err_info,
buffer_assure_space(wth->frame_buffer, sliceLength);
wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
sliceLength, wth->fh, err, err_info);
- wth->data_offset += sliceLength;
/* fill in packet header values */
tsecs = (time_t) (timestamp/1000000);
@@ -505,11 +501,10 @@ static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info,
* the packet header, we can remember the offset of the data,
* and not have the seek_read routine read the header.
*/
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), wth->fh, err,
err_info);
- wth->data_offset += sizeof(ep_pkt);
/* Extract the fields from the packet */
length = pntohs(&ep_pkt[ETHERPEEK_V56_LENGTH_OFFSET]);
@@ -541,7 +536,6 @@ static gboolean etherpeek_read_v56(wtap *wth, int *err, gchar **err_info,
buffer_assure_space(wth->frame_buffer, sliceLength);
wtap_file_read_expected_bytes(buffer_start_ptr(wth->frame_buffer),
sliceLength, wth->fh, err, err_info);
- wth->data_offset += sliceLength;
/* fill in packet header values */
wth->phdr.len = length;
diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c
index 06446a5b3d..ec6373906f 100644
--- a/wiretap/eyesdn.c
+++ b/wiretap/eyesdn.c
@@ -150,7 +150,6 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info)
if (memcmp(magic, eyesdn_hdr_magic, EYESDN_HDR_MAGIC_SIZE) != 0)
return 0;
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->file_type = WTAP_FILE_EYESDN;
wth->snapshot_length = 0; /* not known */
@@ -188,7 +187,6 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
if (!parse_eyesdn_packet_data(wth->fh, pkt_len, buf, err, err_info))
return FALSE;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
}
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 3178bff1ca..c823098f52 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -343,7 +343,6 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
/* initialization */
wth->file_encap = WTAP_ENCAP_UNKNOWN;
- wth->data_offset = 0;
wth->subtype_sequential_close = NULL;
wth->subtype_close = NULL;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
@@ -374,7 +373,6 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
g_free(wth);
return NULL;
}
- wth->data_offset = 0;
switch ((*open_routines[i])(wth, err, err_info)) {
diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c
index fdcc3cb175..b2d4c93624 100644
--- a/wiretap/hcidump.c
+++ b/wiretap/hcidump.c
@@ -45,7 +45,7 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
guint8 *buf;
int bytes_read, packet_size;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh);
if (bytes_read != DUMP_HDR_SIZE) {
@@ -54,7 +54,6 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += DUMP_HDR_SIZE;
packet_size = GUINT16_FROM_LE(dh.len);
if (packet_size > WTAP_MAX_PACKET_SIZE) {
@@ -78,7 +77,6 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.ts.secs = GUINT32_FROM_LE(dh.ts_sec);
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index 05b6087583..0a8e3e438e 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -101,7 +101,6 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return -1;
- wth->data_offset = 0;
/* Get capture start time */
@@ -130,13 +129,12 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
void *bufp;
/* Read record header. */
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
ret = i4b_read_rec_header(wth->fh, &hdr, err, err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += sizeof hdr;
i4b_byte_swap_header(wth, &hdr);
if (hdr.length < sizeof(hdr)) {
*err = WTAP_ERR_BAD_FILE; /* record length < header! */
@@ -171,7 +169,6 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
bufp = buffer_start_ptr(wth->frame_buffer);
if (!i4b_read_rec_data(wth->fh, bufp, length, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += length;
switch (hdr.type) {
diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c
index 07a7c0acee..e7e0b0ab5b 100644
--- a/wiretap/ipfix.c
+++ b/wiretap/ipfix.c
@@ -262,8 +262,8 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
ipfix_message_header_t msg_hdr;
- ipfix_debug1("ipfix_read: wth->data_offset is initially %" G_GINT64_MODIFIER "u", wth->data_offset);
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
+ ipfix_debug1("ipfix_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
if (!ipfix_read_message_header(&msg_hdr, wth->fh, err, err_info)) {
ipfix_debug2("ipfix_read: couldn't read message header with code: %d\n, and error '%s'",
@@ -282,8 +282,7 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
wth->phdr.ts.nsecs = 0;
/*ipfix_debug2("Read length: %u Packet length: %u", msg_hdr.message_length, wth->phdr.caplen);*/
- wth->data_offset += msg_hdr.message_length;
- ipfix_debug1("ipfix_read: wth->data_offset is finally %" G_GINT64_MODIFIER "u", wth->data_offset);
+ ipfix_debug1("ipfix_read: data_offset is finally %" G_GINT64_MODIFIER "d", file_tell(wth->fh));
return TRUE;
}
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index 3b6c7739e2..1dca53675d 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -65,7 +65,6 @@ int iptrace_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += 11;
name[11] = 0;
if (strcmp(name, "iptrace 1.0") == 0) {
@@ -134,14 +133,13 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
guint8 fddi_padding[3];
/* Read the descriptor data */
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_1_0_PHDR_SIZE,
err, err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += IPTRACE_1_0_PHDR_SIZE;
/*
* Byte 28 of the frame header appears to be a BSD-style IFT_xxx
@@ -185,7 +183,6 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
packet_size -= 3;
- wth->data_offset += 3;
/*
* Read the padding.
@@ -210,7 +207,6 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err,
err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.len = packet_size;
@@ -349,14 +345,13 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
guint8 fddi_padding[3];
/* Read the descriptor data */
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_2_0_PHDR_SIZE,
err, err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += IPTRACE_2_0_PHDR_SIZE;
/*
* Byte 28 of the frame header appears to be a BSD-style IFT_xxx
@@ -400,7 +395,6 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
packet_size -= 3;
- wth->data_offset += 3;
/*
* Read the padding.
@@ -425,7 +419,6 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err,
err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.len = packet_size;
diff --git a/wiretap/iseries.c b/wiretap/iseries.c
index 37c2742880..764f2401ae 100644
--- a/wiretap/iseries.c
+++ b/wiretap/iseries.c
@@ -231,7 +231,6 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type = WTAP_FILE_ISERIES;
wth->snapshot_length = 0;
@@ -272,7 +271,6 @@ iseries_open (wtap * wth, int *err, gchar ** err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_ETHERNET;
wth->file_type = WTAP_FILE_ISERIES;
wth->snapshot_length = 0;
@@ -429,7 +427,6 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
if (pkt_len == -1)
return FALSE;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
}
diff --git a/wiretap/k12.c b/wiretap/k12.c
index a4cbf0c417..7be553aafb 100644
--- a/wiretap/k12.c
+++ b/wiretap/k12.c
@@ -410,7 +410,7 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
guint64 ts;
guint32 extra_len;
- offset = wth->data_offset;
+ offset = file_tell(wth->fh);
/* ignore the record if it isn't a packet */
do {
@@ -448,8 +448,6 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
} while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET) || !src_id || !src_desc );
- wth->data_offset = offset;
-
wth->phdr.presence_flags = WTAP_HAS_TS;
ts = pntohll(buffer + K12_PACKET_TIMESTAMP);
@@ -815,7 +813,6 @@ int k12_open(wtap *wth, int *err, gchar **err_info) {
}
} while(1);
- wth->data_offset = offset;
wth->file_type = WTAP_FILE_K12;
wth->file_encap = WTAP_ENCAP_K12;
wth->snapshot_length = 0;
diff --git a/wiretap/k12text.l b/wiretap/k12text.l
index 867725231c..40fdd2f4a9 100644
--- a/wiretap/k12text.l
+++ b/wiretap/k12text.l
@@ -113,6 +113,21 @@ static FILE_T yy_fh;
#define MAX_JUNK 400000
#define ECHO
+
+/*
+ * Private per-file data.
+ */
+typedef struct {
+ /*
+ * The file position after the end of the previous frame processed by
+ * k12text_read.
+ *
+ * We need to keep this around, and seek to it at the beginning of
+ * each call to k12text_read(), since the lexer undoubtedly did some
+ * amount of look-ahead when processing the previous frame.
+ */
+ gint64 next_frame_offset;
+} k12text_t;
%}
start_timestamp \053[\055]{9}\053[\055]{15,100}\053[\055]{10,100}\053
oneormoredigits [0-9]+:
@@ -222,13 +237,18 @@ k12text_reset(FILE_T fh)
static gboolean
k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
{
-
- /* We seek to the file position after the end of the previous frame processed by */
- /* k12text_read (kept in wth->data_offset). We do this each time since the lexer */
- /* undoubtedly did some amount of look-ahead when processing the previous frame. */
- /* We also clear out any lexer state (eg: look-ahead buffer) and init vars set by lexer. */
-
- if ( file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ k12text_t *k12text = (k12text_t *)wth->priv;
+
+ /*
+ * We seek to the file position after the end of the previous frame
+ * processed by k12text_read(), since the lexer undoubtedly did some
+ * amount of look-ahead when processing the previous frame.
+ *
+ * We also clear out any lexer state (eg: look-ahead buffer) and
+ * init vars set by lexer.
+ */
+
+ if ( file_seek(wth->fh, k12text->next_frame_offset, SEEK_SET, err) == -1) {
return FALSE;
}
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
@@ -247,8 +267,8 @@ k12text_read(wtap *wth, int *err, char ** err_info, gint64 *data_offset)
return FALSE;
}
- *data_offset = wth->data_offset; /* file position for beginning of this frame */
- wth->data_offset += file_bytes_read; /* file position after end of this frame */
+ *data_offset = k12text->next_frame_offset; /* file position for beginning of this frame */
+ k12text->next_frame_offset += file_bytes_read; /* file position after end of this frame */
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
@@ -307,6 +327,7 @@ k12text_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_h
int
k12text_open(wtap *wth, int *err, gchar **err_info _U_)
{
+ k12text_t *k12text;
k12text_reset(wth->fh); /* init lexer buffer and vars set by lexer */
@@ -319,7 +340,9 @@ k12text_open(wtap *wth, int *err, gchar **err_info _U_)
return -1;
}
- wth->data_offset = 0;
+ k12text = (k12text_t *)g_malloc(sizeof(k12text_t));
+ wth->priv = (void *)k12text;
+ k12text->next_frame_offset = 0;
wth->file_type = WTAP_FILE_K12TEXT;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->snapshot_length = 0;
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index 498855bbef..77a6887041 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -296,7 +296,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += LA_RecordHeaderSize;
record_type = pletohs(rec_header.record_type);
record_length = pletohs(rec_header.record_length); /* make sure to do this for while() loop */
@@ -319,7 +318,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
*err = WTAP_ERR_SHORT_READ;
return -1;
}
- wth->data_offset += sizeof header_fixed;
record_length -= sizeof header_fixed;
if (record_length != 0) {
@@ -333,7 +331,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
comment[record_length] = '\0';
- wth->data_offset += record_length;
wth->shb_hdr.opt_comment = comment;
}
@@ -361,7 +358,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
g_free(wth->priv);
return 0;
}
- wth->data_offset += LA_RecordHeaderSize;
record_type = pletohs(rec_header.record_type);
record_length = pletohs(rec_header.record_length);
@@ -382,7 +378,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
g_free(wth->priv);
return 0;
}
- wth->data_offset += sizeof summary;
/* Assume that the date of the creation of the trace file
* is the same date of the trace. Lanalyzer doesn't
@@ -437,7 +432,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
g_free(wth->priv);
return -1;
}
- wth->data_offset -= LA_RecordHeaderSize;
return 1;
default:
@@ -445,7 +439,6 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
g_free(wth->priv);
return -1;
}
- wth->data_offset += record_length;
break;
}
}
@@ -478,7 +471,6 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
}
return FALSE;
}
- wth->data_offset += 2;
bytes_read = file_read(LE_record_length, 2, wth->fh);
if (bytes_read != 2) {
*err = file_error(wth->fh, err_info);
@@ -486,7 +478,6 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += 2;
record_type = pletohs(LE_record_type);
record_length = pletohs(LE_record_length);
@@ -523,11 +514,10 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += DESCRIPTOR_LEN;
/* Read the packet data */
buffer_assure_space(wth->frame_buffer, packet_size);
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
packet_size, wth->fh);
@@ -538,7 +528,6 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += packet_size;
true_size = pletohs(&descriptor[4]);
packet_size = pletohs(&descriptor[6]);
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index bf2a5aceb0..c509643e7b 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -88,6 +88,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
gboolean modified;
gboolean aix;
int file_encap;
+ gint64 first_packet_offset;
libpcap_t *libpcap;
/* Read in the number that should be at the start of a "libpcap" file */
@@ -99,7 +100,6 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof magic;
switch (magic) {
@@ -170,7 +170,6 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr;
if (byte_swapped) {
/* Byte-swap the header fields about which we care. */
@@ -357,6 +356,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* Try ss991029, the last of his patches, first.
*/
wth->file_type = WTAP_FILE_PCAP_SS991029;
+ first_packet_offset = file_tell(wth->fh);
switch (libpcap_try(wth, err)) {
case BAD_READ:
@@ -372,7 +372,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* Well, it looks as if it might be 991029.
* Put the seek pointer back, and return success.
*/
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -393,7 +393,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* it as 990915.
*/
wth->file_type = WTAP_FILE_PCAP_SS990915;
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -408,6 +408,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
} else {
wth->file_type = WTAP_FILE_PCAP;
}
+ first_packet_offset = file_tell(wth->fh);
switch (libpcap_try(wth, err)) {
case BAD_READ:
@@ -424,7 +425,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* libpcap file.
* Put the seek pointer back, and return success.
*/
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -443,7 +444,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* ss990417.
*/
wth->file_type = WTAP_FILE_PCAP_SS990417;
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -462,7 +463,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* Well, it looks as if it might be ss990417.
* Put the seek pointer back, and return success.
*/
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -483,7 +484,7 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
* and treat it as a Nokia file.
*/
wth->file_type = WTAP_FILE_PCAP_NOKIA;
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
+ if (file_seek(wth->fh, first_packet_offset, SEEK_SET, err) == -1) {
g_free(wth->priv);
return -1;
}
@@ -612,7 +613,6 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
- wth->data_offset += bytes_read;
packet_size = hdr.hdr.incl_len;
orig_size = hdr.hdr.orig_len;
@@ -629,7 +629,6 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
*/
packet_size -= 3;
orig_size -= 3;
- wth->data_offset += 3;
/*
* Read the padding.
@@ -639,7 +638,7 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
return FALSE; /* Read error */
}
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
libpcap = (libpcap_t *)wth->priv;
phdr_len = pcap_process_pseudo_header(wth->fh, wth->file_type,
@@ -653,13 +652,11 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
*/
orig_size -= phdr_len;
packet_size -= phdr_len;
- wth->data_offset += phdr_len;
buffer_assure_space(wth->frame_buffer, packet_size);
if (!libpcap_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
packet_size, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c
index 90eafcd9c0..f3a4561c09 100644
--- a/wiretap/mime_file.c
+++ b/wiretap/mime_file.c
@@ -102,7 +102,7 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
wth->phdr.ts.secs = 0;
wth->phdr.ts.nsecs = 0;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* try to read max WTAP_MAX_PACKET_SIZE bytes */
packet_size = file_read(_buf, sizeof(_buf), wth->fh);
@@ -123,7 +123,6 @@ mime_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
buf = buffer_start_ptr(wth->frame_buffer);
memcpy(buf, _buf, packet_size);
- wth->data_offset += packet_size;
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
return TRUE;
diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c
index fc7f126a6e..321f45a69a 100644
--- a/wiretap/mpeg.c
+++ b/wiretap/mpeg.c
@@ -225,13 +225,12 @@ mpeg_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
}
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
buffer_assure_space(wth->frame_buffer, packet_size);
if (!mpeg_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
packet_size, err, err_info))
return FALSE;
- wth->data_offset += packet_size;
/* XXX - relative, not absolute, time stamps */
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.ts = ts;
diff --git a/wiretap/netmon.c b/wiretap/netmon.c
index d6d179e34f..e5253ace55 100644
--- a/wiretap/netmon.c
+++ b/wiretap/netmon.c
@@ -512,9 +512,8 @@ again:
file, but set the frame table up so it's the last
record in sequence. */
rec_offset = netmon->frame_table[netmon->current_frame];
- if (wth->data_offset != rec_offset) {
- wth->data_offset = rec_offset;
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1)
+ if (file_tell(wth->fh) != rec_offset) {
+ if (file_seek(wth->fh, rec_offset, SEEK_SET, err) == -1)
return FALSE;
}
netmon->current_frame++;
@@ -540,7 +539,6 @@ again:
}
return FALSE;
}
- wth->data_offset += hdr_size;
switch (netmon->version_major) {
@@ -565,7 +563,7 @@ again:
return FALSE;
}
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/*
* If this is an ATM packet, the first
@@ -596,7 +594,6 @@ again:
*/
orig_size -= (guint)sizeof (struct netmon_atm_hdr);
packet_size -= (guint)sizeof (struct netmon_atm_hdr);
- wth->data_offset += sizeof (struct netmon_atm_hdr);
break;
default:
@@ -608,7 +605,6 @@ again:
if (!netmon_read_rec_data(wth->fh, data_ptr, packet_size, err,
err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
switch (netmon->version_major) {
@@ -696,7 +692,6 @@ again:
trlr_size, err, err_info);
if (wth->phdr.pkt_encap == -1)
return FALSE; /* error */
- wth->data_offset += trlr_size;
if (wth->phdr.pkt_encap == 0)
goto again;
netmon_set_pseudo_header_info(wth->phdr.pkt_encap,
diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c
index f26164314e..d4a3cc9db5 100644
--- a/wiretap/netscaler.c
+++ b/wiretap/netscaler.c
@@ -433,6 +433,7 @@ typedef struct nspr_pktracepart_v24
typedef struct {
gchar *pnstrace_buf;
+ gint64 xxx_offset;
gint32 nstrace_buf_offset;
gint32 nstrace_buflen;
/* Performance Monitor Time variables */
@@ -540,6 +541,7 @@ int nstrace_open(wtap *wth, int *err, gchar **err_info)
nstrace = (nstrace_t *)g_malloc(sizeof(nstrace_t));
wth->priv = (void *)nstrace;
nstrace->pnstrace_buf = nstrace_buf;
+ nstrace->xxx_offset = 0;
nstrace->nstrace_buflen = page_size;
nstrace->nstrace_buf_offset = 0;
nstrace->nspm_curtime = 0;
@@ -668,8 +670,8 @@ nspm_signature_version(wtap *wth, gchar *nstrace_buf, gint32 len)
}\
}\
nstrace_buf_offset = 0;\
- wth->data_offset += nstrace_buflen;\
- nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - wth->data_offset));\
+ nstrace->xxx_offset += nstrace_buflen;\
+ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));\
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && bytes_read == nstrace_buflen); \
return FALSE;\
}
@@ -756,7 +758,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
memcpy(buffer_start_ptr(wth->frame_buffer), fp, wth->phdr.caplen);
- *data_offset = wth->data_offset + nstrace_buf_offset;
+ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;
nstrace->nstrace_buf_offset = nstrace_buf_offset + wth->phdr.len;
nstrace->nstrace_buflen = nstrace_buflen;
@@ -781,7 +783,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
memcpy(buffer_start_ptr(wth->frame_buffer), pp, wth->phdr.caplen);
- *data_offset = wth->data_offset + nstrace_buf_offset;
+ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;
nstrace->nstrace_buf_offset = nstrace_buf_offset + wth->phdr.caplen;
nstrace->nsg_creltime = nsg_creltime;
@@ -814,8 +816,8 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
}
nstrace_buf_offset = 0;
- wth->data_offset += nstrace_buflen;
- nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - wth->data_offset));
+ nstrace->xxx_offset += nstrace_buflen;
+ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen));
return FALSE;
@@ -872,7 +874,7 @@ static gboolean nstrace_read_v10(wtap *wth, int *err, gchar **err_info, gint64 *
TRACE_V##ver##_REC_LEN_OFF(enumprefix,type,structname);\
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);\
memcpy(buffer_start_ptr(wth->frame_buffer), fp, wth->phdr.caplen);\
- *data_offset = wth->data_offset + nstrace_buf_offset;\
+ *data_offset = nstrace->xxx_offset + nstrace_buf_offset;\
nstrace->nstrace_buf_offset = nstrace_buf_offset + nspr_getv20recordsize((nspr_hd_v20_t *)fp);\
nstrace->nstrace_buflen = nstrace_buflen;\
nstrace->nsg_creltime = nsg_creltime;\
@@ -976,8 +978,8 @@ static gboolean nstrace_read_v20(wtap *wth, int *err, gchar **err_info, gint64 *
}
nstrace_buf_offset = 0;
- wth->data_offset += nstrace_buflen;
- nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - wth->data_offset));
+ nstrace->xxx_offset += nstrace_buflen;
+ nstrace_buflen = GET_READ_PAGE_SIZE((nstrace->file_size - nstrace->xxx_offset));
}while((nstrace_buflen > 0) && (bytes_read = file_read(nstrace_buf, nstrace_buflen, wth->fh)) && (bytes_read == nstrace_buflen));
return FALSE;
diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c
index d5011c84ce..29ba0fe0c7 100644
--- a/wiretap/netscreen.c
+++ b/wiretap/netscreen.c
@@ -204,7 +204,6 @@ int netscreen_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
return -1;
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->file_type = WTAP_FILE_NETSCREEN;
wth->snapshot_length = 0; /* not known */
@@ -292,7 +291,6 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info,
wth->file_encap = WTAP_ENCAP_PER_PACKET;
}
- wth->data_offset = offset;
wth->phdr.caplen = caplen;
*data_offset = offset;
return TRUE;
diff --git a/wiretap/nettl.c b/wiretap/nettl.c
index 83868011bf..b83c693cf7 100644
--- a/wiretap/nettl.c
+++ b/wiretap/nettl.c
@@ -295,7 +295,6 @@ int nettl_open(wtap *wth, int *err, gchar **err_info)
g_free(nettl);
return -1;
}
- wth->data_offset = FILE_HDR_SIZE;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
return 1;
@@ -309,14 +308,13 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
gboolean fddihack=FALSE;
/* Read record header. */
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->pseudo_header,
err, err_info, &fddihack);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += ret;
if (wth->phdr.caplen > WTAP_MAX_PACKET_SIZE) {
/*
@@ -351,7 +349,6 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
if (!nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
wth->phdr.caplen, err, err_info, fddihack))
return FALSE; /* Read error */
- wth->data_offset += wth->phdr.caplen;
return TRUE;
}
diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c
index 7ffa513cd7..554be28385 100644
--- a/wiretap/network_instruments.c
+++ b/wiretap/network_instruments.c
@@ -253,10 +253,8 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info)
wth->file_type = WTAP_FILE_NETWORK_INSTRUMENTS;
/* reset the pointer to the first packet */
- if (file_seek(wth->fh, header_offset, SEEK_SET,
- err) == -1)
+ if (file_seek(wth->fh, header_offset, SEEK_SET, err) == -1)
return -1;
- wth->data_offset = header_offset;
init_gmt_to_localtime_offset();
@@ -267,29 +265,26 @@ int network_instruments_open(wtap *wth, int *err, gchar **err_info)
static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- int bytes_consumed;
- int offset_from_packet_header = 0;
+ int header_bytes_consumed;
+ int data_bytes_consumed;
packet_entry_header packet_header;
/* skip records other than data records */
for (;;) {
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/* process the packet header, including TLVs */
- bytes_consumed = read_packet_header(wth->fh, &wth->pseudo_header, &packet_header, err,
+ header_bytes_consumed = read_packet_header(wth->fh, &wth->pseudo_header, &packet_header, err,
err_info);
- if (bytes_consumed <= 0)
+ if (header_bytes_consumed <= 0)
return FALSE; /* EOF or error */
- wth->data_offset += bytes_consumed;
-
if (packet_header.packet_type == PACKET_TYPE_DATA_PACKET)
break;
/* skip to next packet */
- offset_from_packet_header = (int) (wth->data_offset - *data_offset);
if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet,
- offset_from_packet_header, err, err_info)) {
+ header_bytes_consumed, err, err_info)) {
return FALSE; /* EOF or error */
}
}
@@ -354,19 +349,16 @@ static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
buffer_assure_space(wth->frame_buffer, packet_header.captured_size);
/* read the frame data */
- offset_from_packet_header = (int) (wth->data_offset - *data_offset);
- bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame,
- offset_from_packet_header, buffer_start_ptr(wth->frame_buffer),
+ data_bytes_consumed = read_packet_data(wth->fh, packet_header.offset_to_frame,
+ header_bytes_consumed, buffer_start_ptr(wth->frame_buffer),
packet_header.captured_size, err, err_info);
- if (bytes_consumed < 0) {
+ if (data_bytes_consumed < 0) {
return FALSE;
}
- wth->data_offset += bytes_consumed;
/* skip over any extra bytes following the frame data */
- offset_from_packet_header = (int) (wth->data_offset - *data_offset);
if (!skip_to_next_packet(wth, packet_header.offset_to_next_packet,
- offset_from_packet_header, err, err_info)) {
+ header_bytes_consumed + data_bytes_consumed, err, err_info)) {
return FALSE;
}
@@ -560,7 +552,6 @@ skip_to_next_packet(wtap *wth, int offset_to_next_packet, int current_offset_fro
if (seek_increment > 0) {
if (file_seek(wth->fh, seek_increment, SEEK_CUR, err) == -1)
return FALSE;
- wth->data_offset += seek_increment;
}
return TRUE;
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.
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index b2f07d11fe..ec2fe89c9c 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -533,9 +533,9 @@ static gint64 ng_file_read(void *buffer, unsigned int nbytes, wtap *wth,
gboolean is_random, int *err, gchar **err_info);
static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream,
int *err, gchar **err_info);
-static gint64 ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err,
+static gboolean ng_file_skip_seq(wtap *wth, gint64 delta, int *err,
gchar **err_info);
-static gint64 ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err,
+static gboolean ng_file_seek_rand(wtap *wth, gint64 offset, int *err,
gchar **err_info);
int
@@ -568,6 +568,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
};
#define NUM_NGSNIFF_ENCAPS (sizeof sniffer_encap / sizeof sniffer_encap[0])
struct tm tm;
+ gint64 current_offset;
ngsniffer_t *ngsniffer;
/* Read in the string that should be at the start of a Sniffer file */
@@ -579,7 +580,6 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof magic;
if (memcmp(magic, ngsniffer_magic, sizeof ngsniffer_magic)) {
return 0;
@@ -597,7 +597,6 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += 2;
bytes_read = file_read(record_length, 4, wth->fh);
if (bytes_read != 4) {
*err = file_error(wth->fh, err_info);
@@ -605,7 +604,6 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += 4;
type = pletohs(record_type);
@@ -623,7 +621,6 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof version;
/* Check the data link type. */
if (version.network >= NUM_NGSNIFF_ENCAPS
@@ -707,6 +704,8 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
}
}
+ current_offset = file_tell(wth->fh);
+
/*
* Now, if we have a random stream open, position it to the same
* location, which should be the beginning of the real data, and
@@ -717,7 +716,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
* "ngsniffer_read()".
*/
if (wth->random_fh != NULL) {
- if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET, err) == -1)
+ if (file_seek(wth->random_fh, current_offset, SEEK_SET, err) == -1)
return -1;
}
@@ -733,10 +732,10 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
/* Set the current file offset; the offset in the compressed file
and in the uncompressed data stream currently the same. */
- ngsniffer->seq.uncomp_offset = wth->data_offset;
- ngsniffer->seq.comp_offset = wth->data_offset;
- ngsniffer->rand.uncomp_offset = wth->data_offset;
- ngsniffer->rand.comp_offset = wth->data_offset;
+ ngsniffer->seq.uncomp_offset = current_offset;
+ ngsniffer->seq.comp_offset = current_offset;
+ ngsniffer->rand.uncomp_offset = current_offset;
+ ngsniffer->rand.comp_offset = current_offset;
/* We don't yet have any list of compressed blobs. */
ngsniffer->first_blob = NULL;
@@ -841,7 +840,6 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers,
*err = WTAP_ERR_SHORT_READ;
return -1;
}
- wth->data_offset += 6;
length = pletohs(record_length);
@@ -902,7 +900,6 @@ process_header_records(wtap *wth, int *err, gchar **err_info, gint16 maj_vers,
if (file_seek(wth->fh, length, SEEK_CUR, err) == -1)
return -1;
}
- wth->data_offset += length;
}
}
@@ -1067,16 +1064,20 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
ngsniffer = (ngsniffer_t *)wth->priv;
for (;;) {
/*
+ * We use the uncompressed offset, as that's what
+ * we need to use for compressed files.
+ */
+ *data_offset = ngsniffer->seq.uncomp_offset;
+
+ /*
* Read the record header.
*/
- *data_offset = wth->data_offset;
ret = ngsniffer_read_rec_header(wth, FALSE, &type, &length,
err, err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += 6;
switch (type) {
@@ -1097,7 +1098,6 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/* Read error */
return FALSE;
}
- wth->data_offset += sizeof frame2;
time_low = pletohs(&frame2.time_low);
time_med = pletohs(&frame2.time_med);
time_high = frame2.time_high;
@@ -1128,7 +1128,6 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/* Read error */
return FALSE;
}
- wth->data_offset += sizeof frame4;
time_low = pletohs(&frame4.time_low);
time_med = pletohs(&frame4.time_med);
time_high = frame4.time_high;
@@ -1160,7 +1159,6 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/* Read error */
return FALSE;
}
- wth->data_offset += sizeof frame6;
time_low = pletohs(&frame6.time_low);
time_med = pletohs(&frame6.time_med);
time_high = frame6.time_high;
@@ -1190,10 +1188,8 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
* it is but can't handle it. Skip past the data
* portion, and keep looping.
*/
- if (ng_file_seek_seq(wth, length, SEEK_CUR, err, err_info)
- == -1)
+ if (!ng_file_skip_seq(wth, length, err, err_info))
return FALSE;
- wth->data_offset += length;
}
found:
@@ -1221,7 +1217,6 @@ found:
pd = buffer_start_ptr(wth->frame_buffer);
if (!ngsniffer_read_rec_data(wth, FALSE, pd, length, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += length;
wth->phdr.pkt_encap = fix_pseudo_header(wth->file_encap, pd, length,
&wth->pseudo_header);
@@ -1270,7 +1265,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off,
struct frame4_rec frame4;
struct frame6_rec frame6;
- if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err, err_info) == -1)
+ if (!ng_file_seek_rand(wth, seek_off, err, err_info))
return FALSE;
ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err,
@@ -2480,6 +2475,10 @@ ng_file_read(void *buffer, unsigned int nbytes, wtap *wth, gboolean is_random,
copied_bytes = file_read(buffer, copybytes, infile);
if ((unsigned int) copied_bytes != copybytes)
*err = file_error(infile, err_info);
+ if (copied_bytes != -1) {
+ comp_stream->uncomp_offset += copied_bytes;
+ comp_stream->comp_offset += copied_bytes;
+ }
return copied_bytes;
}
@@ -2630,36 +2629,23 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err,
return 0;
}
-/* Seek in the sequential data stream; we can only seek forward, and we
- do it on compressed files by skipping forward. */
-static gint64
-ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err,
- gchar **err_info)
+/* Skip some number of bytes forward in the sequential stream. */
+static gboolean
+ng_file_skip_seq(wtap *wth, gint64 delta, int *err, gchar **err_info)
{
- gint64 delta;
+ ngsniffer_t *ngsniffer;
char *buf;
unsigned int amount_to_read;
- ngsniffer_t *ngsniffer;
-
- if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED)
- return file_seek(wth->fh, offset, whence, err);
ngsniffer = (ngsniffer_t *)wth->priv;
- switch (whence) {
-
- case SEEK_SET:
- break; /* "offset" is the target offset */
-
- case SEEK_CUR:
- offset += ngsniffer->seq.uncomp_offset;
- break; /* "offset" is relative to the current offset */
- case SEEK_END:
- g_assert_not_reached(); /* "offset" is relative to the end of the file... */
- break; /* ...but we don't know where that is. */
+ if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
+ ngsniffer->seq.uncomp_offset += delta;
+ if (file_skip(wth->fh, delta, err) == -1)
+ return FALSE;
+ return TRUE;
}
- delta = offset - ngsniffer->seq.uncomp_offset;
g_assert(delta >= 0);
/* Ok, now read and discard "delta" bytes. */
@@ -2672,17 +2658,17 @@ ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err,
if (ng_file_read(buf, amount_to_read, wth, FALSE, err, err_info) < 0) {
g_free(buf);
- return -1; /* error */
+ return FALSE; /* error */
}
delta -= amount_to_read;
}
g_free(buf);
- return offset;
+ return TRUE;
}
-/* Seek in the random data stream.
+/* Seek to a given offset in the random data stream.
On compressed files, we see whether we're seeking to a position within
the blob we currently have in memory and, if not, we find in the list
@@ -2690,32 +2676,20 @@ ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err,
we're seeking, and read that blob in. We can then move to the appropriate
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). */
-static gint64
-ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err,
- gchar **err_info)
+static gboolean
+ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info)
{
ngsniffer_t *ngsniffer;
gint64 delta;
GList *new, *next;
blob_info_t *next_blob, *new_blob;
- if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED)
- return file_seek(wth->random_fh, offset, whence, err);
-
ngsniffer = (ngsniffer_t *)wth->priv;
- switch (whence) {
-
- case SEEK_SET:
- break; /* "offset" is the target offset */
-
- case SEEK_CUR:
- offset += ngsniffer->rand.uncomp_offset;
- break; /* "offset" is relative to the current offset */
-
- case SEEK_END:
- g_assert_not_reached(); /* "offset" is relative to the end of the file... */
- break; /* ...but we don't know where that is. */
+ if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
+ if (file_seek(wth->random_fh, offset, SEEK_SET, err) == -1)
+ return FALSE;
+ return TRUE;
}
delta = offset - ngsniffer->rand.uncomp_offset;
diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c
index e8435698d7..ba80f55b63 100644
--- a/wiretap/packetlogger.c
+++ b/wiretap/packetlogger.c
@@ -82,7 +82,6 @@ int packetlogger_open(wtap *wth, int *err, gchar **err_info)
wth->subtype_read = packetlogger_read;
wth->subtype_seek_read = packetlogger_seek_read;
- wth->data_offset = 0;
wth->file_type = WTAP_FILE_PACKETLOGGER;
wth->file_encap = WTAP_ENCAP_PACKETLOGGER;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
@@ -96,7 +95,7 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
packetlogger_header_t pl_hdr;
guint bytes_read;
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
if(!packetlogger_read_header(&pl_hdr, wth->fh, err, err_info))
return FALSE;
@@ -129,8 +128,6 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- wth->data_offset += (pl_hdr.len + 4);
-
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.len = pl_hdr.len - 8;
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index f1a3beb963..cabbd576e5 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -1985,7 +1985,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
wtapng_if_descr_t int_data;
interface_data_t interface_data;
pcapng_block_header_t bh;
-
+ gint64 saved_offset;
pn.shb_read = FALSE;
pn.read_idbs = TRUE; /* IDB expected after SHB */
@@ -2014,7 +2014,6 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += bytes_read;
/* first block must be a "Section Header Block" */
if (wblock.type != BLOCK_TYPE_SHB) {
@@ -2058,7 +2057,6 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
/* Loop over all IDB:s that appear before any packets */
while (1) {
bytes_read = pcapng_read_block(wth->fh, FALSE, &pn, &wblock, err, err_info);
- wth->data_offset += bytes_read;
if (bytes_read == 0) {
pcapng_debug0("No more IDBs available...");
break;
@@ -2109,6 +2107,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
/* peek at next block */
/* Try to read the (next) block header */
+ saved_offset = file_tell(wth->fh);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&bh, sizeof bh, wth->fh);
if (bytes_read == 0) {
@@ -2124,7 +2123,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
}
/* go back to where we were */
- file_seek(wth->fh, wth->data_offset, SEEK_SET, err);
+ file_seek(wth->fh, saved_offset, SEEK_SET, err);
if (pn.byte_swapped) {
bh.block_type = BSWAP32(bh.block_type);
@@ -2153,9 +2152,8 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
wtapng_if_descr_t *wtapng_if_descr;
wtapng_if_stats_t if_stats;
- pcapng_debug1("pcapng_read: wth->data_offset is initially %" G_GINT64_MODIFIER "u", wth->data_offset);
- *data_offset = wth->data_offset;
- pcapng_debug1("pcapng_read: *data_offset is initially set to %" G_GINT64_MODIFIER "u", *data_offset);
+ *data_offset = file_tell(wth->fh);
+ pcapng_debug1("pcapng_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
/* XXX - This should be done in the packet block reading function and
* should make use of the caplen of the packet.
@@ -2178,8 +2176,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
while (1) {
bytes_read = pcapng_read_block(wth->fh, FALSE, pcapng, &wblock, err, err_info);
if (bytes_read <= 0) {
- wth->data_offset = *data_offset;
- pcapng_debug1("pcapng_read: wth->data_offset is finally %" G_GINT64_MODIFIER "u", wth->data_offset);
+ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset);
pcapng_debug0("pcapng_read: couldn't read packet block");
return FALSE;
}
@@ -2191,7 +2188,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
if (wblock.type == BLOCK_TYPE_ISB ) {
pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB");
*data_offset += bytes_read;
- pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "u", *data_offset);
+ pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
if (wth->number_of_interfaces < wblock.data.if_stats.interface_id) {
pcapng_debug1("pcapng_read: BLOCK_TYPE_ISB wblock.if_stats.interface_id %u > number_of_interfaces", wblock.data.if_stats.interface_id);
} else {
@@ -2223,7 +2220,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
/* XXX - improve handling of "unknown" blocks */
pcapng_debug1("pcapng_read: block type 0x%x not PB/EPB", wblock.type);
*data_offset += bytes_read;
- pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "u", *data_offset);
+ pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
}
}
@@ -2233,14 +2230,12 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcapng: interface index %u is not less than interface count %u.",
wblock.data.packet.interface_id, pcapng->number_of_interfaces);
- wth->data_offset = *data_offset + bytes_read;
- pcapng_debug1("pcapng_read: wth->data_offset is finally %" G_GINT64_MODIFIER "u", wth->data_offset);
+ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset + bytes_read);
return FALSE;
}
/*pcapng_debug2("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/
- wth->data_offset = *data_offset + bytes_read;
- pcapng_debug1("pcapng_read: wth->data_offset is finally %" G_GINT64_MODIFIER "u", wth->data_offset);
+ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset + bytes_read);
return TRUE;
}
diff --git a/wiretap/radcom.c b/wiretap/radcom.c
index a81d72ccf0..a70d8ad606 100644
--- a/wiretap/radcom.c
+++ b/wiretap/radcom.c
@@ -130,7 +130,6 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
/* Look for the "Active Time" string. The "frame_date" structure should
* be located 32 bytes before the beginning of this string */
- wth->data_offset = 8;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(t_magic, 11, wth->fh);
if (bytes_read != 11) {
@@ -143,7 +142,6 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
{
if (file_seek(wth->fh, -10, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += 1;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(t_magic, 11, wth->fh);
if (bytes_read != 11) {
@@ -154,7 +152,6 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
}
}
if (file_seek(wth->fh, -43, SEEK_CUR, err) == -1) return -1;
- wth->data_offset -= 32;
/* Get capture start time */
errno = WTAP_ERR_CANT_READ;
@@ -166,7 +163,6 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof(struct frame_date);
/* This is a radcom file */
wth->file_type = WTAP_FILE_RADCOM;
@@ -187,34 +183,28 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
#endif
if (file_seek(wth->fh, sizeof(struct frame_date), SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += sizeof(struct frame_date);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(search_encap, 4, wth->fh);
if (bytes_read != 4) {
goto read_error;
}
- wth->data_offset += 4;
while (memcmp(encap_magic, search_encap, 4)) {
if (file_seek(wth->fh, -3, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset -= 3;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(search_encap, 4, wth->fh);
if (bytes_read != 4) {
goto read_error;
}
- wth->data_offset += 4;
}
if (file_seek(wth->fh, 12, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += 12;
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(search_encap, 4, wth->fh);
if (bytes_read != 4) {
goto read_error;
}
- wth->data_offset += 4;
if (memcmp(search_encap, "LAPB", 4) == 0)
wth->file_encap = WTAP_ENCAP_LAPB;
else if (memcmp(search_encap, "Ethe", 4) == 0)
@@ -249,15 +239,12 @@ int radcom_open(wtap *wth, int *err, gchar **err_info)
if (wth->file_encap == WTAP_ENCAP_ETHERNET) {
if (file_seek(wth->fh, 294, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += 294;
} else if (wth->file_encap == WTAP_ENCAP_LAPB) {
if (file_seek(wth->fh, 297, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += 297;
} else if (wth->file_encap == WTAP_ENCAP_ATM_RFC1483) {
if (file_seek(wth->fh, 504, SEEK_CUR, err) == -1)
return -1;
- wth->data_offset += 504;
}
return 1;
@@ -283,13 +270,12 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
char fcs[2];
/* Read record header. */
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
ret = radcom_read_rec_header(wth->fh, &hdr, err, err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
- wth->data_offset += sizeof hdr;
data_length = pletohs(&hdr.data_length);
if (data_length == 0) {
/*
@@ -344,7 +330,6 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
if (!radcom_read_rec_data(wth->fh, phdr, sizeof phdr, err,
err_info))
return FALSE; /* Read error */
- wth->data_offset += 8;
length -= 8;
wth->phdr.len -= 8;
wth->phdr.caplen -= 8;
@@ -358,7 +343,6 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
if (!radcom_read_rec_data(wth->fh,
buffer_start_ptr(wth->frame_buffer), length, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += length;
if (wth->file_encap == WTAP_ENCAP_LAPB) {
/* Read the FCS.
@@ -373,7 +357,6 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += sizeof fcs;
}
return TRUE;
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index a0296db139..484680fe87 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -259,6 +259,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info)
};
#define NUM_SHOMITI_ENCAPS (sizeof shomiti_encap / sizeof shomiti_encap[0])
int file_encap;
+ gint64 saved_offset;
/* Read in the string that should be at the start of a "snoop" file */
errno = WTAP_ERR_CANT_READ;
@@ -269,7 +270,6 @@ int snoop_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof magic;
if (memcmp(magic, snoop_magic, sizeof snoop_magic) != 0) {
return 0;
@@ -284,7 +284,6 @@ int snoop_open(wtap *wth, int *err, gchar **err_info)
return -1;
return 0;
}
- wth->data_offset += sizeof hdr;
/*
* Make sure it's a version we support.
@@ -337,6 +336,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info)
is_shomiti = FALSE;
/* Read first record header. */
+ saved_offset = file_tell(wth->fh);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&rec_hdr, sizeof rec_hdr, wth->fh);
if (bytes_read != sizeof rec_hdr) {
@@ -389,7 +389,7 @@ int snoop_open(wtap *wth, int *err, gchar **err_info)
/*
* Seek back to the beginning of the first record.
*/
- if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1)
+ if (file_seek(wth->fh, saved_offset, SEEK_SET, err) == -1)
return -1;
hdr.network = g_ntohl(hdr.network);
@@ -479,7 +479,6 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += sizeof hdr;
rec_size = g_ntohl(hdr.rec_len);
orig_size = g_ntohl(hdr.orig_len);
@@ -514,7 +513,7 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
/*
* If this is an ATM packet, the first four bytes are the
@@ -545,7 +544,6 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
rec_size -= (guint32)sizeof (struct snoop_atm_hdr);
orig_size -= (guint32)sizeof (struct snoop_atm_hdr);
packet_size -= (guint32)sizeof (struct snoop_atm_hdr);
- wth->data_offset += sizeof (struct snoop_atm_hdr);
break;
case WTAP_ENCAP_ETHERNET:
@@ -581,7 +579,6 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
rec_size -= header_size;
orig_size -= header_size;
packet_size -= header_size;
- wth->data_offset += header_size;
break;
}
@@ -589,7 +586,6 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
if (!snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
packet_size, err, err_info))
return FALSE; /* Read error */
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
wth->phdr.ts.secs = g_ntohl(hdr.ts_sec);
@@ -636,7 +632,6 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += bytes_read;
padbytes -= bytes_read;
}
diff --git a/wiretap/tnef.c b/wiretap/tnef.c
index f7772509d0..1ab28e2bb0 100644
--- a/wiretap/tnef.c
+++ b/wiretap/tnef.c
@@ -37,17 +37,20 @@
static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
+ gint64 offset;
guint8 *buf;
gint64 file_size;
int packet_size;
*err = 0;
+ offset = file_tell(wth->fh);
+
/* there is only ever one packet */
- if(wth->data_offset)
+ if (offset)
return FALSE;
- *data_offset = wth->data_offset;
+ *data_offset = offset;
if ((file_size = wtap_file_size(wth, err)) == -1)
return FALSE;
@@ -69,8 +72,6 @@ static gboolean tnef_read(wtap *wth, int *err, gchar **err_info, gint64 *data_of
wtap_file_read_expected_bytes(buf, packet_size, wth->fh, err, err_info);
- wth->data_offset += packet_size;
-
wth->phdr.presence_flags = 0; /* no time stamp, no "real length" */
wth->phdr.caplen = packet_size;
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index 7f29072636..fa7a42eefd 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -221,7 +221,6 @@ int toshiba_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_PER_PACKET;
wth->file_type = WTAP_FILE_TOSHIBA;
wth->snapshot_length = 0; /* not known */
@@ -259,7 +258,6 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
if (!parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err, err_info))
return FALSE;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
}
diff --git a/wiretap/visual.c b/wiretap/visual.c
index de10c33f43..0b0e0aebb5 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -266,10 +266,6 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
wth->file_encap = encap;
wth->snapshot_length = pletohs(&vfile_hdr.max_length);
- /* Save the pointer to the beginning of the packet data so
- that the later seek_reads work correctly. */
- wth->data_offset = CAPTUREFILE_HEADER_SIZE;
-
/* Set up the pointers to the handlers for this file type */
wth->subtype_read = visual_read;
wth->subtype_seek_read = visual_seek_read;
@@ -326,7 +322,6 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
}
return FALSE;
}
- wth->data_offset += phdr_size;
/* Get the included length of data. This includes extra headers + payload */
packet_size = pletohs(&vpkt_hdr.incl_len);
@@ -346,7 +341,6 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
}
return FALSE;
}
- wth->data_offset += ahdr_size;
/* Remove ATM header from length of included bytes in capture, as
this header was appended by the processor doing the packet reassembly,
@@ -365,7 +359,7 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
buffer_assure_space(wth->frame_buffer, packet_size);
- *data_offset = wth->data_offset;
+ *data_offset = file_tell(wth->fh);
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
packet_size, wth->fh);
@@ -377,7 +371,6 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- wth->data_offset += packet_size;
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
diff --git a/wiretap/vms.c b/wiretap/vms.c
index 2b02dbf0d0..8173e576cf 100644
--- a/wiretap/vms.c
+++ b/wiretap/vms.c
@@ -265,7 +265,6 @@ int vms_open(wtap *wth, int *err, gchar **err_info)
return -1;
}
- wth->data_offset = 0;
wth->file_encap = WTAP_ENCAP_RAW_IP;
wth->file_type = WTAP_FILE_VMS;
wth->snapshot_length = 0; /* not known */
@@ -308,7 +307,6 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
if (!parse_vms_hex_dump(wth->fh, pkt_len, buf, err, err_info))
return FALSE;
- wth->data_offset = offset;
*data_offset = offset;
return TRUE;
}
diff --git a/wiretap/vwr.c b/wiretap/vwr.c
index f3ef7e24d6..8ccebc1803 100644
--- a/wiretap/vwr.c
+++ b/wiretap/vwr.c
@@ -700,15 +700,12 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
guint16 pkt_len; /* length of radiotap headers */
/* read the next frame record header in the capture file; if no more frames, return */
- /* if we found a frame record, set the data_offset value to the start of the frame */
- /* record (i.e., the record header for the frame) */
if ((ret = vwr_read_rec_header(vwr, wth->fh, &rec_size, &IS_TX, err, err_info)) <= 0) {
*err_info = g_strdup_printf("Record not readable or EOF encountered");
return(FALSE); /* Read error or EOF */
- } else
- wth->data_offset += ret; /* bump offset past header */
+ }
- *data_offset = (wth->data_offset - 16); /* set offset for random seek @PLCP */
+ *data_offset = (file_tell(wth->fh) - 16); /* set offset for random seek @PLCP */
/* got a frame record; read over entire record (frame + trailer) into a local buffer */
/* if we don't get it all, then declare an error, we can't process the frame */
@@ -718,8 +715,6 @@ static gboolean vwr_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*err = WTAP_ERR_SHORT_READ;
return(FALSE);
}
- else
- wth->data_offset += rec_size; /* got it OK, bump to next rec */
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index a6feab666b..94868b309c 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -59,8 +59,6 @@ struct wtap {
GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/
union wtap_pseudo_header pseudo_header;
- gint64 data_offset;
-
void *priv;
subtype_read_func subtype_read;