From 8c9edf12800bc6d68894dc457e7ebaf994429da8 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 16 Jun 2013 00:20:00 +0000 Subject: 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 --- wiretap/btsnoop.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'wiretap/btsnoop.c') diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index b5427af934..cb44f4e51a 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -74,12 +74,10 @@ static const gint64 KUnixTimeBase = G_GINT64_CONSTANT(0x00dcddb30f2f8000); /* of static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, guint8 *pd, int length, + struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, gchar **err_info); static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_info); -static gboolean btsnoop_read_rec_data(FILE_T fh, guint8 *pd, int length, - int *err, gchar **err_info); int btsnoop_open(wtap *wth, int *err, gchar **err_info) { @@ -164,17 +162,12 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info, return FALSE; /* Read packet data. */ - buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); - if (!btsnoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - wth->phdr.caplen, err, err_info)) { - return FALSE; /* Read error */ - } - - return TRUE; + return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, + wth->phdr.caplen, err, err_info); } static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, guint8 *pd, int length, + struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, gchar **err_info) { if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) @@ -185,10 +178,8 @@ static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, return FALSE; /* Read packet data. */ - if (!btsnoop_read_rec_data(wth->random_fh, pd, length, err, err_info)) - return FALSE; /* failed */ - - return TRUE; + return wtap_read_packet_bytes(wth->random_fh, buf, length, err, + err_info); } static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh, @@ -258,23 +249,6 @@ static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh, return TRUE; } -static gboolean btsnoop_read_rec_data(FILE_T fh, guint8 *pd, int length, - int *err, gchar **err_info) -{ - int bytes_read; - - errno = WTAP_ERR_CANT_READ; - bytes_read = file_read(pd, length, fh); - - if (bytes_read != length) { - *err = file_error(fh, err_info); - if (*err == 0) - *err = WTAP_ERR_SHORT_READ; - return FALSE; - } - return TRUE; -} - /* Returns 0 if we could write the specified encapsulation type, an error indication otherwise. */ int btsnoop_dump_can_write_encap(int encap) -- cgit v1.2.1