Change wtap_read() API so that the data offset is set via a pointer, and
authorgram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 7 Sep 2000 05:34:23 +0000 (05:34 +0000)
committergram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 7 Sep 2000 05:34:23 +0000 (05:34 +0000)
a "keep reading" boolean value is returned from the function.
This avoids having to hack around the fact that some file formats truly
do have records that start at offset 0. (i4btrace and csids have no
file header. Neither does the pppdump-style file that I'm looking at right now).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@2392 f5534014-38df-0310-8fa8-9805f1628bb7

17 files changed:
file.c
wiretap/ascend.c
wiretap/csids.c
wiretap/i4btrace.c
wiretap/iptrace.c
wiretap/lanalyzer.c
wiretap/libpcap.c
wiretap/netmon.c
wiretap/nettl.c
wiretap/netxray.c
wiretap/ngsniffer.c
wiretap/radcom.c
wiretap/snoop.c
wiretap/toshiba.c
wiretap/wtap-int.h
wiretap/wtap.c
wiretap/wtap.h

diff --git a/file.c b/file.c
index 929db878ac8589c04b5d98babcb61a2df0f9450a..32895d7a52892ddf3061887abf4bd8f6b9b4d080 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.212 2000/08/24 09:16:39 guy Exp $
+ * $Id: file.c,v 1.213 2000/09/07 05:33:49 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -327,7 +327,7 @@ read_cap_file(capture_file *cf, int *err)
   progbar = create_progress_dlg(load_msg, "Stop", &stop_flag);
   g_free(load_msg);
 
-  while ((data_offset = wtap_read(cf->wth, err)) > 0) {
+  while ((wtap_read(cf->wth, err, &data_offset))) {
     /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
        when we update it, we have to run the GTK+ main loop to get it
        to repaint what's pending, and doing so may involve an "ioctl()"
@@ -466,7 +466,7 @@ continue_tail_cap_file(capture_file *cf, int to_read, int *err)
 
   gtk_clist_freeze(GTK_CLIST(packet_list));
 
-  while (to_read != 0 && (data_offset = wtap_read(cf->wth, err)) > 0) {
+  while (to_read != 0 && (wtap_read(cf->wth, err, &data_offset))) {
     if (cf->state == FILE_READ_ABORTED) {
       /* Well, the user decided to exit Ethereal.  Break out of the
          loop, and let the code below (which is called even if there
@@ -507,7 +507,7 @@ finish_tail_cap_file(capture_file *cf, int *err)
 
   gtk_clist_freeze(GTK_CLIST(packet_list));
 
-  while ((data_offset = wtap_read(cf->wth, err)) > 0) {
+  while ((wtap_read(cf->wth, err, &data_offset))) {
     if (cf->state == FILE_READ_ABORTED) {
       /* Well, the user decided to abort the read.  Break out of the
          loop, and let the code below (which is called even if there
index ae66b75f6b4a1ef29de5a1a14638348cf21e334d..6d31919d9ee4c64fad77eb808369246c04ddf368 100644 (file)
@@ -1,6 +1,6 @@
 /* ascend.c
  *
- * $Id: ascend.c,v 1.17 2000/08/11 13:32:37 deniel Exp $
+ * $Id: ascend.c,v 1.18 2000/09/07 05:34:07 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -99,7 +99,7 @@ static const char ascend_w2magic[] = { 'W', 'D', '_', 'D', 'I', 'A', 'L', 'O', '
 #define ASCEND_W1_SIZE (sizeof ascend_w1magic / sizeof ascend_w1magic[0])
 #define ASCEND_W2_SIZE (sizeof ascend_w2magic / sizeof ascend_w2magic[0])
 
-static int ascend_read(wtap *wth, int *err);
+static gboolean ascend_read(wtap *wth, int *err, int *data_offset);
 static int ascend_seek_read (wtap *wth, int seek_off,
        union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
 static void ascend_close(wtap *wth);
@@ -192,7 +192,7 @@ int ascend_open(wtap *wth, int *err)
 }
 
 /* Read the next packet; called from wtap_loop(). */
-static int ascend_read(wtap *wth, int *err)
+static gboolean ascend_read(wtap *wth, int *err, int *data_offset)
 {
   int offset;
   guint8 *buf = buffer_start_ptr(wth->frame_buffer);
@@ -207,11 +207,11 @@ static int ascend_read(wtap *wth, int *err)
   wth->capture.ascend->seek_add = 0;
   offset = ascend_seek(wth, ASCEND_MAX_SEEK);
   if (offset < 1) {
-    return 0;
+    return FALSE;
   }
   if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) {
     *err = WTAP_ERR_BAD_RECORD;
-    return -1;
+    return FALSE;
   }
 
   buffer_assure_space(wth->frame_buffer, wth->snapshot_length);
@@ -227,7 +227,8 @@ static int ascend_read(wtap *wth, int *err)
   wth->phdr.pkt_encap = wth->file_encap;
   wth->data_offset = offset;
 
-  return offset;
+  *data_offset = offset;
+  return TRUE;
 }
 
 static int ascend_seek_read (wtap *wth, int seek_off,
index 419db2af028f42c37b8c2aea9aa0f9ef774adb3e..fbe2d946bde06b75fb28926503da2a3b3626646a 100644 (file)
@@ -1,6 +1,6 @@
 /* csids.c
  *
- * $Id: csids.c,v 1.3 2000/08/31 16:44:47 gram Exp $
+ * $Id: csids.c,v 1.4 2000/09/07 05:34:07 gram Exp $
  *
  * Copyright (c) 2000 by Mike Hall <mlh@io.com>
  * Copyright (c) 2000 by Cisco Systems
@@ -44,7 +44,7 @@
  *
  */
 
-static int csids_read(wtap *wth, int *err);
+static gboolean csids_read(wtap *wth, int *err, int *data_offset);
 static int csids_seek_read(wtap *wth, int seek_off,
        union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
 
@@ -140,21 +140,18 @@ int csids_open(wtap *wth, int *err)
 }
 
 /* Find the next packet and parse it; called from wtap_loop(). */
-static int csids_read(wtap *wth, int *err)
+static gboolean csids_read(wtap *wth, int *err, int *data_offset)
 {
   guint8 *buf;
   int bytesRead = 0;
   struct csids_header hdr;
-  int packet_offset = wth->data_offset;
+
+  *data_offset = wth->data_offset;
 
   bytesRead = file_read( &hdr, 1, sizeof( struct csids_header) , wth->fh );
   if( bytesRead != sizeof( struct csids_header) ) {
     *err = file_error( wth->fh );
-    if( *err != 0 ) {
-      return -1;
-    } else {
-      return 0;
-    }
+    return FALSE;
   }
   hdr.seconds = pntohl(&hdr.seconds);
   hdr.caplen = pntohs(&hdr.caplen);
@@ -168,9 +165,7 @@ static int csids_read(wtap *wth, int *err)
   bytesRead = file_read( buf, 1, hdr.caplen, wth->fh );
   if( bytesRead != hdr.caplen ) {
     *err = file_error( wth->fh );
-    if( *err != 0 ) {
-      return -1;
-    }       
+    return FALSE;
   }
   
   wth->data_offset += hdr.caplen;
@@ -188,12 +183,7 @@ static int csids_read(wtap *wth, int *err)
     *(++swap) = BSWAP16(*swap); /* ip flags and fragoff */
   }
 
-  /* This is a hack to fix the fact that have to atleast return 1 
-   * or we stop processing. csids has no file header. We recover from 
-   * this hack in csids_seek_read by checking the seek_off == 1 and 
-   * setting it back to 0.
-   */
-  return packet_offset ? packet_offset : 1;
+  return TRUE;
 }
 
 /* Used to read packets in random-access fashion */
@@ -208,18 +198,7 @@ csids_seek_read (wtap *wth,
   int bytesRead = 0;
   struct csids_header hdr;
 
-  /* hack to fix a problem with the way error checking is done. If the 
-   * the return value from csids_read is 0 for the first packet, then
-   * we stop there. So I return 1. But that messes up the offset for 
-   * the seek_off on this call. So if seek_off is 1 then make it 0 and 
-   * if it is not 1 leave it alone. --mlh 
-   */
-  int real_seek_off = seek_off;
-  if( real_seek_off == 1 ) {
-    real_seek_off = 0;
-  }
-
-  file_seek(wth->random_fh, real_seek_off , SEEK_SET);
+  file_seek(wth->random_fh, seek_off , SEEK_SET);
 
   bytesRead = file_read( &hdr, 1, sizeof( struct csids_header) , wth->random_fh );
   if( bytesRead != sizeof( struct csids_header) ) {
index 12f8aef0eb48fcbabc056beabec038772aa2e6f8..52e487ff08a374919da98ad7daf521b776a1e327 100644 (file)
@@ -1,6 +1,6 @@
 /* i4btrace.c
  *
- * $Id: i4btrace.c,v 1.9 2000/08/25 21:25:37 gram Exp $
+ * $Id: i4btrace.c,v 1.10 2000/09/07 05:34:08 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org>
@@ -31,7 +31,7 @@
 #include "buffer.h"
 #include "i4b_trace.h"
 
-static int i4btrace_read(wtap *wth, int *err);
+static gboolean i4btrace_read(wtap *wth, int *err, int *data_offset);
 static int i4btrace_seek_read(wtap *wth, int seek_off,
     union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
 static int i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err);
@@ -110,26 +110,25 @@ int i4btrace_open(wtap *wth, int *err)
 #define V120SABME      "\010\001\177"
 
 /* Read the next packet */
-static int i4btrace_read(wtap *wth, int *err)
+static gboolean i4btrace_read(wtap *wth, int *err, int *data_offset)
 {
-       int     record_offset;
        int     ret;
        i4b_trace_hdr_t hdr;
        guint16 length;
        void *bufp;
 
        /* Read record header. */
-       record_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        ret = i4b_read_rec_header(wth->fh, &hdr, err);
        if (ret <= 0) {
                /* Read error or EOF */
-               return ret;
+               return FALSE;
        }
        wth->data_offset += sizeof hdr;
        i4b_byte_swap_header(wth, &hdr);
        length = hdr.length - sizeof(hdr);
        if (length == 0)
-               return 0;
+               return FALSE;
 
        wth->phdr.len = length;
        wth->phdr.caplen = length;
@@ -145,7 +144,7 @@ static int i4btrace_read(wtap *wth, int *err)
        buffer_assure_space(wth->frame_buffer, length);
        bufp = buffer_start_ptr(wth->frame_buffer);
        if (i4b_read_rec_data(wth->fh, bufp, length, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += length;
 
        /*
@@ -179,17 +178,7 @@ static int i4btrace_read(wtap *wth, int *err)
                        wth->phdr.pkt_encap = WTAP_ENCAP_NULL;
        }
 
-       /*
-        * XXX - there is no file header for i4btrace files, so the
-        * first record begins at the beginning of the file, hence
-        * its offset is 0.
-        *
-        * Unfortunately, a return value of 0 means "end of file".
-        *
-        * Therefore, we return the record offset + 1, and compensate
-        * for that in "i4btrace_seek_read()".
-        */
-       return record_offset + 1;
+       return TRUE;
 }
 
 static int
@@ -200,11 +189,7 @@ i4btrace_seek_read(wtap *wth, int seek_off,
        int     err;            /* XXX - return this */
        i4b_trace_hdr_t hdr;
 
-       /*
-        * We subtract 1 because we added 1 before returning the record
-        * offset in "i4btrace_read()"; see the comment above.
-        */
-       file_seek(wth->random_fh, seek_off - 1, SEEK_SET);
+       file_seek(wth->random_fh, seek_off, SEEK_SET);
 
        /* Read record header. */
        ret = i4b_read_rec_header(wth->random_fh, &hdr, &err);
index a1793b6a2307aa64363e4a862bb530e7d4318f5b..a2bf913b5800e0a619ddeb9f6e2f37bfef1a8d5d 100644 (file)
@@ -1,6 +1,6 @@
 /* iptrace.c
  *
- * $Id: iptrace.c,v 1.30 2000/08/25 21:25:37 gram Exp $
+ * $Id: iptrace.c,v 1.31 2000/09/07 05:34:09 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
 #include "buffer.h"
 #include "iptrace.h"
 
-static int iptrace_read_1_0(wtap *wth, int *err);
+static gboolean iptrace_read_1_0(wtap *wth, int *err, int *data_offset);
 static int iptrace_seek_read_1_0(wtap *wth, int seek_off,
     union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
-static int iptrace_read_2_0(wtap *wth, int *err);
+
+static gboolean iptrace_read_2_0(wtap *wth, int *err, int *data_offset);
 static int iptrace_seek_read_2_0(wtap *wth, int seek_off,
     union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
+
 static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
     int *err);
 static int iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size,
@@ -96,9 +98,8 @@ typedef struct {
 } iptrace_1_0_phdr;
 
 /* Read the next packet */
-static int iptrace_read_1_0(wtap *wth, int *err)
+static gboolean iptrace_read_1_0(wtap *wth, int *err, int *data_offset)
 {
-       int                     record_offset;
        int                     ret;
        guint32                 packet_size;
        guint8                  header[30];
@@ -106,11 +107,11 @@ static int iptrace_read_1_0(wtap *wth, int *err)
        iptrace_1_0_phdr        pkt_hdr;
 
        /* Read the descriptor data */
-       record_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        ret = iptrace_read_rec_header(wth->fh, header, 30, err);
        if (ret <= 0) {
                /* Read error or EOF */
-               return ret;
+               return FALSE;
        }
        wth->data_offset += 30;
 
@@ -119,7 +120,7 @@ static int iptrace_read_1_0(wtap *wth, int *err)
        buffer_assure_space( wth->frame_buffer, packet_size );
        data_ptr = buffer_start_ptr( wth->frame_buffer );
        if (iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += packet_size;
 
        wth->phdr.len = packet_size;
@@ -139,7 +140,7 @@ static int iptrace_read_1_0(wtap *wth, int *err)
                g_message("iptrace: interface type IFT=0x%02x unknown or unsupported",
                    pkt_hdr.if_type);
                *err = WTAP_ERR_UNSUPPORTED_ENCAP;
-               return -1;
+               return FALSE;
        }
 
        if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) {
@@ -159,7 +160,7 @@ static int iptrace_read_1_0(wtap *wth, int *err)
                        wth->file_encap = WTAP_ENCAP_PER_PACKET;
        }
 
-       return record_offset;
+       return TRUE;
 }
 
 static int iptrace_seek_read_1_0(wtap *wth, int seek_off,
@@ -205,9 +206,8 @@ typedef struct {
 } iptrace_2_0_phdr;
 
 /* Read the next packet */
-static int iptrace_read_2_0(wtap *wth, int *err)
+static gboolean iptrace_read_2_0(wtap *wth, int *err, int *data_offset)
 {
-       int                     record_offset;
        int                     ret;
        guint32                 packet_size;
        guint8                  header[40];
@@ -215,11 +215,11 @@ static int iptrace_read_2_0(wtap *wth, int *err)
        iptrace_2_0_phdr        pkt_hdr;
 
        /* Read the descriptor data */
-       record_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        ret = iptrace_read_rec_header(wth->fh, header, 40, err);
        if (ret <= 0) {
                /* Read error or EOF */
-               return ret;
+               return FALSE;
        }
        wth->data_offset += 40;
 
@@ -228,7 +228,7 @@ static int iptrace_read_2_0(wtap *wth, int *err)
        buffer_assure_space( wth->frame_buffer, packet_size );
        data_ptr = buffer_start_ptr( wth->frame_buffer );
        if (iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += packet_size;
 
        /* AIX saves time in nsec, not usec. It's easier to make iptrace
@@ -252,7 +252,7 @@ static int iptrace_read_2_0(wtap *wth, int *err)
                g_message("iptrace: interface type IFT=0x%02x unknown or unsupported",
                    pkt_hdr.if_type);
                *err = WTAP_ERR_UNSUPPORTED_ENCAP;
-               return -1;
+               return FALSE;
        }
 
        if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) {
@@ -272,7 +272,7 @@ static int iptrace_read_2_0(wtap *wth, int *err)
                        wth->file_encap = WTAP_ENCAP_PER_PACKET;
        }
 
-       return record_offset;
+       return TRUE;
 }
 
 static int iptrace_seek_read_2_0(wtap *wth, int seek_off,
index bf2966fc82c5e65cbbf7746e01824a42781e43e6..4df14843c97669020d1f7623a4810ddb56fc5f34 100644 (file)
@@ -1,6 +1,6 @@
 /* lanalyzer.c
  *
- * $Id: lanalyzer.c,v 1.24 2000/08/25 21:25:38 gram Exp $
+ * $Id: lanalyzer.c,v 1.25 2000/09/07 05:34:10 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -47,7 +47,7 @@
 #define BOARD_325              226     /* LANalyzer 325 (Ethernet) */
 #define BOARD_325TR            227     /* LANalyzer 325TR (Token-ring) */
 
-static int lanalyzer_read(wtap *wth, int *err);
+static gboolean lanalyzer_read(wtap *wth, int *err, int *data_offset);
 static void lanalyzer_close(wtap *wth);
 
 int lanalyzer_open(wtap *wth, int *err)
@@ -199,7 +199,7 @@ int lanalyzer_open(wtap *wth, int *err)
 #define DESCRIPTOR_LEN 32
 
 /* Read the next packet */
-static int lanalyzer_read(wtap *wth, int *err)
+static gboolean lanalyzer_read(wtap *wth, int *err, int *data_offset)
 {
        int             packet_size = 0;
        int             bytes_read;
@@ -207,7 +207,6 @@ static int lanalyzer_read(wtap *wth, int *err)
        char            LE_record_length[2];
        guint16         record_type, record_length;
        gchar           descriptor[DESCRIPTOR_LEN];
-       int             data_offset;
        guint16         time_low, time_med, time_high, true_size;
        double          t;
 
@@ -216,13 +215,10 @@ static int lanalyzer_read(wtap *wth, int *err)
        bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
        if (bytes_read != 2) {
                *err = file_error(wth->fh);
-               if (*err != 0)
-                       return -1;
-               if (bytes_read != 0) {
+               if (*err == 0 && bytes_read != 0) {
                        *err = WTAP_ERR_SHORT_READ;
-                       return -1;
                }
-               return 0;
+               return FALSE;
        }
        wth->data_offset += 2;
        bytes_read = file_read(LE_record_length, 1, 2, wth->fh);
@@ -230,7 +226,7 @@ static int lanalyzer_read(wtap *wth, int *err)
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               return FALSE;
        }
        wth->data_offset += 2;
 
@@ -244,7 +240,7 @@ static int lanalyzer_read(wtap *wth, int *err)
                g_message("lanalyzer: record type %u seen after trace summary record",
                    record_type);
                *err = WTAP_ERR_BAD_RECORD;
-               return -1;
+               return FALSE;
        }
        else {
                packet_size = record_length - DESCRIPTOR_LEN;
@@ -257,13 +253,13 @@ static int lanalyzer_read(wtap *wth, int *err)
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               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 = wth->data_offset;
        errno = WTAP_ERR_CANT_READ;
        bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
                packet_size, wth->fh);
@@ -272,7 +268,7 @@ static int lanalyzer_read(wtap *wth, int *err)
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               return FALSE;
        }
        wth->data_offset += packet_size;
 
@@ -294,7 +290,7 @@ static int lanalyzer_read(wtap *wth, int *err)
        wth->phdr.caplen = packet_size;
        wth->phdr.pkt_encap = wth->file_encap;
 
-       return data_offset;
+       return TRUE;
 }
 
 static void
index 539ca4c83ef19bea1ba445c3d41cfe871512f131..9c52fa48110109798c67d6ec10303ce1e65039f3 100644 (file)
@@ -1,6 +1,6 @@
 /* libpcap.c
  *
- * $Id: libpcap.c,v 1.38 2000/08/25 06:25:21 guy Exp $
+ * $Id: libpcap.c,v 1.39 2000/09/07 05:34:11 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -38,7 +38,7 @@
 #define BIT_SWAPPED_MAC_ADDRS
 #endif
 
-static int libpcap_read(wtap *wth, int *err);
+static gboolean libpcap_read(wtap *wth, int *err, int *data_offset);
 static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr);
 static void libpcap_close(wtap *wth);
 static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
@@ -453,12 +453,11 @@ give_up:
 }
 
 /* Read the next packet */
-static int libpcap_read(wtap *wth, int *err)
+static gboolean libpcap_read(wtap *wth, int *err, int *data_offset)
 {
        guint   packet_size;
        int     bytes_to_read, bytes_read;
        struct pcaprec_ss990915_hdr hdr;
-       int     data_offset;
 
        /* Read record header. */
        errno = WTAP_ERR_CANT_READ;
@@ -484,13 +483,10 @@ static int libpcap_read(wtap *wth, int *err)
        bytes_read = file_read(&hdr, 1, bytes_to_read, wth->fh);
        if (bytes_read != bytes_to_read) {
                *err = file_error(wth->fh);
-               if (*err != 0)
-                       return -1;
-               if (bytes_read != 0) {
+               if (*err == 0 && bytes_read != 0) {
                        *err = WTAP_ERR_SHORT_READ;
-                       return -1;
                }
-               return 0;
+               return FALSE;
        }
        wth->data_offset += bytes_read;
 
@@ -505,11 +501,11 @@ static int libpcap_read(wtap *wth, int *err)
                g_message("pcap: File has %u-byte packet, bigger than maximum of %u",
                    packet_size, WTAP_MAX_PACKET_SIZE);
                *err = WTAP_ERR_BAD_RECORD;
-               return -1;
+               return FALSE;
        }
 
        buffer_assure_space(wth->frame_buffer, packet_size);
-       data_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        errno = WTAP_ERR_CANT_READ;
        bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
                        packet_size, wth->fh);
@@ -518,7 +514,7 @@ static int libpcap_read(wtap *wth, int *err)
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               return FALSE;
        }
        wth->data_offset += packet_size;
 
@@ -528,7 +524,7 @@ static int libpcap_read(wtap *wth, int *err)
        wth->phdr.len = hdr.hdr.orig_len;
        wth->phdr.pkt_encap = wth->file_encap;
 
-       return data_offset;
+       return TRUE;
 }
 
 static void
index 603982d8d0d13c19c618789b6fea99235bf54794..337c4a8c34b22be5df6e5a6c1da7854d3c6b4261 100644 (file)
@@ -1,6 +1,6 @@
 /* netmon.c
  *
- * $Id: netmon.c,v 1.32 2000/08/25 21:25:39 gram Exp $
+ * $Id: netmon.c,v 1.33 2000/09/07 05:34:12 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -93,7 +93,7 @@ struct netmonrec_2_x_hdr {
        guint32 incl_len;       /* number of octets captured in file */
 };
 
-static int netmon_read(wtap *wth, int *err);
+static gboolean netmon_read(wtap *wth, int *err, int *data_offset);
 static void netmon_close(wtap *wth);
 static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
     const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err);
@@ -277,7 +277,7 @@ int netmon_open(wtap *wth, int *err)
 }
 
 /* Read the next packet */
-static int netmon_read(wtap *wth, int *err)
+static gboolean netmon_read(wtap *wth, int *err, int *data_offset)
 {
        netmon_t *netmon = wth->capture.netmon;
        guint32 packet_size = 0;
@@ -287,7 +287,7 @@ static int netmon_read(wtap *wth, int *err)
                struct netmonrec_2_x_hdr hdr_2_x;
        }       hdr;
        int     hdr_size = 0;
-       int     data_offset;
+       int     rec_offset;
        time_t  secs;
        guint32 usecs;
        double  t;
@@ -305,9 +305,9 @@ static int netmon_read(wtap *wth, int *err)
           not there already (seeking to the current position
           may still cause a seek and a read of the underlying file,
           so we don't want to do it unconditionally). */
-       data_offset = netmon->frame_table[netmon->current_frame];
-       if (wth->data_offset != data_offset) {
-               wth->data_offset = data_offset;
+       rec_offset = netmon->frame_table[netmon->current_frame];
+       if (wth->data_offset != rec_offset) {
+               wth->data_offset = rec_offset;
                file_seek(wth->fh, wth->data_offset, SEEK_SET);
        }
        netmon->current_frame++;
@@ -328,13 +328,10 @@ static int netmon_read(wtap *wth, int *err)
        bytes_read = file_read(&hdr, 1, hdr_size, wth->fh);
        if (bytes_read != hdr_size) {
                *err = file_error(wth->fh);
-               if (*err != 0)
-                       return -1;
-               if (bytes_read != 0) {
+               if (*err == 0 && bytes_read != 0) {
                        *err = WTAP_ERR_SHORT_READ;
-                       return -1;
                }
-               return 0;
+               return FALSE;
        }
        wth->data_offset += hdr_size;
 
@@ -356,10 +353,10 @@ static int netmon_read(wtap *wth, int *err)
                g_message("netmon: File has %u-byte packet, bigger than maximum of %u",
                    packet_size, WTAP_MAX_PACKET_SIZE);
                *err = WTAP_ERR_BAD_RECORD;
-               return -1;
+               return FALSE;
        }
        buffer_assure_space(wth->frame_buffer, packet_size);
-       data_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        errno = WTAP_ERR_CANT_READ;
        bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
                        packet_size, wth->fh);
@@ -368,7 +365,7 @@ static int netmon_read(wtap *wth, int *err)
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               return FALSE;
        }
        wth->data_offset += packet_size;
 
@@ -401,7 +398,7 @@ static int netmon_read(wtap *wth, int *err)
        }
        wth->phdr.pkt_encap = wth->file_encap;
 
-       return data_offset;
+       return TRUE;
 }
 
 static void
index 3bd86d378e30192ce873a5c392457a2a7efcd797..314ab95a966818b1b6f04c360d1d4348a33b6908 100644 (file)
@@ -1,6 +1,6 @@
 /* nettl.c
  *
- * $Id: nettl.c,v 1.15 2000/08/25 21:25:40 gram Exp $
+ * $Id: nettl.c,v 1.16 2000/09/07 05:34:13 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -63,7 +63,7 @@ struct nettlrec_ns_ls_ip_hdr {
 
 /* header is followed by data and once again the total length (2 bytes) ! */
 
-static int nettl_read(wtap *wth, int *err);
+static gboolean nettl_read(wtap *wth, int *err, int *data_offset);
 static int nettl_seek_read(wtap *wth, int seek_off,
                union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
 static int nettl_read_rec_header(wtap *wth, FILE_T fh,
@@ -122,18 +122,17 @@ int nettl_open(wtap *wth, int *err)
 }
 
 /* Read the next packet */
-static int nettl_read(wtap *wth, int *err)
+static gboolean nettl_read(wtap *wth, int *err, int *data_offset)
 {
-    int record_offset;
     int ret;
 
     /* Read record header. */
-    record_offset = wth->data_offset;
+    *data_offset = wth->data_offset;
     ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->pseudo_header,
         err);
     if (ret <= 0) {
        /* Read error or EOF */
-       return ret;
+       return FALSE;
     }
     wth->data_offset += ret;
 
@@ -143,9 +142,9 @@ static int nettl_read(wtap *wth, int *err)
     buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
     if (nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
                wth->phdr.caplen, err) < 0)
-       return -1;      /* Read error */
+       return FALSE;   /* Read error */
     wth->data_offset += wth->phdr.caplen;
-    return record_offset;
+    return TRUE;
 }
 
 static int
index ed513be5f6aa2068a8a15716432cc451df8cce4a..061387ff7e3a808c03a557b4a3e89fb624c1d1b4 100644 (file)
@@ -1,6 +1,6 @@
 /* netxray.c
  *
- * $Id: netxray.c,v 1.30 2000/08/25 21:25:40 gram Exp $
+ * $Id: netxray.c,v 1.31 2000/09/07 05:34:14 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -93,7 +93,7 @@ struct netxrayrec_2_x_hdr {
        guint32 xxx[7];         /* unknown */
 };
 
-static int netxray_read(wtap *wth, int *err);
+static gboolean netxray_read(wtap *wth, int *err, int *data_offset);
 static void netxray_close(wtap *wth);
 static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
        const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err);
