Use g_array_index() to get at elements of the encapsulation table array;
[metze/wireshark/wip.git] / wiretap / wtap.c
index 198e6f77ce005c02423f9421b711ffec5c98ac67..35b33c60458499e1fc524b61aa8e4c5b89d2b342 100644 (file)
@@ -613,7 +613,9 @@ static struct encap_type_info encap_table_base[] = {
 WS_DLL_LOCAL
 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;
+
+#define encap_table_entry(encap)       \
+       g_array_index(encap_table_arr, struct encap_type_info, encap)
 
 static void wtap_init_encap_types(void) {
 
@@ -622,8 +624,6 @@ static void wtap_init_encap_types(void) {
        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 = (struct encap_type_info *)encap_table_arr->data;
 }
 
 int wtap_get_num_encap_types(void) {
@@ -641,8 +641,6 @@ int wtap_register_encap_type(const char* name, const char* short_name) {
 
        g_array_append_val(encap_table_arr,e);
 
-       encap_table = (struct encap_type_info *)encap_table_arr->data;
-
        return wtap_num_encap_types++;
 }
 
@@ -656,7 +654,7 @@ wtap_encap_string(int encap)
        else if (encap == WTAP_ENCAP_PER_PACKET)
                return "Per packet";
        else
-               return encap_table[encap].name;
+               return encap_table_entry(encap).name;
 }
 
 /* Name to use in, say, a command-line flag specifying the type. */
@@ -668,7 +666,7 @@ wtap_encap_short_string(int encap)
        else if (encap == WTAP_ENCAP_PER_PACKET)
                return "per-packet";
        else
-               return encap_table[encap].short_name;
+               return encap_table_entry(encap).short_name;
 }
 
 /* Translate a short name to a capture file type. */
@@ -678,8 +676,8 @@ wtap_short_string_to_encap(const char *short_name)
        int encap;
 
        for (encap = 0; encap < WTAP_NUM_ENCAP_TYPES; encap++) {
-               if (encap_table[encap].short_name != NULL &&
-                   strcmp(short_name, encap_table[encap].short_name) == 0)
+               if (encap_table_entry(encap).short_name != NULL &&
+                   strcmp(short_name, encap_table_entry(encap).short_name) == 0)
                        return encap;
        }
        return -1;      /* no such encapsulation type */