Remove the (long deprecated) proto_tree_add_*_hidden() functions
[obnox/wireshark/wip.git] / wiretap / wtap.c
index c0972ec1e6e4bd867f36ebd1455eaa0f8cc766bb..64c2f0a66b89e7ecfa91b740af2f2bbb0317076e 100644 (file)
@@ -39,7 +39,7 @@
 #include "wtap.h"
 
 #include "file_wrappers.h"
-#include "file_util.h"
+#include <wsutil/file_util.h>
 #include "buffer.h"
 
 /*
@@ -84,10 +84,12 @@ wtap_file_tsprecision(wtap *wth)
 }
 
 /* Table of the encapsulation types we know about. */
-static const struct encap_type_info {
+struct encap_type_info {
        const char *name;
        const char *short_name;
-} encap_table[WTAP_NUM_ENCAP_TYPES] = {
+};
+
+static struct encap_type_info encap_table_base[] = {
        /* WTAP_ENCAP_UNKNOWN */
        { "Unknown", NULL },
 
@@ -348,7 +350,7 @@ static const struct encap_type_info {
 
        /* WTAP_ENCAP_JUNIPER_CHDLC */
        { "Juniper C-HDLC", "juniper-chdlc" },
-    
+
        /* WTAP_ENCAP_JUNIPER_GGSN */
        { "Juniper GGSN", "juniper-ggsn" },
 
@@ -371,9 +373,95 @@ static const struct encap_type_info {
        { "IEEE 802.16 MAC Common Part Sublayer", "ieee-802-16-mac-cps" },
 
        /* WTAP_ENCAP_NETTL_RAW_TELNET */
-       { "Raw telnet with nettl headers", "raw-telnet-nettl" }
+       { "Raw telnet with nettl headers", "raw-telnet-nettl" },
+
+       /* WTAP_ENCAP_USB_LINUX */
+       { "USB packets with Linux header", "usb-linux" },
+
+       /* WTAP_ENCAP_MPEG */
+       { "MPEG", "mpeg" },
+
+       /* WTAP_ENCAP_PPI */
+       { "Per-Packet Information header", "ppi" },
+
+       /* WTAP_ENCAP_ERF */
+       { "Endace Record File", "erf" },
+
+       /* WTAP_ENCAP_BT_H4 */
+       { "Bluetooth H4 with linux header", "bluetooth-h4" },
+
+       /* WTAP_ENCAP_SITA */
+       { "SITA WAN packets", "sita-wan" },
+
+       /* WTAP_ENCAP_SCCP */
+       { "SS7 SCCP", "sccp" },
+
+       /* WTAP_ENCAP_BLUETOOTH_HCI */
+       { "Bluetooth without transport layer", "bluetooth-hci" },
+
+       /* WTAP_ENCAP_IPMB */
+       { "Intelligent Platform Management Bus", "ipmb" },
+
+       /* WTAP_ENCAP_IEEE802_15_4 */
+       { "IEEE 802.15.4 Wireless PAN", "wpan" },
+
+       /* WTAP_ENCAP_X2E_XORAYA */
+       { "X2E Xoraya", "x2e-xoraya" },
+
+       /* WTAP_ENCAP_FLEXRAY */
+       { "FlexRay", "flexray" },
+
+       /* WTAP_ENCAP_LIN */
+       { "Local Interconnect Network", "lin" },
+
+       /* WTAP_ENCAP_MOST */
+       { "Media Oriented Systems Transport", "most" },
+
+       /* WTAP_ENCAP_CAN20B */
+       { "Controller Area Network 2.0B", "can20b" },
+
+       /* WTAP_ENCAP_LAYER1_EVENT */
+       { "EyeSDN Layer 1 event", "layer1-event" },
+
+       /* WTAP_ENCAP_X2E_SERIAL */
+       { "X2E serial line capture", "x2e-serial" }
 };
 
+gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
+static GArray* encap_table_arr = NULL;
+static const struct encap_type_info* encap_table = NULL;
+
+static void wtap_init_encap_types(void) {
+
+       if (encap_table_arr) return;
+
+       encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info));
+
+       g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types);
+
+       encap_table = (void*)encap_table_arr->data;
+}
+
+int wtap_get_num_encap_types(void) {
+       wtap_init_encap_types();
+       return wtap_num_encap_types;
+}
+
+
+int wtap_register_encap_type(char* name, char* short_name) {
+       struct encap_type_info* e = g_malloc(sizeof(struct encap_type_info));
+       wtap_init_encap_types();
+
+       e->name = g_strdup(name);
+       e->short_name = g_strdup(short_name);
+
+       g_array_append_val(encap_table_arr,e);
+
+       encap_table = (void*)encap_table_arr->data;
+       return wtap_num_encap_types++;
+}
+
+
 /* Name that should be somewhat descriptive. */
 const char
 *wtap_encap_string(int encap)
@@ -440,14 +528,14 @@ const char
 #ifdef HAVE_LIBZ
                if (err >= WTAP_ERR_ZLIB_MIN && err <= WTAP_ERR_ZLIB_MAX) {
                        /* Assume it's a zlib error. */
-                       sprintf(errbuf, "Uncompression error: %s",
+                       g_snprintf(errbuf, 128, "Uncompression error: %s",
                            zError(err - WTAP_ERR_ZLIB));
                        return errbuf;
                }
 #endif
                wtap_errlist_index = -1 - err;
                if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
-                       sprintf(errbuf, "Error %d", err);
+                       g_snprintf(errbuf, 128, "Error %d", err);
                        return errbuf;
                }
                if (wtap_errlist[wtap_errlist_index] == NULL)
@@ -540,7 +628,7 @@ wtap_read_so_far(wtap *wth, int *err)
 {
        off_t file_pos;
 
-       file_pos = eth_lseek(wth->fd, 0, SEEK_CUR);
+       file_pos = ws_lseek(wth->fd, 0, SEEK_CUR);
        if (file_pos == -1) {
                if (err != NULL)
                        *err = errno;