@@ -219,7 +219,7 @@ int netxray_open(wtap *wth, int *err)
 }
 
 /* Read the next packet */
-static int netxray_read(wtap *wth, int *err)
+static gboolean netxray_read(wtap *wth, int *err, int *data_offset)
 {
        guint32 packet_size;
        int     bytes_read;
@@ -228,14 +228,13 @@ static int netxray_read(wtap *wth, int *err)
                struct netxrayrec_2_x_hdr hdr_2_x;
        }       hdr;
        int     hdr_size = 0;
-       int     data_offset;
        double  t;
 
 reread:
        /* Have we reached the end of the packet data? */
        if (wth->data_offset == wth->capture.netxray->end_offset) {
                /* Yes. */
-               return 0;
+               return FALSE;
        }
        /* Read record header. */
        switch (wth->capture.netxray->version_major) {
@@ -253,10 +252,10 @@ reread:
        if (bytes_read != hdr_size) {
                *err = file_error(wth->fh);
                if (*err != 0)
-                       return -1;
+                       return FALSE;
                if (bytes_read != 0) {
                        *err = WTAP_ERR_SHORT_READ;
-                       return -1;
+                       return FALSE;
                }
 
                /* We're at EOF.  Wrap? */
@@ -269,13 +268,13 @@ reread:
                }
 
                /* We've already wrapped - don't wrap again. */
-               return 0;
+               return FALSE;
        }
        wth->data_offset += hdr_size;
 
        packet_size = pletohs(&hdr.hdr_1_x.incl_len);
        buffer_assure_space(wth->frame_buffer, packet_size);
