aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-08-19 19:40:00 +0000
committerGuy Harris <guy@alum.mit.edu>2005-08-19 19:40:00 +0000
commit38ec1644e68721d6b5afb84dce1684b943b1aee0 (patch)
tree8ffe4f642463b43885354f4dd755e59b4daf3823 /wiretap
parent06823cdce8a0e63cf888c449a1b37071d622f1c3 (diff)
Add APIs to Wiretap to return the file of the size as supplied by the OS
(so if the file's gzipped, it's *NOT* the size of the file after uncompressing), and an approximation of the amount of that data read sequentially so far. Use those for various progress bars and the like. Make the fstat() in the Ascend trace reader directly use wth->fd, as it's inside Wiretap; that gets rid of the last caller of wtap_fd() (as we're no longer directly using fstat() or lseek() in Ethereal), so get rid of wtap_fd(). svn path=/trunk/; revision=15437
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/ascend.c2
-rw-r--r--wiretap/wtap.c51
-rw-r--r--wiretap/wtap.def3
-rw-r--r--wiretap/wtap.h8
4 files changed, 58 insertions, 6 deletions
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 3b239226ce..5c57279905 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -218,7 +218,7 @@ int ascend_open(wtap *wth, int *err, gchar **err_info _U_)
packet's timestamp from the capture file's ctime, which gives us an
offset that we can apply to each packet.
*/
- if (fstat(wtap_fd(wth), &statbuf) == -1) {
+ if (fstat(wth->fd, &statbuf) == -1) {
*err = errno;
g_free(wth->capture.ascend);
return -1;
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 8876b9c060..727c77d286 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -27,14 +27,41 @@
#include <string.h>
#include <errno.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+
#include "wtap-int.h"
#include "file_wrappers.h"
#include "buffer.h"
-int
-wtap_fd(wtap *wth)
+/*
+ * Return the size of the file, as reported by the OS.
+ * (gint64, in case that's 64 bits.)
+ */
+gint64
+wtap_file_size(wtap *wth, int *err)
{
- return wth->fd;
+ struct stat statb;
+
+ if (fstat(wth->fd, &statb) == -1) {
+ if (err != NULL)
+ *err = errno;
+ return -1;
+ }
+ return statb.st_size;
}
int
@@ -465,6 +492,24 @@ wtap_read(wtap *wth, int *err, gchar **err_info, long *data_offset)
return TRUE; /* success */
}
+/*
+ * Return an approximation of the amount of data we've read sequentially
+ * from the file so far. (gint64, in case that's 64 bits.)
+ */
+gint64
+wtap_read_so_far(wtap *wth, int *err)
+{
+ off_t file_pos;
+
+ file_pos = lseek(wth->fd, 0, SEEK_CUR);
+ if (file_pos == -1) {
+ if (err != NULL)
+ *err = errno;
+ return -1;
+ }
+ return file_pos;
+}
+
struct wtap_pkthdr*
wtap_phdr(wtap *wth)
{
diff --git a/wiretap/wtap.def b/wiretap/wtap.def
index 1554ebefc4..1e314db475 100644
--- a/wiretap/wtap.def
+++ b/wiretap/wtap.def
@@ -10,8 +10,8 @@ wtap_dump_file
wtap_dump_open
wtap_encap_short_string
wtap_encap_string
-wtap_fd
wtap_file_encap
+wtap_file_size
wtap_file_type
wtap_file_type_short_string
wtap_file_type_string
@@ -23,6 +23,7 @@ wtap_phdr
wtap_process_pcap_packet
wtap_pseudoheader
wtap_read
+wtap_read_so_far
wtap_seek_read
wtap_sequential_close
wtap_short_string_to_encap
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 8008dde650..b828a7e4b6 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -523,11 +523,17 @@ struct wtap* wtap_open_offline(const char *filename, int *err,
gboolean wtap_read(wtap *wth, int *err, gchar **err_info,
long *data_offset);
+/*
+ * Return an approximation of the amount of data we've read sequentially
+ * from the file so far. (gint64, in case that's 64 bits.)
+ */
+gint64 wtap_read_so_far(wtap *wth, int *err);
+
struct wtap_pkthdr *wtap_phdr(wtap *wth);
union wtap_pseudo_header *wtap_pseudoheader(wtap *wth);
guint8 *wtap_buf_ptr(wtap *wth);
-int wtap_fd(wtap *wth);
+gint64 wtap_file_size(wtap *wth, int *err);
int wtap_snapshot_length(wtap *wth); /* per file */
int wtap_file_type(wtap *wth);
int wtap_file_encap(wtap *wth);