Avoid warnings.
[obnox/wireshark/wip.git] / wiretap / file_access.c
index 50f025b16701caa713d8bffe1f5b5f0425bd1bc8..5ba7d685e514b27bceadc09cea106e794d991b97 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <errno.h>
 
 
 #include <errno.h>
 
-#include "file_util.h"
+#include <wsutil/file_util.h>
 
 #include "wtap-int.h"
 #include "file_wrappers.h"
 
 #include "wtap-int.h"
 #include "file_wrappers.h"
@@ -47,7 +47,7 @@
 #include "airopeek9.h"
 #include "ngsniffer.h"
 #include "radcom.h"
 #include "airopeek9.h"
 #include "ngsniffer.h"
 #include "radcom.h"
-#include "ascend.h"
+#include "ascendtext.h"
 #include "nettl.h"
 #include "libpcap.h"
 #include "snoop.h"
 #include "nettl.h"
 #include "libpcap.h"
 #include "snoop.h"
 #include "k12.h"
 #include "ber.h"
 #include "catapult_dct2000.h"
 #include "k12.h"
 #include "ber.h"
 #include "catapult_dct2000.h"
+#include "mpeg.h"
+#include "netscreen.h"
+#include "commview.h"
+#include "pcapng.h"
+#include "aethra.h"
+#include "btsnoop.h"
+#include "tnef.h"
+#include "dct3trace.h"
+#include "packetlogger.h"
+#include "daintree-sna.h"
+#include "netscaler.h"
+#include "mime_file.h"
+#include "ipfix.h"
+
 
 /* The open_file_* routines should return:
  *
 
 /* The open_file_* routines should return:
  *
  * should be discovered as a libpcap file, not a toshiba file.
  */
 
  * should be discovered as a libpcap file, not a toshiba file.
  */
 