-       data_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        errno = WTAP_ERR_CANT_READ;
        bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1,
                        packet_size, wth->fh);
@@ -284,7 +283,7 @@ reread:
                *err = file_error(wth->fh);
                if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               return -1;
+               return FALSE;
        }
        wth->data_offset += packet_size;
 
@@ -299,7 +298,7 @@ reread:
        wth->phdr.len = pletohs(&hdr.hdr_1_x.orig_len);
        wth->phdr.pkt_encap = wth->file_encap;
 
-       return data_offset;
+       return TRUE;
 }
 
 static void
index bd11b9253c3c76fcfef2afb0aeaa054094c7c680..898806c5fca08a36e23938905181f156555b9990 100644 (file)
@@ -1,6 +1,6 @@
 /* ngsniffer.c
  *
- * $Id: ngsniffer.c,v 1.50 2000/08/25 21:25:41 gram Exp $
+ * $Id: ngsniffer.c,v 1.51 2000/09/07 05:34:16 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -250,7 +250,7 @@ struct frame4_rec {
 static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 };
 
 static int skip_header_records(wtap *wth, int *err, gint16 version);
-static int ngsniffer_read(wtap *wth, int *err);
+static gboolean ngsniffer_read(wtap *wth, int *err, int *data_offset);
 static int ngsniffer_seek_read(wtap *wth, int seek_off,
     union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size);
 static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
@@ -533,9 +533,8 @@ skip_header_records(wtap *wth, int *err, gint16 version)
 }
 
 /* Read the next packet */
