file_seek() used to be a wrapper around fseek() or gzseek(), both of
authorGuy Harris <guy@alum.mit.edu>
Fri, 4 May 2012 16:56:18 +0000 (16:56 -0000)
committerGuy Harris <guy@alum.mit.edu>
Fri, 4 May 2012 16:56:18 +0000 (16:56 -0000)
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

45 files changed:
wiretap/5views.c
wiretap/aethra.c
wiretap/airopeek9.c
wiretap/ascendtext.c
wiretap/ber.c
wiretap/btsnoop.c
wiretap/catapult_dct2000.c
wiretap/commview.c
wiretap/cosine.c
wiretap/csids.c
wiretap/daintree-sna.c
wiretap/dbs-etherwatch.c
wiretap/dct3trace.c
wiretap/erf.c
wiretap/etherpeek.c
wiretap/eyesdn.c
wiretap/file_access.c
wiretap/hcidump.c
wiretap/i4btrace.c
wiretap/ipfix.c
wiretap/iptrace.c
wiretap/iseries.c
wiretap/k12.c
wiretap/k12text.l
wiretap/lanalyzer.c
wiretap/libpcap.c
wiretap/mime_file.c
wiretap/mpeg.c
wiretap/netmon.c
wiretap/netscaler.c
wiretap/netscreen.c
wiretap/nettl.c
wiretap/network_instruments.c
wiretap/netxray.c
wiretap/ngsniffer.c
wiretap/packetlogger.c
wiretap/pcapng.c
wiretap/radcom.c
wiretap/snoop.c
wiretap/tnef.c
wiretap/toshiba.c
wiretap/visual.c
wiretap/vms.c
wiretap/vwr.c
wiretap/wtap-int.h

index 1ad604204f31ea5afc46037d8f5bf39b7e0c0160..f3cfda1865d5ba568b2b50d6615ba27b7db33620 100644 (file)
@@ -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);
index 44e728c61d6b731ccd5aec0ddd85a99385c75aff..08880823ddd922d672e56aec1dc1d4303f899791 100644 (file)
@@ -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++;
index b322e8bf0481aa0a09235938f4a174857474c04a..a43303774c6c5f98f3e40643809e05bababe7b49 100644 (file)
@@ -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 +
index 569713e0431245966a3c71c873659065e9ba4953..2795a23ca28dfcfd403c2e38e3e1a463634b7275 100644 (file)
@@ -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;
index df0b1687af0fac6a806b544489772dcc9b995306..7b8530955095bb1f19d7593de45fae8c675dc8a7 100644 (file)
 
 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;
index a8e6d80e73859928f0a184e37537e3cbefa8ab48..c9397d556b5477e1c44a2f9bd241e222ab5a8ccc 100644 (file)
@@ -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;
index 28240409f238361a8b5267f89b695aaada8eba72..ef6769d99813308a3acdcccf0e431d6636078b45 100644 (file)
@@ -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];
index a2415fdcd703dcf685e04bc4bd9a33f9489383eb..f3c3e3ecb1edd64e15e93bdd48a7f34adb4f9b15 100644 (file)
@@ -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;
index 022667a357116eda03700a7897ccf11c069db3b3..9121861b3c1800362a59812ab79286d69a0d4d97 100644 (file)
@@ -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;
index 23f97c5749fc1ba62a8322fb855a9692661a3e13..61722f6dcb1ed99224aeae9db0605be2482c6e1c 100644 (file)
@@ -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;
index d52135a8c13d389af338a8a9583205772183b50e..e0b6b0fd8b6ace8534f3bd94aa7d16221f4c615d 100644 (file)
@@ -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;
index 7bc6ff1be6fb84bcb4bc59baf91da8fd5454120c..b07677c480f95d35148dd2cdcf7825a0fe9e2f28 100644 (file)
@@ -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;
 }
index dfc916994a220ffc84b327b7d4b58d0f70f6d6bb..dc8243cf8cc4da7c018d1c779b78d8033cf32889 100644 (file)
@@ -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;
 }
index 213bd1af31976062863b8d9cf104a63133e9364c..4f608c69887a1eff34e9e8bf6eca1251e8dffab9 100644 (file)
@@ -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 );
 
index fb5659c3fd2ef1729999ac9c79bf5b3e43a96012..6f7dac635e26ac099a021b23914778c0bf7f1c2c 100644 (file)
@@ -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;
index 06446a5b3def88049f2c3d649d8bd6a5eb9015d9..ec6373906ff94abd54e4e1b97af444ad52acb4b9 100644 (file)
@@ -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;
 }
index 3178bff1caefff10a0478dbec093e406ea039cd1..c823098f521447d223db1332056d00360c927c28 100644 (file)
@@ -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)) {
 
index fdcc3cb175e11337e5411f84f170643df4c5e052..b2d4c9362499c1aa0df0028f727cc74db864277b 100644 (file)
@@ -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);
index 05b608758370d61b77c05d9b0c5205f0336291b4..0a8e3e438eec223c93bcb07fbe1921e8d87c3338 100644 (file)
@@ -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) {
 
index 07a7c0aceebb692e5f6742b5b9221eb5baeacfd1..e7e0b0ab5b7bf27915eef373b82dc0f7cd57b72e 100644 (file)
@@ -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;
 }
