diff options
author | Anders Broman <anders.broman@ericsson.com> | 2013-08-20 05:06:26 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2013-08-20 05:06:26 +0000 |
commit | 4e63bb5ec529783a1058dbaeff7483e1eb5572d3 (patch) | |
tree | 87cde5a02a243e4b7b3aac918176ffd838b71bc4 /epan | |
parent | ce6a604f07b5e155686d18968222296805aa57d6 (diff) | |
download | wireshark-4e63bb5ec529783a1058dbaeff7483e1eb5572d3.tar.gz |
Use g_hash_table() for ipxnet name resolution.
svn path=/trunk/; revision=51436
Diffstat (limited to 'epan')
-rw-r--r-- | epan/addr_resolv.c | 82 | ||||
-rw-r--r-- | epan/addr_resolv.h | 3 |
2 files changed, 44 insertions, 41 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index b7382aa752..5b75a28d65 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -286,6 +286,7 @@ typedef struct _ipxnet char name[MAXNAMELEN]; } ipxnet_t; +static GHashTable *ipxnet_hash_table = NULL; static GHashTable *ipv4_hash_table = NULL; static GHashTable *ipv6_hash_table = NULL; @@ -298,8 +299,6 @@ static GHashTable *wka_hashtable = NULL; static GHashTable *eth_hashtable = NULL; static GHashTable *serv_port_hashtable = NULL; -static hashipxnet_t *ipxnet_table[HASHIPXNETSIZE]; - static subnet_length_entry_t subnet_length_entries[SUBNETLENGTHSIZE]; /* Ordered array of entries */ static gboolean have_subnet_entry = FALSE; @@ -1799,6 +1798,7 @@ static guint8 * eth_addr_lookup(const gchar *name _U_) { #if 0 + /* XXX Do we need reverse lookup??? */ ether_t *eth; hashether_t *tp; hashether_t **table = eth_table; @@ -1998,33 +1998,29 @@ initialize_ipxnets(void) static void ipx_name_lookup_cleanup(void) { - /* The memory pointed to by this table is se_ allocated so we don't have to - * free it here. - */ - memset(ipxnet_table, 0, sizeof(ipxnet_table)); + if(ipxnet_hash_table){ + g_hash_table_destroy(ipxnet_hash_table); + ipxnet_hash_table = NULL; + } + } static hashipxnet_t * add_ipxnet_name(guint addr, const gchar *name) { - int hash_idx; hashipxnet_t *tp; - hash_idx = HASH_IPX_NET(addr); - - tp = ipxnet_table[hash_idx]; + tp = (hashipxnet_t *)g_hash_table_lookup(ipxnet_hash_table, &addr); + if(tp){ + g_strlcpy(tp->name, name, MAXNAMELEN); + }else{ + int *key; - if( tp == NULL ) { - tp = ipxnet_table[hash_idx] = se_new(hashipxnet_t); - } else { - while(1) { - if (tp->next == NULL) { - tp->next = se_new(hashipxnet_t); - tp = tp->next; - break; - } - tp = tp->next; - } + key = (int *)g_new(int, 1); + *key = addr; + tp = g_new(hashipxnet_t,1); + g_strlcpy(tp->name, name, MAXNAMELEN); + g_hash_table_insert(ipxnet_hash_table, key, tp); } tp->addr = addr; @@ -2039,34 +2035,24 @@ add_ipxnet_name(guint addr, const gchar *name) static gchar * ipxnet_name_lookup(const guint addr) { - int hash_idx; hashipxnet_t *tp; ipxnet_t *ipxnet; - hash_idx = HASH_IPX_NET(addr); - - tp = ipxnet_table[hash_idx]; + tp = (hashipxnet_t *)g_hash_table_lookup(ipxnet_hash_table, &addr); + if(tp == NULL){ + int *key; - if( tp == NULL ) { - tp = ipxnet_table[hash_idx] = se_new(hashipxnet_t); - } else { - while(1) { - if (tp->addr == addr) { - return tp->name; - } - if (tp->next == NULL) { - tp->next = se_new(hashipxnet_t); - tp = tp->next; - break; - } - tp = tp->next; - } + key = (int *)g_new(int, 1); + *key = addr; + tp = g_new(hashipxnet_t, 1); + g_hash_table_insert(ipxnet_hash_table, key, tp); + }else{ + return tp->name; } /* fill in a new entry */ tp->addr = addr; - tp->next = NULL; if ( (ipxnet = get_ipxnetbyaddr(addr)) == NULL) { /* unknown name */ @@ -2083,6 +2069,10 @@ ipxnet_name_lookup(const guint addr) static guint ipxnet_addr_lookup(const gchar *name, gboolean *success) { + *success = FALSE; + return 0; +#if 0 + /* XXX Do we need reverse lookup??? */ ipxnet_t *ipxnet; hashipxnet_t *tp; hashipxnet_t **table = ipxnet_table; @@ -2113,7 +2103,7 @@ ipxnet_addr_lookup(const gchar *name, gboolean *success) *success = TRUE; return tp->addr; - +#endif } /* ipxnet_addr_lookup */ static gboolean @@ -2815,6 +2805,9 @@ host_name_lookup_init(void) #endif /* _WIN32 */ #endif /*GNU_ADNS */ + g_assert(ipxnet_hash_table == NULL); + ipxnet_hash_table = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); + g_assert(ipv4_hash_table == NULL); ipv4_hash_table = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); @@ -2925,6 +2918,7 @@ host_name_lookup_cleanup(void) g_hash_table_destroy(ipv4_hash_table); ipv4_hash_table = NULL; } + if(ipv6_hash_table){ g_hash_table_destroy(ipv6_hash_table); ipv6_hash_table = NULL; @@ -3480,6 +3474,12 @@ get_serv_port_hashtable(void) } GHashTable * +get_ipxnet_hash_table(void) +{ + return ipxnet_hash_table; +} + +GHashTable * get_ipv4_hash_table(void) { return ipv4_hash_table; diff --git a/epan/addr_resolv.h b/epan/addr_resolv.h index 3308150e90..c6743a3a2f 100644 --- a/epan/addr_resolv.h +++ b/epan/addr_resolv.h @@ -341,6 +341,9 @@ WS_DLL_PUBLIC GHashTable *get_serv_port_hashtable(void); WS_DLL_PUBLIC +GHashTable *get_ipxnet_table(void); + +WS_DLL_PUBLIC GHashTable *get_ipv4_hash_table(void); WS_DLL_PUBLIC |