-static int ngsniffer_read(wtap *wth, int *err)
+static gboolean ngsniffer_read(wtap *wth, int *err, int *data_offset)
 {
-       int     record_offset;
        int     ret;
        guint16 type, length;
        struct frame2_rec frame2;
@@ -548,12 +547,12 @@ static int ngsniffer_read(wtap *wth, int *err)
                /*
                 * Read the record header.
                 */
-               record_offset = wth->data_offset;
+               *data_offset = wth->data_offset;
                ret = ngsniffer_read_rec_header(wth, FALSE, &type, &length,
                    err);
                if (ret <= 0) {
                        /* Read error or EOF */
-                       return ret;
+                       return FALSE;
                }
                wth->data_offset += 6;
 
@@ -567,14 +566,14 @@ static int ngsniffer_read(wtap *wth, int *err)
                                 */
                                g_message("ngsniffer: REC_FRAME2 record in an ATM Sniffer file");
                                *err = WTAP_ERR_BAD_RECORD;
-                               return -1;
+                               return FALSE;
                        }
 
                        /* Read the f_frame2_struct */
                        ret = ngsniffer_read_frame2(wth, FALSE, &frame2, err);
                        if (ret < 0) {
                                /* Read error */
-                               return ret;
+                               return FALSE;
                        }
                        wth->data_offset += sizeof frame2;
                        time_low = pletohs(&frame2.time_low);
