summaryrefslogtreecommitdiff
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
committerGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
commit8c9edf12800bc6d68894dc457e7ebaf994429da8 (patch)
treeec6efefbd4e7f8227a7b96661f721ff4ba2986c3 /wiretap/wtap.c
parent3846abe34d6861c6ee0bba61fcd5baa4d213885c (diff)
downloadwireshark-8c9edf12800bc6d68894dc457e7ebaf994429da8.tar.gz
Have the seek-read routines take a Buffer rather than a guint8 pointer
as the "where to put the packet data" argument. This lets more of the libwiretap code be common between the read and seek-read code paths, and also allows for more flexibility in the "fill in the data" path - we can expand the buffer as needed in both cases. svn path=/trunk/; revision=49949
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r--wiretap/wtap.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index d5ccfdf656..ecff10b716 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -900,6 +900,34 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
}
/*
+ * Read packet data into a Buffer, growing the buffer as necessary.
+ *
+ * This returns an error on a short read, even if the short read hit
+ * the EOF immediately. (The assumption is that each packet has a
+ * header followed by raw packet data, and that we've already read the
+ * header, so if we get an EOF trying to read the packet data, the file
+ * has been cut short, even if the read didn't read any data at all.)
+ */
+gboolean
+wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
+ gchar **err_info)
+{
+ int bytes_read;
+
+ buffer_assure_space(buf, length);
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(buffer_start_ptr(buf), length, fh);
+
+ if (bytes_read < 0 || (guint)bytes_read != length) {
+ *err = file_error(fh, err_info);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*
* Return an approximation of the amount of data we've read sequentially
* from the file so far. (gint64, in case that's 64 bits.)
*/
@@ -923,20 +951,9 @@ wtap_buf_ptr(wtap *wth)
gboolean
wtap_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, guint8 *pd, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info)
{
- phdr->presence_flags = 0;
- phdr->pkt_encap = wth->file_encap;
- phdr->len = phdr->caplen = len;
-
- if (!wth->subtype_seek_read(wth, seek_off, phdr, pd, len, err, err_info))
- return FALSE;
-
- if (phdr->caplen > phdr->len)
- phdr->caplen = phdr->len;
-
- /* g_assert(phdr->pkt_encap != WTAP_ENCAP_PER_PACKET); */
-
- return TRUE;
+ return wth->subtype_seek_read(wth, seek_off, phdr, buf, len,
+ err, err_info);
}