index 3b6c7739e2e49e805ef9ff58dec6a68bd9e54df5..1dca53675d4ac0a0d5d32e0f74b7b3a5d3835596 100644 (file)
@@ -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;
index 37c2742880c46d8d6d2316f59665d6ba79a5c0f0..764f2401ae78dbccd733f94dd9831e26e196855b 100644 (file)
@@ -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;
 }
index a4cbf0c4179f64a88e606111e32e8430acb1c8e2..7be553aafb92e2347083a03c1ee3b9160f38b255 100644 (file)
@@ -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;
index 867725231c25e064afea0d8e1c6ba49ad8e76b2d..40fdd2f4a9b1bdd3eacff54cf7b0808922a60a73 100644 (file)
@@ -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;
index 498855bbef3212de171bc091b26d3e76f37a2ae1..77a688704102dcc1f9426177f70216dda84e6326 100644 (file)
@@ -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]);
index bf2a5aceb005d6c8e8e82f99cfecefdb668dde2c..c509643e7b2eeabdd04428379a9b3dd25da3ea65 100644 (file)
@@ -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;
 
index 90eafcd9c029dec2a6e6320f9100777d99763c90..f3a4561c09bb812f9370a4c2cef01ffb4e944248 100644 (file)
@@ -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;
index fc7f126a6e58caac42b71a2083558a511e8001eb..321f45a69a255a6b46357fd323a5cbd47c6a80a3 100644 (file)
@@ -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;
index d6d179e34fd531e6529ad97a9ebb842f53ae6049..e5253ace55c66f35efdb321df0d89af1cab359cd 100644 (file)
@@ -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,
index f26164314e08ae371c1db6bccad9ebaefdeb6ec4..d4a3cc9db530126553e89a4d2eea15c44115cfb0 100644 (file)
@@ -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;
index d5011c84cef585258089505489ce445d772c6a3e..29ba0fe0c7aa51d20d003900ea5b4bddc73b7427 100644 (file)
@@ -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;
index 83868011bf07a7112ce9ab119e4d81c83606095b..b83c693cf7ee1cc4d2b018fc6b6bc3266ca459d9 100644 (file)
@@ -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;
 }
 
index 7ffa513cd77157abab5b4322cdbbfa774eb213d1..554be28385ff56671350539606123cb9561db88e 100644 (file)
@@ -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;
index 13178ba825c68e315694687eb50034edb327f4ab..f2685e9001892981d6ee2a7c37222879a2dcb121 100644 (file)
@@ -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;
                }
 
@@ -981,13 +984,6 @@ reread:
                return FALSE;
        }
 
-       /*
-        * 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.
         */
@@ -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.
index b2f07d11fe4da26c0fa5066c008c14af1af9ba0e..ec2fe89c9c2552a8240b40d07b1e9d52f8844844 100644 (file)
@@ -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;
        }
 }
 
@@ -1066,17 +1063,21 @@ 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;
index e8435698d7656c53c321e474cf3a8f4e581a5d5d..ba80f55b63a85f3255ba1f2784cc14bd876eea07 100644 (file)
@@ -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;
index f1a3beb963263da99491d4d996490d19369bc23c..cabbd576e5438494c27a9d07c87b523422e9d8c8 100644 (file)
@@ -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;
 }
index a81d72ccf07ae38ea77ac6ddd0363c3feee5e90d..a70d8ad60602b3260c6cebd2f756e50f3bd621f7 100644 (file)
@@ -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;
index a0296db139374600a105effc4a25b267e9c3ca15..484680fe87626eb93acd47a3955aabcb226deb81 100644 (file)
@@ -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;
        }
 
index f7772509d04be409ffad9cafdac95765b6bc8a64..1ab28e2bb001bbe4688c4f2a474c661779a51342 100644 (file)
 
 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;
index 7f2907263637daf94bb8a9df51fa4756d0044324..fa7a42eefd4202d7cf053f610228fdf60ed9f431 100644 (file)
@@ -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;
 }
index de10c33f43d07676f33a1cb572e8685814ae30ef..0b0e0aebb517b2f30f3f1699e9a1262b13fa491e 100644 (file)
@@ -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;
 
index 2b02dbf0d0f44a598cf46c5b6d636fe006d882d2..8173e576cf07a8c734044af4ac434c99be54640a 100644 (file)
@@ -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;
 }
index f3ef7e24d6348d4d59efb690bb75c882b3836464..8ccebc1803cab20a8049b1d97f1a9aaee9feef88 100644 (file)
@@ -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 */
 
     
 
index a6feab666b4a0577a7aac5fd14f0654c453726b7..94868b309c940d6898d03ef69538df3514e23556 100644 (file)
@@ -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;