@@ -599,7 +598,7 @@ static int ngsniffer_read(wtap *wth, int *err)
                                 */
                                g_message("ngsniffer: REC_FRAME4 record in a non-ATM Sniffer file");
                                *err = WTAP_ERR_BAD_RECORD;
-                               return -1;
+                               return FALSE;
                        }
 
                        /* Read the f_frame4_struct */
@@ -627,7 +626,7 @@ static int ngsniffer_read(wtap *wth, int *err)
                        /*
                         * End of file.  Return an EOF indication.
                         */
-                       return 0;
+                       return FALSE;
 
                default:
                        break;  /* unknown type, skip it */
@@ -652,7 +651,7 @@ found:
        buffer_assure_space(wth->frame_buffer, length);
        pd = buffer_start_ptr(wth->frame_buffer);
        if (ngsniffer_read_rec_data(wth, FALSE, pd, length, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += length;
 
        if (wth->file_encap == WTAP_ENCAP_UNKNOWN) {
@@ -685,7 +684,7 @@ found:
        wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec))
                        *1.0e6);
        wth->phdr.pkt_encap = wth->file_encap;
-       return record_offset;
+       return TRUE;
 }
 
 static int ngsniffer_seek_read(wtap *wth, int seek_off,
index 4d559fc4b366baeeb7463871d1f63e369a5ee204..23cb8fdfa9b4fd041775a455e910c305a2349277 100644 (file)
@@ -1,6 +1,6 @@
 /* radcom.c
  *
- * $Id: radcom.c,v 1.25 2000/08/25 21:25:42 gram Exp $
+ * $Id: radcom.c,v 1.26 2000/09/07 05:34:18 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -66,7 +66,7 @@ struct radcomrec_hdr {
        char    xxw[9];         /* unknown */
 };
 
