From Martin Mathieson:
[obnox/wireshark/wip.git] / wiretap / wtap.c
index 9c5ff2042c01d7449b19413e37dd604278e3cf53..c410e13190c1760fc3df07472d2dde25b2fa4e40 100644 (file)
 #include <string.h>
 #include <errno.h>
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #include "wtap-int.h"
+#include "wtap.h"
+
 #include "file_wrappers.h"
+#include "file_util.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
@@ -55,6 +77,12 @@ wtap_file_encap(wtap *wth)
        return wth->file_encap;
 }
 
+int
+wtap_file_tsprecision(wtap *wth)
+{
+       return wth->tsprecision;
+}
+
 /* Table of the encapsulation types we know about. */
 static const struct encap_type_info {
        const char *name;
@@ -258,6 +286,9 @@ static const struct encap_type_info {
        /* WTAP_ENCAP_NETTL_RAW_ICMPV6 */
        { "Raw ICMPv6 with nettl headers", "raw-icmpv6-nettl" },
 
+       /* UNUSED */
+       { "", "" },
+
        /* WTAP_ENCAP_GPRS_LLC */
        { "GPRS LLC", "gprs-llc" },
 
@@ -284,6 +315,51 @@ static const struct encap_type_info {
 
        /* WTAP_ENCAP_NETTL_UNKNOWN */
        { "Unknown link-layer type with nettl headers", "unknown-nettl" },
+
+       /* WTAP_ENCAP_MTP2_WITH_PHDR */
+       { "MTP2 with pseudoheader", "mtp2-with-phdr" },
+
+       /* WTAP_ENCAP_JUNIPER_PPPOE */
+       { "Juniper PPPoE", "juniper-pppoe" },
+
+       /* WTAP_ENCAP_GCOM_TIE1 */
+       { "GCOM TIE1", "gcom-tie1" },
+
+       /* WTAP_ENCAP_GCOM_SERIAL */
+       { "GCOM Serial", "gcom-serial" },
+
+       /* WTAP_ENCAP_NETTL_X25 */
+       { "X25 with nettl headers", "x25-nettl" },
+
+       /* WTAP_ENCAP_K12 */
+       { "K12 protocol analyzer", "k12" },
+
+       /* WTAP_ENCAP_JUNIPER_MLPPP */
+       { "Juniper MLPPP", "juniper-mlppp" },
+
+       /* WTAP_ENCAP_JUNIPER_MLFR */
+       { "Juniper MLFR", "juniper-mlfr" },
+
+       /* WTAP_ENCAP_JUNIPER_ETHER */
+       { "Juniper Ethernet", "juniper-ether" },
+
+       /* WTAP_ENCAP_JUNIPER_PPP */
+       { "Juniper PPP", "juniper-ppp" },
+
+       /* WTAP_ENCAP_JUNIPER_FRELAY */
+       { "Juniper Frame-Relay", "juniper-frelay" },
+
+       /* WTAP_ENCAP_JUNIPER_CHDLC */
+       { "Juniper C-HDLC", "juniper-chdlc" },
+    
+       /* WTAP_ENCAP_JUNIPER_GGSN */
+       { "Juniper GGSN", "juniper-ggsn" },
+
+       /* WTAP_ENCAP_LINUX_LAPD */
+       { "LAPD", "lapd" },
+
+       /* WTAP_ENCAP_CATAPULT_DCT2000 */
+       { "Catapult DCT2000", "dct2000" },
 };
 
 /* Name that should be somewhat descriptive. */
@@ -443,6 +519,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 = eth_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)
 {