summaryrefslogtreecommitdiff
path: root/wiretap/libpcap.c
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>2000-09-07 05:34:23 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>2000-09-07 05:34:23 +0000
commitf52ffba40709c1d134671eef22086827cdeda0f3 (patch)
tree31fc7f12926ced1a03d1ebd95053a6131039c09b /wiretap/libpcap.c
parente1f3604b376f38c081ff142d54d91aa3f68bd0f8 (diff)
downloadwireshark-f52ffba40709c1d134671eef22086827cdeda0f3.tar.gz
Change wtap_read() API so that the data offset is set via a pointer, and
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). svn path=/trunk/; revision=2392
Diffstat (limited to 'wiretap/libpcap.c')
-rw-r--r--wiretap/libpcap.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index 539ca4c83e..9c52fa4811 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -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