-static int radcom_read(wtap *wth, int *err);
+static gboolean radcom_read(wtap *wth, int *err, int *data_offset);
 static int radcom_seek_read(wtap *wth, int seek_off,
        union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
 static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr,
@@ -221,9 +221,8 @@ read_error:
 }
 
 /* Read the next packet */
-static int radcom_read(wtap *wth, int *err)
+static gboolean radcom_read(wtap *wth, int *err, int *data_offset)
 {
-       int     record_offset;
        int     ret;
        struct radcomrec_hdr hdr;
        guint16 length;
@@ -233,15 +232,15 @@ static int radcom_read(wtap *wth, int *err)
        char    fcs[2];
 
        /* Read record header. */
-       record_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
        ret = radcom_read_rec_header(wth->fh, &hdr, err);
        if (ret <= 0) {
                /* Read error or EOF */
-               return ret;
+               return FALSE;
        }
        wth->data_offset += sizeof hdr;
        length = pletohs(&hdr.length);
-       if (length == 0) return 0;
+       if (length == 0) return FALSE;
 
        if (wth->file_encap == WTAP_ENCAP_LAPB)
                length -= 2; /* FCS */
@@ -267,7 +266,7 @@ static int radcom_read(wtap *wth, int *err)
        buffer_assure_space(wth->frame_buffer, length);
        if (radcom_read_rec_data(wth->fh,
            buffer_start_ptr(wth->frame_buffer), length, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += length;
 
        wth->phdr.pkt_encap = wth->file_encap;
@@ -281,12 +280,12 @@ static int radcom_read(wtap *wth, int *err)
                        *err = file_error(wth->fh);
                        if (*err == 0)
                                *err = WTAP_ERR_SHORT_READ;
-                       return -1;
+                       return FALSE;
                }
                wth->data_offset += sizeof fcs;
        }
 
-       return record_offset;
+       return TRUE;
 }
 
 static int
index 3d247bce21ecc37f972a698f2f9c80c9407241a1..14a590136a3234553d1f32247c251fcaee661ebd 100644 (file)
@@ -1,6 +1,6 @@
 /* snoop.c
  *
- * $Id: snoop.c,v 1.29 2000/07/26 00:20:06 guy Exp $
+ * $Id: snoop.c,v 1.30 2000/09/07 05:34:19 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -55,7 +55,7 @@ struct snooprec_hdr {
        guint32 ts_usec;        /* timestamp microseconds */
 };
 