-static int (*const open_routines[])(wtap *, int *, char **) = {
+
+static wtap_open_routine_t open_routines_base[] = {
        /* Files that have magic bytes in fixed locations. These
         * are easy to identify.
         */
        /* Files that have magic bytes in fixed locations. These
         * are easy to identify.
         */
@@ -111,12 +126,30 @@ static int (*const open_routines[])(wtap *, int *, char **) = {
        k12_open,
        catapult_dct2000_open,
        ber_open,
        k12_open,
        catapult_dct2000_open,
        ber_open,
+       pcapng_open,
+       aethra_open,
+       btsnoop_open,
+       packetlogger_open, /* This type does not have a magic number, but its
+                           * files are sometimes grabbed by mpeg_open. */
+       mpeg_open,
+       tnef_open,
+       dct3trace_open,
+       daintree_sna_open,
+       mime_file_open,
        /* Files that don't have magic bytes at a fixed location,
         * but that instead require a heuristic of some sort to
         * identify them.  This includes the ASCII trace files that
         * would be, for example, saved copies of a Telnet session
         * to some box.
         */
        /* Files that don't have magic bytes at a fixed location,
         * but that instead require a heuristic of some sort to
         * identify them.  This includes the ASCII trace files that
         * would be, for example, saved copies of a Telnet session
         * to some box.
         */
+
+       /* I put NetScreen *before* erf, because there were some
+        * false positives with my test-files (Sake Blok, July 2007)
+        */
+       netscreen_open,
+       erf_open,
+       ipfix_open,
+       k12text_open,
        etherpeek_open,
        pppdump_open,
        iseries_open,
        etherpeek_open,
        pppdump_open,
        iseries_open,
@@ -127,11 +160,40 @@ static int (*const open_routines[])(wtap *, int *, char **) = {
        csids_open,
        vms_open,
        cosine_open,
        csids_open,
        vms_open,
        cosine_open,
-       erf_open,
        hcidump_open,
        hcidump_open,
+       commview_open,
+       nstrace_open
 };
 
 };
 
-#define        N_FILE_TYPES    (sizeof open_routines / sizeof open_routines[0])
+#define        N_FILE_TYPES    (sizeof open_routines_base / sizeof open_routines_base[0])
+
+static wtap_open_routine_t* open_routines = NULL;
+
+static GArray* open_routines_arr = NULL;
+
+
+/* initialize the open routines array if it has not been initialized yet */
+static void init_open_routines(void) {
+
+       if (open_routines_arr) return;
+
+       open_routines_arr = g_array_new(FALSE,TRUE,sizeof(wtap_open_routine_t));
+
+       g_array_append_vals(open_routines_arr,open_routines_base,N_FILE_TYPES);
+
+       open_routines = (wtap_open_routine_t*)(void *)open_routines_arr->data;
+}
+
+void wtap_register_open_routine(wtap_open_routine_t open_routine, gboolean has_magic) {
+       init_open_routines();
+
+       if (has_magic)
+               g_array_prepend_val(open_routines_arr,open_routine);
+       else
+               g_array_append_val(open_routines_arr,open_routine);
+
+       open_routines = (wtap_open_routine_t*)(void *)open_routines_arr->data;
+}
 
 /*
  * Visual C++ on Win32 systems doesn't define these.  (Old UNIX systems don't
 
 /*
  * Visual C++ on Win32 systems doesn't define these.  (Old UNIX systems don't
@@ -160,9 +222,10 @@ static int (*const open_routines[])(wtap *, int *, char **) = {
    written to as new packets arrive independently of random I/O done
    to display protocol trees for packets when they're selected. */
 wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
    written to as new packets arrive independently of random I/O done
    to display protocol trees for packets when they're selected. */
 wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
-    gboolean do_random)
+                       gboolean do_random)
 {
 {
-       struct stat statb;
+       int     fd;
+       ws_statb64 statb;
        wtap    *wth;
        unsigned int    i;
        gboolean use_stdin = FALSE;
        wtap    *wth;
        unsigned int    i;
        gboolean use_stdin = FALSE;
@@ -173,12 +236,12 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
 
        /* First, make sure the file is valid */
        if (use_stdin) {
 
        /* First, make sure the file is valid */
        if (use_stdin) {
-               if (fstat(0, &statb) < 0) {
+               if (ws_fstat64(0, &statb) < 0) {
                        *err = errno;
                        return NULL;
                }
        } else {
                        *err = errno;
                        return NULL;
                }
        } else {
-               if (eth_stat(filename, &statb) < 0) {
+               if (ws_stat64(filename, &statb) < 0) {
                        *err = errno;
                        return NULL;
                }
                        *err = errno;
                        return NULL;
                }
@@ -226,40 +289,46 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
        }
 
        errno = ENOMEM;
        }
 
        errno = ENOMEM;
-       wth = g_malloc(sizeof(wtap));
-       if (wth == NULL) {
-               *err = errno;
-               return NULL;
-       }
+       wth = (wtap *)g_malloc0(sizeof(wtap));
 
        /* Open the file */
        errno = WTAP_ERR_CANT_OPEN;
        if (use_stdin) {
                /*
                 * We dup FD 0, so that we don't have to worry about
 
        /* Open the file */
        errno = WTAP_ERR_CANT_OPEN;
        if (use_stdin) {
                /*
                 * We dup FD 0, so that we don't have to worry about
-                * an fclose or gzclose of wth->fh closing the standard
+                * a file_close of wth->fh closing the standard
                 * input of the process.
                 */
                 * input of the process.
                 */
-               wth->fd = eth_dup(0);
+               fd = ws_dup(0);
+               if (fd < 0) {
+                       *err = errno;
+                       g_free(wth);
+                       return NULL;
+               }
 #ifdef _WIN32
 #ifdef _WIN32
-               _setmode(wth->fd, O_BINARY);
+               if (_setmode(fd, O_BINARY) == -1) {
+                       /* "Shouldn't happen" */
+                       *err = errno;
+                       g_free(wth);
+                       return NULL;
+               }
 #endif
 #endif
-       } else
-               wth->fd = eth_open(filename, O_RDONLY|O_BINARY, 0000 /* no creation so don't matter */);
-       if (wth->fd < 0) {
-               *err = errno;
-               g_free(wth);
-               return NULL;
-       }
-       if (!(wth->fh = filed_open(wth->fd, "rb"))) {
-               *err = errno;
-               eth_close(wth->fd);
-               g_free(wth);
-               return NULL;
+               if (!(wth->fh = filed_open(fd))) {
+                       *err = errno;
+                       ws_close(fd);
+                       g_free(wth);
+                       return NULL;
+               }
+       } else {
+               if (!(wth->fh = file_open(filename))) {
+                       *err = errno;
+                       g_free(wth);
+                       return NULL;
+               }
        }
 
        if (do_random) {
        }
 
        if (do_random) {
-               if (!(wth->random_fh = file_open(filename, "rb"))) {
+               if (!(wth->random_fh = file_open(filename))) {
                        *err = errno;
                        file_close(wth->fh);
                        g_free(wth);
                        *err = errno;
                        file_close(wth->fh);
                        g_free(wth);
@@ -274,9 +343,18 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
        wth->subtype_sequential_close = NULL;
        wth->subtype_close = NULL;
        wth->tsprecision = WTAP_FILE_TSPREC_USEC;
        wth->subtype_sequential_close = NULL;
        wth->subtype_close = NULL;
        wth->tsprecision = WTAP_FILE_TSPREC_USEC;
+       wth->priv = NULL;
+
+       init_open_routines();
+       if (wth->random_fh) {
+               wth->fast_seek = g_ptr_array_new();
+
+               file_set_random_access(wth->fh, FALSE, wth->fast_seek);
+               file_set_random_access(wth->random_fh, TRUE, wth->fast_seek);
+       }
 
        /* Try all file types */
 
        /* Try all file types */
-       for (i = 0; i < N_FILE_TYPES; i++) {
+       for (i = 0; i < open_routines_arr->len; i++) {
                /* Seek back to the beginning of the file; the open routine
                   for the previous file type may have left the file
                   position somewhere other than the beginning, and the
                /* Seek back to the beginning of the file; the open routine
                   for the previous file type may have left the file
                   position somewhere other than the beginning, and the
@@ -293,7 +371,7 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
                        return NULL;
                }
                wth->data_offset = 0;
                        return NULL;
                }
                wth->data_offset = 0;
-               
+
                switch ((*open_routines[i])(wth, err, err_info)) {
 
                case -1:
                switch ((*open_routines[i])(wth, err, err_info)) {
 
                case -1:
@@ -315,240 +393,311 @@ wtap* wtap_open_offline(const char *filename, int *err, char **err_info,
        }
 
        /* Well, it's not one of the types of file we know about. */
        }
 
        /* Well, it's not one of the types of file we know about. */
-       if (wth->random_fh != NULL)
-               file_close(wth->random_fh);
-       file_close(wth->fh);
-       g_free(wth);
+       wtap_close(wth);
        *err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
        return NULL;
 
 success:
        *err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
        return NULL;
 
 success:
-       wth->frame_buffer = g_malloc(sizeof(struct Buffer));
+       wth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer));
        buffer_init(wth->frame_buffer, 1500);
        return wth;
 }
 
 /* Table of the file types we know about. */
        buffer_init(wth->frame_buffer, 1500);
        return wth;
 }
 
 /* Table of the file types we know about. */
-static const struct file_type_info {
-    /* the file type name */
-    /* should be NULL for all "pseudo" types that are only internally used and not read/writeable */
-       const char *name;
-
-    /* the file type short name, used as a shortcut for the command line tools */
-    /* should be NULL for all "pseudo" types that are are only internally used and not read/writeable */
-       const char *short_name;
-    
-    /* the common file extensions for this type (seperated by semicolon) */
-    /* should be *.* if no common extension is applicable */
-    const char *file_extensions;
-    
-    /* the default file extension, used to save this type */
-    /* should be NULL if no default extension is known */
-    const char *file_extension_default;
-    
-    /* can this type be compressed with gzip? */
-       gboolean        can_compress;
-    
-    /* can this type write this encapsulation format? */
-    /* should be NULL is this file type don't have write support */
-       int     (*can_write_encap)(int);
-    
-    /* the function to open the capture file for writing */
-    /* should be NULL is this file type don't have write support */
-       int     (*dump_open)(wtap_dumper *, gboolean, int *);
-} dump_open_table[WTAP_NUM_FILE_TYPES] = {
+static const struct file_type_info dump_open_table_base[] = {
        /* WTAP_FILE_UNKNOWN (only used internally for initialization) */
        /* WTAP_FILE_UNKNOWN (only used internally for initialization) */
-       { NULL, NULL, NULL, NULL, FALSE,
+       { NULL, NULL, NULL, NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_WTAP (only used internally while capturing) */
          NULL, NULL },
 
        /* WTAP_FILE_WTAP (only used internally while capturing) */
-       { NULL, NULL, NULL, NULL, FALSE,
+       { NULL, NULL, NULL, NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_PCAP */
          NULL, NULL },
 
        /* WTAP_FILE_PCAP */
-       { "Wireshark/tcpdump/... - libpcap", "libpcap", "*.pcap;*.cap", ".pcap", TRUE,
+        /* Gianluca Varenni suggests that we add "deprecated" to the description. */
+       { "Wireshark/tcpdump/... - libpcap", "libpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_NSEC */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_NSEC */
-       { "Wireshark - nanosecond libpcap", "nseclibpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "Wireshark - nanosecond libpcap", "nseclibpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_AIX */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_AIX */
-       { "AIX tcpdump - libpcap", "aixlibpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "AIX tcpdump - libpcap", "aixlibpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_PCAP_SS991029 */
          NULL, NULL },
 
        /* WTAP_FILE_PCAP_SS991029 */
-       { "Modified tcpdump - libpcap", "modlibpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "Modified tcpdump - libpcap", "modlibpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_NOKIA */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_NOKIA */
-       { "Nokia tcpdump - libpcap ", "nokialibpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "Nokia tcpdump - libpcap ", "nokialibpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_SS990417 */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_SS990417 */
-       { "RedHat 6.1 tcpdump - libpcap", "rh6_1libpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "RedHat 6.1 tcpdump - libpcap", "rh6_1libpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_SS990915 */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_PCAP_SS990915 */
-       { "SuSE 6.3 tcpdump - libpcap", "suse6_3libpcap", "*.pcap;*.cap", ".pcap", TRUE,
+       { "SuSE 6.3 tcpdump - libpcap", "suse6_3libpcap", "*.pcap;*.cap", ".pcap", FALSE, FALSE,
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_5VIEWS */
          libpcap_dump_can_write_encap, libpcap_dump_open },
 
        /* WTAP_FILE_5VIEWS */
-       { "Accellent 5Views capture", "5views", "*.5vw", ".5vw", FALSE,
+       { "Accellent 5Views capture", "5views", "*.5vw", ".5vw", TRUE, FALSE,
          _5views_dump_can_write_encap, _5views_dump_open },
 
        /* WTAP_FILE_IPTRACE_1_0 */
          _5views_dump_can_write_encap, _5views_dump_open },
 
        /* WTAP_FILE_IPTRACE_1_0 */
-       { "AIX iptrace 1.0", "iptrace_1", "*.*", NULL, FALSE,
+       { "AIX iptrace 1.0", "iptrace_1", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_IPTRACE_2_0 */
          NULL, NULL },
 
        /* WTAP_FILE_IPTRACE_2_0 */
-       { "AIX iptrace 2.0", "iptrace_2", "*.*", NULL, FALSE,
+       { "AIX iptrace 2.0", "iptrace_2", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_BER */
          NULL, NULL },
 
        /* WTAP_FILE_BER */
-       { "ASN.1 Basic Encoding Rules", "ber", "*.*", NULL, FALSE,
+       { "ASN.1 Basic Encoding Rules", "ber", "*.*", NULL, FALSE, FALSE,
                NULL, NULL },
 
        /* WTAP_FILE_HCIDUMP */
                NULL, NULL },
 
        /* WTAP_FILE_HCIDUMP */
-       { "Bluetooth HCI dump", "hcidump", "*.*", NULL, FALSE,
+       { "Bluetooth HCI dump", "hcidump", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_CATAPULT_DCT2000 */
          NULL, NULL },
 
        /* WTAP_FILE_CATAPULT_DCT2000 */
-       { "Catapult DCT2000 trace (.out format)", "dct2000", "*.out", ".out", FALSE,
+       { "Catapult DCT2000 trace (.out format)", "dct2000", "*.out", ".out", FALSE, FALSE,
          catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open },
 
        /* WTAP_FILE_NETXRAY_OLD */
          catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open },
 
        /* WTAP_FILE_NETXRAY_OLD */
-       { "Cinco Networks NetXRay 1.x", "netxray1", "*.cap", ".cap", FALSE,
+       { "Cinco Networks NetXRay 1.x", "netxray1", "*.cap", ".cap", TRUE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_NETXRAY_1_0 */
          NULL, NULL },
 
        /* WTAP_FILE_NETXRAY_1_0 */
-       { "Cinco Networks NetXRay 2.0 or later", "netxray2", "*.cap", ".cap", FALSE,
+       { "Cinco Networks NetXRay 2.0 or later", "netxray2", "*.cap", ".cap", TRUE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_COSINE */
          NULL, NULL },
 
        /* WTAP_FILE_COSINE */
-       { "CoSine IPSX L2 capture", "cosine", "*.*", NULL, FALSE,
+       { "CoSine IPSX L2 capture", "cosine", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_CSIDS */
          NULL, NULL },
 
        /* WTAP_FILE_CSIDS */
-       { "CSIDS IPLog", "csids", "*.*", NULL, FALSE,
+       { "CSIDS IPLog", "csids", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_DBS_ETHERWATCH */
          NULL, NULL },
 
        /* WTAP_FILE_DBS_ETHERWATCH */
-       { "DBS Etherwatch (VMS)", "etherwatch", "*.*", NULL, FALSE,
+       { "DBS Etherwatch (VMS)", "etherwatch", "*.*", NULL, FALSE, FALSE,
          NULL, NULL},
 
        /* WTAP_FILE_ERF */
          NULL, NULL},
 
        /* WTAP_FILE_ERF */
-       { "Endace DAG capture", "erf", "*.erf", ".erf", FALSE,
-         NULL, NULL },
+       { "Endace ERF capture", "erf", "*.erf", ".erf", FALSE, FALSE,
+         erf_dump_can_write_encap, erf_dump_open },
 
        /* WTAP_FILE_EYESDN */
 
        /* WTAP_FILE_EYESDN */
-       { "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "*.*", NULL, FALSE,
-               NULL, NULL },
-    
+       { "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "*.trc", ".trc", FALSE, FALSE,
+          eyesdn_dump_can_write_encap, eyesdn_dump_open },
+
        /* WTAP_FILE_NETTL */
        /* WTAP_FILE_NETTL */
-       { "HP-UX nettl trace", "nettl", "*.TRC0;*.TRC1", ".TRC0", FALSE,
+       { "HP-UX nettl trace", "nettl", "*.TRC0;*.TRC1", ".TRC0", FALSE, FALSE,
          nettl_dump_can_write_encap, nettl_dump_open },
 
        /* WTAP_FILE_ISERIES */
          nettl_dump_can_write_encap, nettl_dump_open },
 
        /* WTAP_FILE_ISERIES */
-       { "IBM iSeries comm. trace (ASCII)", "iseries_ascii", "*.*", NULL, FALSE,
+       { "IBM iSeries comm. trace (ASCII)", "iseries_ascii", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_ISERIES_UNICODE */
          NULL, NULL },
 
        /* WTAP_FILE_ISERIES_UNICODE */
-       { "IBM iSeries comm. trace (UNICODE)", "iseries_unicode", "*.*", NULL, FALSE,
+       { "IBM iSeries comm. trace (UNICODE)", "iseries_unicode", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_I4BTRACE */
          NULL, NULL },
 
        /* WTAP_FILE_I4BTRACE */
-       { "I4B ISDN trace", "i4btrace", "*.*", NULL, FALSE,
+       { "I4B ISDN trace", "i4btrace", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_ASCEND */
          NULL, NULL },
 
        /* WTAP_FILE_ASCEND */
-       { "Lucent/Ascend access server trace", "ascend", "*.*", NULL, FALSE,
+       { "Lucent/Ascend access server trace", "ascend", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_NETMON_1_x */
          NULL, NULL },
 
        /* WTAP_FILE_NETMON_1_x */
-       { "Microsoft NetMon 1.x", "netmon1", "*.cap", ".cap", FALSE,
+       { "Microsoft NetMon 1.x", "netmon1", "*.cap", ".cap", TRUE, FALSE,
          netmon_dump_can_write_encap, netmon_dump_open },
 
        /* WTAP_FILE_NETMON_2_x */
          netmon_dump_can_write_encap, netmon_dump_open },
 
        /* WTAP_FILE_NETMON_2_x */
-       { "Microsoft NetMon 2.x", "netmon2", "*.cap", ".cap", FALSE,
+       { "Microsoft NetMon 2.x", "netmon2", "*.cap", ".cap", TRUE, FALSE,
          netmon_dump_can_write_encap, netmon_dump_open },
 
        /* WTAP_FILE_NGSNIFFER_UNCOMPRESSED */
          netmon_dump_can_write_encap, netmon_dump_open },
 
        /* WTAP_FILE_NGSNIFFER_UNCOMPRESSED */
-       { "NA Sniffer (DOS)", "ngsniffer", "*.cap;*.enc;*.trc;*.fdc;*.syc", ".cap", FALSE,
+       { "NA Sniffer (DOS)", "ngsniffer", "*.cap;*.enc;*.trc;*.fdc;*.syc", ".cap", FALSE, FALSE,
          ngsniffer_dump_can_write_encap, ngsniffer_dump_open },
 
        /* WTAP_FILE_NGSNIFFER_COMPRESSED */
          ngsniffer_dump_can_write_encap, ngsniffer_dump_open },
 
        /* WTAP_FILE_NGSNIFFER_COMPRESSED */
-       { "NA Sniffer (DOS), compressed", "ngsniffer_comp", "*.caz", ".caz", FALSE,
+       { "NA Sniffer (DOS), compressed", "ngsniffer_comp", "*.caz", ".caz", FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_NETXRAY_1_1 */
          NULL, NULL },
 
        /* WTAP_FILE_NETXRAY_1_1 */
-       { "NA Sniffer (Windows) 1.1", "ngwsniffer_1_1", "*.cap", ".cap", FALSE,
+       { "NA Sniffer (Windows) 1.1", "ngwsniffer_1_1", "*.cap", ".cap", TRUE, FALSE,
          netxray_dump_can_write_encap_1_1, netxray_dump_open_1_1 },
 
        /* WTAP_FILE_NETXRAY_2_00x */
          netxray_dump_can_write_encap_1_1, netxray_dump_open_1_1 },
 
        /* WTAP_FILE_NETXRAY_2_00x */
-       { "NA Sniffer (Windows) 2.00x", "ngwsniffer_2_0", "*.cap", ".cap", FALSE,
+       { "NA Sniffer (Windows) 2.00x", "ngwsniffer_2_0", "*.cap", ".cap", TRUE, FALSE,
          netxray_dump_can_write_encap_2_0, netxray_dump_open_2_0 },
 
          netxray_dump_can_write_encap_2_0, netxray_dump_open_2_0 },
 
-       /* WTAP_FILE_NETWORK_INSTRUMENTS_V9 */
-       { "Network Instruments Observer (V9)", "niobserverv9", "*.bfr", ".bfr", FALSE,
+       /* WTAP_FILE_NETWORK_INSTRUMENTS */
+       { "Network Instruments Observer", "niobserver", "*.bfr", ".bfr", FALSE, FALSE,
          network_instruments_dump_can_write_encap, network_instruments_dump_open },
 
        /* WTAP_FILE_LANALYZER */
          network_instruments_dump_can_write_encap, network_instruments_dump_open },
 
        /* WTAP_FILE_LANALYZER */
-       { "Novell LANalyzer","lanalyzer", "*.tr1", ".tr1", FALSE,
+       { "Novell LANalyzer","lanalyzer", "*.tr1", ".tr1", TRUE, FALSE,
          lanalyzer_dump_can_write_encap, lanalyzer_dump_open },
 
        /* WTAP_FILE_PPPDUMP */
          lanalyzer_dump_can_write_encap, lanalyzer_dump_open },
 
        /* WTAP_FILE_PPPDUMP */
-       { "pppd log (pppdump format)", "pppd", "*.*", NULL, FALSE,
+       { "pppd log (pppdump format)", "pppd", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_RADCOM */
          NULL, NULL },
 
        /* WTAP_FILE_RADCOM */
-       { "RADCOM WAN/LAN analyzer", "radcom", "*.*", NULL, FALSE,
+       { "RADCOM WAN/LAN analyzer", "radcom", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_SNOOP */
          NULL, NULL },
 
        /* WTAP_FILE_SNOOP */
-       { "Sun snoop", "snoop", "*.snoop;*.cap", ".snoop", FALSE,
+       { "Sun snoop", "snoop", "*.snoop;*.cap", ".snoop", FALSE, FALSE,
          snoop_dump_can_write_encap, snoop_dump_open },
 
        /* WTAP_FILE_SHOMITI */
          snoop_dump_can_write_encap, snoop_dump_open },
 
        /* WTAP_FILE_SHOMITI */
-       { "Shomiti/Finisar Surveyor", "shomiti", "*.cap", ".cap", FALSE,
+       { "Shomiti/Finisar Surveyor", "shomiti", "*.cap", ".cap", FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_VMS */
          NULL, NULL },
 
        /* WTAP_FILE_VMS */
-       { "TCPIPtrace (VMS)", "tcpiptrace", "*.*", NULL, FALSE,
+       { "TCPIPtrace (VMS)", "tcpiptrace", "*.*", NULL, FALSE, FALSE,
          NULL, NULL},
 
        /* WTAP_FILE_K12 */
          NULL, NULL},
 
        /* WTAP_FILE_K12 */
-       { "Tektronix K12xx 32-bit .rf5 format", "rf5", "*.rf5", ".rf5", FALSE,
+       { "Tektronix K12xx 32-bit .rf5 format", "rf5", "*.rf5", ".rf5", TRUE, FALSE,
                k12_dump_can_write_encap, k12_dump_open },
 
        /* WTAP_FILE_TOSHIBA */
                k12_dump_can_write_encap, k12_dump_open },
 
        /* WTAP_FILE_TOSHIBA */
-       { "Toshiba Compact ISDN Router snoop", "toshiba", "*.*", NULL, FALSE,
+       { "Toshiba Compact ISDN Router snoop", "toshiba", "*.*", NULL, FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_VISUAL_NETWORKS */
          NULL, NULL },
 
        /* WTAP_FILE_VISUAL_NETWORKS */
-       { "Visual Networks traffic capture", "visual", "*.*", NULL, FALSE,
+       { "Visual Networks traffic capture", "visual", "*.*", NULL, TRUE, FALSE,
          visual_dump_can_write_encap, visual_dump_open },
 
        /* WTAP_FILE_ETHERPEEK_V56 */
          visual_dump_can_write_encap, visual_dump_open },
 
        /* WTAP_FILE_ETHERPEEK_V56 */
-       { "Wildpacket Ether/TokenPeek (V5 & V6)", "peek56", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE,
+       { "WildPackets Ether/TokenPeek (V5 & V6)", "peek56", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_ETHERPEEK_V7 */
          NULL, NULL },
 
        /* WTAP_FILE_ETHERPEEK_V7 */
-       { "Wildpacket Ether/Token/AiroPeek (V7)", "peek7", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE,
+       { "WildPackets Ether/Token/AiroPeek (V7)", "peek7", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE, FALSE,
          NULL, NULL },
 
        /* WTAP_FILE_ETHERPEEK_V9 */
          NULL, NULL },
 
        /* WTAP_FILE_ETHERPEEK_V9 */
-       { "Wildpacket Ether/AiroPeek (V9)", "peek9", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE,
+       { "WildPackets Ether/AiroPeek (V9)", "peek9", "*.tpc;*.apc;*.pkt;*.wpz", ".pkt", FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_MPEG */
+       { "MPEG", "mpeg", "*.mpeg;*.mpg;*.mp3", ".mpeg", FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_K12TEXT  */
+       { "K12 text file", "k12text", "*.txt", ".txt", FALSE, FALSE,
+         k12text_dump_can_write_encap, k12text_dump_open },
+
+       /* WTAP_FILE_NETSCREEN */
+       { "NetScreen snoop text file", "netscreen", "*.*", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_COMMVIEW */
+       { "TamoSoft CommView", "commview", "*.ncf", ".ncf", FALSE, FALSE,
+         commview_dump_can_write_encap, commview_dump_open },
+
+       /* WTAP_FILE_PCAPNG */
+       { "Wireshark - pcapng", "pcapng", "*.pcapng", NULL, FALSE, TRUE,
+         pcapng_dump_can_write_encap, pcapng_dump_open },
+
+       /* WTAP_FILE_BTSNOOP */
+       { "Symbian OS btsnoop", "btsnoop", "*.log", ".log", FALSE, FALSE,
+         btsnoop_dump_can_write_encap, btsnoop_dump_open_h4 },
+
+       /* WTAP_FILE_X2E_XORAYA */
+       { NULL, NULL, NULL, NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_TNEF */
+       { "Transport-Neutral Encapsulation Format", "tnef", "*.*", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_DCT3TRACE */
+       { "Gammu DCT3 trace", "dct3trace", "*.xml", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_PACKETLOGGER */
+       { "PacketLogger", "pklg", "*.pklg", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_DAINTREE_SNA */
+       { "Daintree SNA", "dsna", "*.dcf", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_NETSCALER_1_0 */
+       { "NetScaler Trace (Version 1.0)", "nstrace10", "*.*", "*.*", TRUE, FALSE,
+         nstrace_10_dump_can_write_encap, nstrace_dump_open },
+
+       /* WTAP_FILE_NETSCALER_2_0 */
+       { "NetScaler Trace (Version 2.0)", "nstrace20", "*.cap", "*.cap", TRUE, FALSE,
+         nstrace_20_dump_can_write_encap, nstrace_dump_open },
+
+       /* WTAP_FILE_JPEG_JFIF */
+       { "JPEG/JFIF", "jpeg", "*.jpg;*.jpeg;*.jfif", ".jpg", FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_FILE_IPFIX */
+       { "IPFIX File Format", "ipfix", "*.pfx;*.ipfix", NULL, FALSE, FALSE,
+         NULL, NULL },
+
+       /* WTAP_ENCAP_MIME */
+       { "MIME File Format", "mime", NULL, NULL, FALSE, FALSE,
+          NULL, NULL },
+
+       /* WTAP_FILE_AETHRA */
+       { "Aethra .aps file", "aethra", "*.aps", NULL, FALSE, FALSE,
          NULL, NULL },
          NULL, NULL },
-    
 };
 
 };
 
+gint wtap_num_file_types = sizeof(dump_open_table_base) / sizeof(struct file_type_info);
+
+static GArray*  dump_open_table_arr = NULL;
+static const struct file_type_info* dump_open_table = dump_open_table_base;
+
+/* initialize the open routines array if it has not being initialized yet */
+static void init_file_types(void) {
+
+       if (dump_open_table_arr) return;
+
+       dump_open_table_arr = g_array_new(FALSE,TRUE,sizeof(struct file_type_info));
+
+       g_array_append_vals(dump_open_table_arr,dump_open_table_base,wtap_num_file_types);
+
+       dump_open_table = (const struct file_type_info*)(void *)dump_open_table_arr->data;
+}
+
+int wtap_register_file_type(const struct file_type_info* fi) {
+       init_file_types();
+
+       g_array_append_val(dump_open_table_arr,*fi);
+
+       dump_open_table = (const struct file_type_info*)(void *)dump_open_table_arr->data;
+
+       return wtap_num_file_types++;
+}
+
+int wtap_get_num_file_types(void)
+{
+       return wtap_num_file_types;
+}
+
 /* Name that should be somewhat descriptive. */
 const char *wtap_file_type_string(int filetype)
 {
 /* Name that should be somewhat descriptive. */
 const char *wtap_file_type_string(int filetype)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES) {
+       if (filetype < 0 || filetype >= wtap_num_file_types) {
                g_error("Unknown capture file type %d", filetype);
                g_error("Unknown capture file type %d", filetype);
-               return NULL;
+               /** g_error() does an abort() and thus never returns **/
+               return "";
        } else
                return dump_open_table[filetype].name;
 }
        } else
                return dump_open_table[filetype].name;
 }
@@ -556,7 +705,7 @@ const char *wtap_file_type_string(int filetype)
 /* Name to use in, say, a command-line flag specifying the type. */
 const char *wtap_file_type_short_string(int filetype)
 {
 /* Name to use in, say, a command-line flag specifying the type. */
 const char *wtap_file_type_short_string(int filetype)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES)
+       if (filetype < 0 || filetype >= wtap_num_file_types)
                return NULL;
        else
                return dump_open_table[filetype].short_name;
                return NULL;
        else
                return dump_open_table[filetype].short_name;
@@ -567,7 +716,7 @@ int wtap_short_string_to_file_type(const char *short_name)
 {
        int filetype;
 
 {
        int filetype;
 
-       for (filetype = 0; filetype < WTAP_NUM_FILE_TYPES; filetype++) {
+       for (filetype = 0; filetype < wtap_num_file_types; filetype++) {
                if (dump_open_table[filetype].short_name != NULL &&
                    strcmp(short_name, dump_open_table[filetype].short_name) == 0)
                        return filetype;
                if (dump_open_table[filetype].short_name != NULL &&
                    strcmp(short_name, dump_open_table[filetype].short_name) == 0)
                        return filetype;
@@ -578,7 +727,7 @@ int wtap_short_string_to_file_type(const char *short_name)
 /* file extensions to use. */
 const char *wtap_file_extensions_string(int filetype)
 {
 /* file extensions to use. */
 const char *wtap_file_extensions_string(int filetype)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES)
+       if (filetype < 0 || filetype >= wtap_num_file_types)
                return NULL;
        else
                return dump_open_table[filetype].file_extensions;
                return NULL;
        else
                return dump_open_table[filetype].file_extensions;
@@ -587,7 +736,7 @@ const char *wtap_file_extensions_string(int filetype)
 /* default file extension to use. */
 const char *wtap_file_extension_default_string(int filetype)
 {
 /* default file extension to use. */
 const char *wtap_file_extension_default_string(int filetype)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES)
+       if (filetype < 0 || filetype >= wtap_num_file_types)
                return NULL;
        else
                return dump_open_table[filetype].file_extension_default;
                return NULL;
        else
                return dump_open_table[filetype].file_extension_default;
@@ -595,7 +744,7 @@ const char *wtap_file_extension_default_string(int filetype)
 
 gboolean wtap_dump_can_open(int filetype)
 {
 
 gboolean wtap_dump_can_open(int filetype)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
+       if (filetype < 0 || filetype >= wtap_num_file_types
            || dump_open_table[filetype].dump_open == NULL)
                return FALSE;
 
            || dump_open_table[filetype].dump_open == NULL)
                return FALSE;
 
@@ -604,7 +753,7 @@ gboolean wtap_dump_can_open(int filetype)
 
 gboolean wtap_dump_can_write_encap(int filetype, int encap)
 {
 
 gboolean wtap_dump_can_write_encap(int filetype, int encap)
 {
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
+       if (filetype < 0 || filetype >= wtap_num_file_types
            || dump_open_table[filetype].can_write_encap == NULL)
                return FALSE;
 
            || dump_open_table[filetype].can_write_encap == NULL)
                return FALSE;
 
@@ -614,34 +763,50 @@ gboolean wtap_dump_can_write_encap(int filetype, int encap)
        return TRUE;
 }
 
        return TRUE;
 }
 
+#ifdef HAVE_LIBZ
 gboolean wtap_dump_can_compress(int filetype)
 {
 gboolean wtap_dump_can_compress(int filetype)
 {
-#ifdef HAVE_LIBZ
-       if (filetype < 0 || filetype >= WTAP_NUM_FILE_TYPES
-           || dump_open_table[filetype].can_compress == FALSE)
+       /*
+        * If this is an unknown file type, or if we have to
+        * seek when writing out a file with this file type,
+        * return FALSE.
+        */
+       if (filetype < 0 || filetype >= wtap_num_file_types
+           || dump_open_table[filetype].writing_must_seek)
                return FALSE;
 
        return TRUE;
                return FALSE;
 
        return TRUE;
+}
 #else
 #else
+gboolean wtap_dump_can_compress(int filetype _U_)
+{
        return FALSE;
        return FALSE;
-#endif
 }
 }
+#endif
+
+gboolean wtap_dump_has_name_resolution(int filetype)
+{
+       if (filetype < 0 || filetype >= wtap_num_file_types
+           || dump_open_table[filetype].has_name_resolution == FALSE)
+               return FALSE;
 
 
+       return TRUE;
+}
 
 static gboolean wtap_dump_open_check(int filetype, int encap, gboolean comressed, int *err);
 static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen,
 
 static gboolean wtap_dump_open_check(int filetype, int encap, gboolean comressed, int *err);
 static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen,
-    gboolean compressed, int *err);
+                                       gboolean compressed, int *err);
 static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, gboolean compressed, int *err);
 
 static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, gboolean compressed, int *err);
 
-static FILE *wtap_dump_file_open(wtap_dumper *wdh, const char *filename);
-static FILE *wtap_dump_file_fdopen(wtap_dumper *wdh, int fd);
+static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename);
+static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd);
 static int wtap_dump_file_close(wtap_dumper *wdh);
 
 wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
                                int snaplen, gboolean compressed, int *err)
 {
        wtap_dumper *wdh;
 static int wtap_dump_file_close(wtap_dumper *wdh);
 
 wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
                                int snaplen, gboolean compressed, int *err)
 {
        wtap_dumper *wdh;
-       FILE *fh;
+       WFILE_T fh;
 
        /* Check whether we can open a capture file with that file type
           and that encapsulation. */
 
        /* Check whether we can open a capture file with that file type
           and that encapsulation. */
@@ -655,12 +820,18 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
 
        /* "-" means stdout */
        if (strcmp(filename, "-") == 0) {
 
        /* "-" means stdout */
        if (strcmp(filename, "-") == 0) {
-               if(compressed) {
+               if (compressed) {
+                       *err = EINVAL;  /* XXX - return a Wiretap error code for this */
                        g_free(wdh);
                        return NULL;    /* compress won't work on stdout */
                }
 #ifdef _WIN32
                        g_free(wdh);
                        return NULL;    /* compress won't work on stdout */
                }
 #ifdef _WIN32
-               setmode(fileno(stdout), O_BINARY);
+               if (_setmode(fileno(stdout), O_BINARY) == -1) {
+                       /* "Should not happen" */
+                       *err = errno;
+                       g_free(wdh);
+                       return NULL;    /* couldn't put standard output in binary mode */
+               }
 #endif
                wdh->fh = stdout;
        } else {
 #endif
                wdh->fh = stdout;
        } else {
@@ -681,7 +852,7 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap,
                   opening it. */
                if (wdh->fh != stdout) {
                        wtap_dump_file_close(wdh);
                   opening it. */
                if (wdh->fh != stdout) {
                        wtap_dump_file_close(wdh);
-                       eth_unlink(filename);
+                       ws_unlink(filename);
                }
                g_free(wdh);
                return NULL;
                }
                g_free(wdh);
                return NULL;
@@ -693,7 +864,7 @@ wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen,
                                gboolean compressed, int *err)
 {
        wtap_dumper *wdh;
                                gboolean compressed, int *err)
 {
        wtap_dumper *wdh;
-       FILE *fh;
+       WFILE_T fh;
 
        /* Check whether we can open a capture file with that file type
           and that encapsulation. */
 
        /* Check whether we can open a capture file with that file type
           and that encapsulation. */
@@ -706,9 +877,14 @@ wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen,
                return NULL;    /* couldn't allocate it */
 
 #ifdef _WIN32
                return NULL;    /* couldn't allocate it */
 
 #ifdef _WIN32
-    if(fd == 1) {
-               setmode(fileno(stdout), O_BINARY);
-    }
+       if (fd == 1) {
+               if (_setmode(fileno(stdout), O_BINARY) == -1) {
+                       /* "Should not happen" */
+                       *err = errno;
+                       g_free(wdh);
+                       return NULL;    /* couldn't put standard output in binary mode */
+               }
+       }
 #endif
 
        /* In case "fopen()" fails but doesn't set "errno", set "errno"
 #endif
 
        /* In case "fopen()" fails but doesn't set "errno", set "errno"
@@ -754,7 +930,6 @@ static gboolean wtap_dump_open_check(int filetype, int encap, gboolean compresse
        if (*err != 0)
                return FALSE;
 
        if (*err != 0)
                return FALSE;
 
-
        /* All systems go! */
        return TRUE;
 }
        /* All systems go! */
        return TRUE;
 }
@@ -764,20 +939,16 @@ static wtap_dumper* wtap_dump_alloc_wdh(int filetype, int encap, int snaplen,
 {
        wtap_dumper *wdh;
 
 {
        wtap_dumper *wdh;
 
-       wdh = g_malloc(sizeof (wtap_dumper));
+       wdh = (wtap_dumper *)g_malloc0(sizeof (wtap_dumper));
        if (wdh == NULL) {
                *err = errno;
                return NULL;
        }
        if (wdh == NULL) {
                *err = errno;
                return NULL;
        }
-       wdh->fh = NULL;
+
        wdh->file_type = filetype;
        wdh->snaplen = snaplen;
        wdh->encap = encap;
        wdh->compressed = compressed;
        wdh->file_type = filetype;
        wdh->snaplen = snaplen;
        wdh->encap = encap;
        wdh->compressed = compressed;
-       wdh->bytes_dumped = 0;
-       wdh->dump.opaque = NULL;
-       wdh->subtype_write = NULL;
-       wdh->subtype_close = NULL;
        return wdh;
 }
 
        return wdh;
 }
 
@@ -791,18 +962,24 @@ static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, gboolean c
        if(compressed) {
                cant_seek = TRUE;
        } else {
        if(compressed) {
                cant_seek = TRUE;
        } else {
-               fd = fileno(wdh->fh);
+               fd = fileno((FILE *)wdh->fh);
                if (lseek(fd, 1, SEEK_CUR) == -1)
                if (lseek(fd, 1, SEEK_CUR) == -1)
-                 cant_seek = TRUE;
+                       cant_seek = TRUE;
                else {
                else {
-                 /* Undo the seek. */
-                 lseek(fd, 0, SEEK_SET);
-                 cant_seek = FALSE;
+                       /* Undo the seek. */
+                       lseek(fd, 0, SEEK_SET);
+                       cant_seek = FALSE;
                }
        }
 
                }
        }
 
+       /* If this file type requires seeking, and we can't seek, fail. */
+       if (dump_open_table[filetype].writing_must_seek && cant_seek) {
+               *err = WTAP_ERR_CANT_WRITE_TO_PIPE;
+               return FALSE;
+       }
+
        /* Now try to open the file for writing. */
        /* Now try to open the file for writing. */
-       if (!(*dump_open_table[filetype].dump_open)(wdh, cant_seek, err)) {
+       if (!(*dump_open_table[filetype].dump_open)(wdh, err)) {
                return FALSE;
        }
 
                return FALSE;
        }
 
@@ -810,7 +987,7 @@ static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int filetype, gboolean c
 }
 
 gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
 }
 
 gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
-    const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err)
+                  const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err)
 {
        return (wdh->subtype_write)(wdh, phdr, pseudo_header, pd, err);
 }
 {
        return (wdh->subtype_write)(wdh, phdr, pseudo_header, pd, err);
 }
@@ -819,11 +996,11 @@ void wtap_dump_flush(wtap_dumper *wdh)
 {
 #ifdef HAVE_LIBZ
        if(wdh->compressed) {
 {
 #ifdef HAVE_LIBZ
        if(wdh->compressed) {
-               gzflush(wdh->fh, Z_SYNC_FLUSH); /* XXX - is Z_SYNC_FLUSH the right one? */
-       } else 
+               gzwfile_flush((GZWFILE_T)wdh->fh);
+       } else
 #endif
        {
 #endif
        {
-               fflush(wdh->fh);
+               fflush((FILE *)wdh->fh);
        }
 }
 
        }
 }
 
@@ -849,64 +1026,102 @@ gboolean wtap_dump_close(wtap_dumper *wdh, int *err)
                        }
                        ret = FALSE;
                }
                        }
                        ret = FALSE;
                }
-    } else {
-        /* as we don't close stdout, at least try to flush it */
-        wtap_dump_flush(wdh);
-    }
-       if (wdh->dump.opaque != NULL)
-               g_free(wdh->dump.opaque);
+       } else {
+               /* as we don't close stdout, at least try to flush it */
+               wtap_dump_flush(wdh);
+       }
+       if (wdh->priv != NULL)
+               g_free(wdh->priv);
        g_free(wdh);
        return ret;
 }
 
        g_free(wdh);
        return ret;
 }
 
-long wtap_get_bytes_dumped(wtap_dumper *wdh)
+gint64 wtap_get_bytes_dumped(wtap_dumper *wdh)
 {
        return wdh->bytes_dumped;
 }
 
 {
        return wdh->bytes_dumped;
 }
 
-void wtap_set_bytes_dumped(wtap_dumper *wdh, long bytes_dumped)
+void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped)
 {
        wdh->bytes_dumped = bytes_dumped;
 }
 
 {
        wdh->bytes_dumped = bytes_dumped;
 }
 
+gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, struct addrinfo *addrinfo_list)
+{
+       if (!wdh || wdh->file_type < 0 || wdh->file_type >= wtap_num_file_types
+               || dump_open_table[wdh->file_type].has_name_resolution == FALSE)
+                       return FALSE;
+       wdh->addrinfo_list = addrinfo_list;
+       return TRUE;
+}
 
 /* internally open a file for writing (compressed or not) */
 
 /* internally open a file for writing (compressed or not) */
-static FILE *wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
-{
 #ifdef HAVE_LIBZ
 #ifdef HAVE_LIBZ
+static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename)
+{
        if(wdh->compressed) {
        if(wdh->compressed) {
-               return gzopen(filename, "wb");
-       } else 
-#endif
-       {
-               return eth_fopen(filename, "wb");
+               return gzwfile_open(filename);
+       } else {
+               return ws_fopen(filename, "wb");
        }
 }
        }
 }
+#else
+static WFILE_T wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename)
+{
+       return ws_fopen(filename, "wb");
+}
+#endif
 
 /* internally open a file for writing (compressed or not) */
 
 /* internally open a file for writing (compressed or not) */
-static FILE *wtap_dump_file_fdopen(wtap_dumper *wdh, int fd)
-{
 #ifdef HAVE_LIBZ
 #ifdef HAVE_LIBZ
+static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd)
+{
        if(wdh->compressed) {
        if(wdh->compressed) {
-               return gzdopen(fd, "wb");
-       } else 
-#endif
-       {
+               return gzwfile_fdopen(fd);
+       } else {
                return fdopen(fd, "wb");
        }
 }
                return fdopen(fd, "wb");
        }
 }
+#else
+static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh _U_, int fd)
+{
+       return fdopen(fd, "wb");
+}
+#endif
 
 /* internally writing raw bytes (compressed or not) */
 
 /* internally writing raw bytes (compressed or not) */
-size_t wtap_dump_file_write(wtap_dumper *wdh, const void *buf, unsigned bufsize)
+gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize,
+                    int *err)
 {
 {
+       size_t nwritten;
+
 #ifdef HAVE_LIBZ
 #ifdef HAVE_LIBZ
-       if(wdh->compressed) {
-               return gzwrite(wdh->fh, buf, bufsize);
-       } else 
+       if (wdh->compressed) {
+               nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned) bufsize);
+               /*
+                * gzwfile_write() returns 0 on error.
+                */
+               if (nwritten == 0) {
+                       *err = gzwfile_geterr((GZWFILE_T)wdh->fh);
+                       return FALSE;
+               }
+       } else
 #endif
        {
 #endif
        {
-               return fwrite(buf, 1, bufsize, wdh->fh);
+               nwritten = fwrite(buf, 1, bufsize, (FILE *)wdh->fh);
+               /*
+                * At least according to the Mac OS X man page,
+                * this can return a short count on an error.
+                */
+               if (nwritten != bufsize) {
+                       if (ferror((FILE *)wdh->fh))
+                               *err = errno;
+                       else
+                               *err = WTAP_ERR_SHORT_WRITE;
+                       return FALSE;
+               }
        }
        }
+       return TRUE;
 }
 
 /* internally close a file for writing (compressed or not) */
 }
 
 /* internally close a file for writing (compressed or not) */
@@ -914,32 +1129,10 @@ static int wtap_dump_file_close(wtap_dumper *wdh)
 {
 #ifdef HAVE_LIBZ
        if(wdh->compressed) {
 {
 #ifdef HAVE_LIBZ
        if(wdh->compressed) {
-               return gzclose(wdh->fh);
-       } else 
-#endif
-       {
-               return fclose(wdh->fh);
-       }
-}
-
-int wtap_dump_file_ferror(wtap_dumper *wdh)
-{
-#ifdef HAVE_LIBZ
-       int errnum;
-
-       if(wdh->compressed) {
-               gzerror(wdh->fh, &errnum);
-
-               if(errnum == Z_ERRNO) {
-                       return errno;
-               } else {
-                       /* XXX - what to do with this zlib specific number? */
-                       return errnum;
-               }
-       } else 
+               return gzwfile_close((GZWFILE_T)wdh->fh);
+       } else
 #endif
        {
 #endif
        {
-               return ferror(wdh->fh);
+               return fclose((FILE *)wdh->fh);
        }
 }
        }
 }
-