Avoid undefined behavior in overflow check
[metze/wireshark/wip.git] / wiretap / wtap.c
index 38be2248dcefd9474b30e480358a3340cf244e1f..3dfb42629796aacbe51fa6b53896ebbf5f496e1b 100644 (file)
 #include <sys/types.h>
 #endif
 
-#ifdef HAVE_LIBZ
-#include <zlib.h>
-#endif
-
 #include "wtap-int.h"
 
 #include "file_wrappers.h"
 #include <wsutil/file_util.h>
 #include <wsutil/buffer.h>
+#include <wsutil/ws_diag_control.h>
 
 #ifdef HAVE_PLUGINS
 
@@ -57,7 +54,6 @@ static gboolean
 check_for_wtap_plugin(GModule *handle)
 {
        gpointer gp;
-       void (*register_wtap_module)(void);
        wtap_plugin *plugin;
 
        /*
@@ -70,14 +66,12 @@ check_for_wtap_plugin(GModule *handle)
 
        /*
         * Yes - this plugin includes one or more wiretap modules.
-        */
-       register_wtap_module = (void (*)(void))gp;
-
-       /*
         * Add this one to the list of wiretap module plugins.
         */
        plugin = (wtap_plugin *)g_malloc(sizeof (wtap_plugin));
-       plugin->register_wtap_module = register_wtap_module;
+DIAG_OFF(pedantic)
+       plugin->register_wtap_module = (void (*)(void))gp;
+DIAG_ON(pedantic)
        wtap_plugins = g_slist_append(wtap_plugins, plugin);
        return TRUE;
 }
@@ -861,9 +855,6 @@ static struct encap_type_info encap_table_base[] = {
        /* WTAP_ENCAP_IXVERIWAVE */
        { "IxVeriWave header and stats block", "ixveriwave" },
 
-       /* WTAP_ENCAP_IEEE_802_11_AIROPEEK */
-       { "IEEE 802.11 plus AiroPeek radio header", "ieee-802-11-airopeek" },
-
        /* WTAP_ENCAP_SDH */
        { "SDH", "sdh" },
 
@@ -959,6 +950,16 @@ static struct encap_type_info encap_table_base[] = {
 
        /* WTAP_ENCAP_NSTRACE_3_5 */
        { "NetScaler Encapsulation 3.5 of Ethernet", "nstrace35" },
+
+       /* WTAP_ENCAP_ISO14443 */
+       { "ISO 14443 contactless smartcard standards", "iso14443" },
+
+       /* WTAP_ENCAP_GFP_T */
+       { "ITU-T G.7041/Y.1303 Generic Framing Procedure Transparent mode", "gfp-t" },
+
+       /* WTAP_ENCAP_GFP_F */
+       { "ITU-T G.7041/Y.1303 Generic Framing Procedure Frame-mapped mode", "gfp-f" }
+
 };
 
 WS_DLL_LOCAL
@@ -1091,7 +1092,7 @@ static const char *wtap_errlist[] = {
        "Files can't be saved in that format",
 
        /* WTAP_ERR_UNWRITABLE_ENCAP */
-       "Files from that network type can't be saved in that format",
+       "Packets with that network type can't be saved in that format",
 
        /* WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED */
        "That file format doesn't support per-packet encapsulations",
@@ -1457,6 +1458,19 @@ gboolean
 wtap_seek_read(wtap *wth, gint64 seek_off,
        struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
 {
+       /*
+        * Set the packet encapsulation to the file's encapsulation
+        * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
+        * right answer (and means that the read routine for this
+        * capture file type doesn't have to set it), and if it
+        * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
+        * anyway.
+        *
+        * Do the same for the packet time stamp resolution.
+        */
+       phdr->pkt_encap = wth->file_encap;
+       phdr->pkt_tsprec = wth->file_tsprec;
+
        if (!wth->subtype_seek_read(wth, seek_off, phdr, buf, err, err_info))
                return FALSE;