-static int snoop_read(wtap *wth, int *err);
+static gboolean snoop_read(wtap *wth, int *err, int *data_offset);
 static int snoop_seek_read(wtap *wth, int seek_off,
     union wtap_pseudo_header *pseudo_header, u_char *pd, int length);
 static int snoop_read_atm_pseudoheader(FILE_T fh,
@@ -206,12 +206,11 @@ int snoop_open(wtap *wth, int *err)
 }
 
 /* Read the next packet */
-static int snoop_read(wtap *wth, int *err)
+static gboolean snoop_read(wtap *wth, int *err, int *data_offset)
 {
        guint32 rec_size;
        guint32 packet_size;
        guint32 orig_size;
-       int     data_offset;
        int     bytes_read;
        struct snooprec_hdr hdr;
        char    padbuf[4];
@@ -223,13 +222,10 @@ static int snoop_read(wtap *wth, int *err)
        bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
        if (bytes_read != sizeof hdr) {
                *err = file_error(wth->fh);
-               if (*err != 0)
-                       return -1;
-               if (bytes_read != 0) {
+               if (*err == 0 && bytes_read != 0) {
                        *err = WTAP_ERR_SHORT_READ;
-                       return -1;
                }
-               return 0;
+               return FALSE;
        }
        wth->data_offset += sizeof hdr;
 
@@ -244,10 +240,10 @@ static int snoop_read(wtap *wth, int *err)
                g_message("snoop: File has %u-byte packet, bigger than maximum of %u",
                    packet_size, WTAP_MAX_PACKET_SIZE);
                *err = WTAP_ERR_BAD_RECORD;
-               return -1;
+               return FALSE;
        }
 
-       data_offset = wth->data_offset;
+       *data_offset = wth->data_offset;
 
        /*
         * If this is an ATM packet, the first four bytes are the
@@ -264,11 +260,11 @@ static int snoop_read(wtap *wth, int *err)
                        g_message("snoop: atmsnoop file has a %u-byte packet, too small to have even an ATM pseudo-header\n",
                            packet_size);
                        *err = WTAP_ERR_BAD_RECORD;
-                       return -1;
+                       return FALSE;
                }
                if (snoop_read_atm_pseudoheader(wth->fh, &wth->pseudo_header,
                    err) < 0)
-                       return -1;      /* Read error */
+                       return FALSE;   /* Read error */
 
                /*
                 * Don't count the pseudo-header as part of the packet.
@@ -282,7 +278,7 @@ static int snoop_read(wtap *wth, int *err)
        buffer_assure_space(wth->frame_buffer, packet_size);
        if (snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
            packet_size, err) < 0)
-               return -1;      /* Read error */
+               return FALSE;   /* Read error */
        wth->data_offset += packet_size;
 
        wth->phdr.ts.tv_sec = ntohl(hdr.ts_sec);
@@ -309,13 +305,13 @@ static int snoop_read(wtap *wth, int *err)
                        *err = file_error(wth->fh);
                        if (*err == 0)
                                *err = WTAP_ERR_SHORT_READ;
-                       return -1;
+                       return FALSE;
                }
                wth->data_offset += bytes_read;
                padbytes -= bytes_read;
        }
 
-       return data_offset;
+       return TRUE;
 }
 
 static int
index caa0b6c2497405a9070d27c498020e36f3271d12..407b52dab755df0f02d236770af9298eb35aa04d 100644 (file)
@@ -1,6 +1,6 @@
 /* toshiba.c
  *
- * $Id: toshiba.c,v 1.11 2000/05/19 23:07:03 gram Exp $
+ * $Id: toshiba.c,v 1.12 2000/09/07 05:34:20 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -104,7 +104,7 @@ static const char toshiba_hdr_magic[]  =
 static const char toshiba_rec_magic[]  = { '[', 'N', 'o', '.' };
 #define TOSHIBA_REC_MAGIC_SIZE  (sizeof toshiba_rec_magic  / sizeof toshiba_rec_magic[0])
 
-static int toshiba_read(wtap *wth, int *err);
+static gboolean toshiba_read(wtap *wth, int *err, int *data_offset);
 static int toshiba_seek_read(wtap *wth, int seek_off,
        union wtap_pseudo_header *pseudo_header, guint8 *pd, int len);
 static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset);
@@ -200,7 +200,7 @@ int toshiba_open(wtap *wth, int *err)
 }
 
 /* Find the next packet and parse it; called from wtap_loop(). */
-static int toshiba_read(wtap *wth, int *err)
+static gboolean toshiba_read(wtap *wth, int *err, int *data_offset)
 {
        int     offset = 0;
        guint8  *buf;
@@ -209,7 +209,7 @@ static int toshiba_read(wtap *wth, int *err)
        /* Find the next packet */
        offset = toshiba_seek_next_packet(wth);
        if (offset < 1) {
-               return 0;
+               return FALSE;
        }
 
        /* Parse the header */
@@ -224,7 +224,8 @@ static int toshiba_read(wtap *wth, int *err)
        parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err);
 
        wth->data_offset = offset;
-       return offset;
+       *data_offset = offset;
+       return TRUE;
 }
 
 /* Used to read packets in random-access fashion */
index a8742b1c385f4516d20e334de89c38675ece57b5..44abd47fbbecc23d11bb0fe4316062c987930a7f 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap-int.h
  *
- * $Id: wtap-int.h,v 1.7 2000/08/25 21:25:43 gram Exp $
+ * $Id: wtap-int.h,v 1.8 2000/09/07 05:34:21 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -116,7 +116,7 @@ typedef struct {
        gboolean byteswapped;
 } csids_t;
 
-typedef int (*subtype_read_func)(struct wtap*, int*);
+typedef int (*subtype_read_func)(struct wtap*, int*, int*);
 typedef int (*subtype_seek_read_func)(struct wtap*, int, union wtap_pseudo_header*,
                                        guint8*, int);
 struct wtap {
index 4a79760390cf663e2089314c90315eefb806414d..dd6a34e39e3236418f6fa4e43449cfc63e234639 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.c
  *
- * $Id: wtap.c,v 1.46 2000/08/19 18:31:23 deniel Exp $
+ * $Id: wtap.c,v 1.47 2000/09/07 05:34:22 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
 #include "file_wrappers.h"
 #include "buffer.h"
 
-FILE* wtap_file(wtap *wth)
+FILE*
+wtap_file(wtap *wth)
 {
        return wth->fh;
 }
 
-int wtap_fd(wtap *wth)
+int
+wtap_fd(wtap *wth)
 {
        return wth->fd;
 }
 
-int wtap_file_type(wtap *wth)
+int
+wtap_file_type(wtap *wth)
 {
        return wth->file_type;
 }
 
-int wtap_snapshot_length(wtap *wth)
+int
+wtap_snapshot_length(wtap *wth)
 {
        return wth->snapshot_length;
 }
 
-int wtap_file_encap(wtap *wth)
+int
+wtap_file_encap(wtap *wth)
 {
        return wth->file_encap;
 }
@@ -113,7 +118,8 @@ const static struct encap_type_info {
 };
 
 /* Name that should be somewhat descriptive. */
-const char *wtap_encap_string(int encap)
+const char
+*wtap_encap_string(int encap)
 {
        if (encap < 0 || encap >= WTAP_NUM_ENCAP_TYPES)
                return NULL;
@@ -122,7 +128,8 @@ const char *wtap_encap_string(int encap)
 }
 
 /* Name to use in, say, a command-line flag specifying the type. */
-const char *wtap_encap_short_string(int encap)
+const char
+*wtap_encap_short_string(int encap)
 {
        if (encap < 0 || encap >= WTAP_NUM_ENCAP_TYPES)
                return NULL;
@@ -131,7 +138,8 @@ const char *wtap_encap_short_string(int encap)
 }
 
 /* Translate a short name to a capture file type. */
-int wtap_short_string_to_encap(const char *short_name)
+int
+wtap_short_string_to_encap(const char *short_name)
 {
        int encap;
 
@@ -162,7 +170,8 @@ static const char *wtap_errlist[] = {
 };
 #define        WTAP_ERRLIST_SIZE       (sizeof wtap_errlist / sizeof wtap_errlist[0])
 
-const char *wtap_strerror(int err)
+const char
+*wtap_strerror(int err)
 {
        static char errbuf[128];
        int wtap_errlist_index;
@@ -196,7 +205,8 @@ const char *wtap_strerror(int err)
    
    Instead, if the subtype has a "sequential close" function, we call it,
    to free up stuff used only by the sequential side. */
-void wtap_sequential_close(wtap *wth)
+void
+wtap_sequential_close(wtap *wth)
 {
        if (wth->subtype_sequential_close != NULL)
                (*wth->subtype_sequential_close)(wth);
@@ -213,7 +223,8 @@ void wtap_sequential_close(wtap *wth)
        }
 }
 
-void wtap_close(wtap *wth)
+void
+wtap_close(wtap *wth)
 {
        wtap_sequential_close(wth);
 
@@ -226,47 +237,53 @@ void wtap_close(wtap *wth)
        g_free(wth);
 }
 
-int wtap_read(wtap *wth, int *err)
+gboolean
+wtap_read(wtap *wth, int *err, int *data_offset)
 {
-       return wth->subtype_read(wth, err);
+       return wth->subtype_read(wth, err, data_offset);
 }
 
-struct wtap_pkthdr *wtap_phdr(wtap *wth)
+struct wtap_pkthdr*
+wtap_phdr(wtap *wth)
 {
        return &wth->phdr;
 }
 
-union wtap_pseudo_header *wtap_pseudoheader(wtap *wth)
+union wtap_pseudo_header*
+wtap_pseudoheader(wtap *wth)
 {
        return &wth->pseudo_header;
 }
 
-guint8 *wtap_buf_ptr(wtap *wth)
+guint8*
+wtap_buf_ptr(wtap *wth)
 {
        return buffer_start_ptr(wth->frame_buffer);
 }
 
-int wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user,
-       int *err)
+gboolean
+wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user, int *err)
 {
-       int data_offset, loop = 0;
+       int             data_offset, loop = 0;
 
-       /* Start be clearing error flag */
+       /* Start by clearing error flag */
        *err = 0;
 
-       while ((data_offset = wtap_read(wth, err)) > 0) {
+       while ( (wtap_read(wth, err, &data_offset)) ) {
                callback(user, &wth->phdr, data_offset,
                    &wth->pseudo_header, buffer_start_ptr(wth->frame_buffer));
                if (count > 0 && ++loop >= count)
                        break;
        }
-       if (data_offset < 0)
-               return FALSE;   /* failure */
-       else
+
+       if (*err == 0)
                return TRUE;    /* success */
+       else
+               return FALSE;   /* failure */
 }
 
-int wtap_seek_read(wtap *wth, int seek_off,
+int
+wtap_seek_read(wtap *wth, int seek_off,
        union wtap_pseudo_header *pseudo_header, guint8 *pd, int len)
 {
        return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len);
index 3b248e9ff10375dc903d989568933f0f721f8996..bc429651f8eca1e2c3c80d4937c886ae8c87229a 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.77 2000/08/11 13:32:37 deniel Exp $
+ * $Id: wtap.h,v 1.78 2000/09/07 05:34:23 gram Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -273,8 +273,16 @@ typedef struct wtap_dumper wtap_dumper;
  * a negative number, indicating the type of error, on other failures.
  */
 struct wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random);
-int wtap_loop(wtap *wth, int, wtap_handler, u_char*, int*);
-int wtap_read(wtap *wth, int *err);
+
+/* Returns TRUE if entire loop-reading was successful. If read failure
+ * happened, FALSE is returned and err is set. */
+gboolean wtap_loop(wtap *wth, int, wtap_handler, u_char*, int *err);
+
+/* Returns TRUE if read was successful. FALSE if failure. data_offset is
+ * set the the offset in the file where the data for the read packet is
+ * located. */
+gboolean wtap_read(wtap *wth, int *err, int *data_offset);
+
 struct wtap_pkthdr *wtap_phdr(wtap *wth);
 union wtap_pseudo_header *wtap_pseudoheader(wtap *wth);
 guint8 *wtap_buf_ptr(wtap *wth);