summaryrefslogtreecommitdiff
path: root/epan/address_types.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-07-02 16:17:20 -0700
committerGuy Harris <guy@alum.mit.edu>2015-07-03 02:21:20 +0000
commitdf5a315048e9b318f7862901c1bd40fa2c08dad5 (patch)
tree5a098c4f335fcdf485aa3e9f150f44aff92f8166 /epan/address_types.c
parented21afa9521a930c96c69ff11b13b54ca006767e (diff)
downloadwireshark-df5a315048e9b318f7862901c1bd40fa2c08dad5.tar.gz
Fix address resolution for columns.
Have address_to_name() be a routine that takes an address and returns a string with a "sufficiently long" lifetime for use in columns, using the address type's addr_name_res_str routine for most address types, rather than having a too-small set of address types wired into it. It replaces both the internal solve_address_to_name() routine and get_addr_name(), and can, for example, handle the special WLAN address types rather than leaving them unresolved even with an ethers file. Change-Id: Id09bc412adf5d2752155650a14a77c5378af2e42 Reviewed-on: https://code.wireshark.org/review/9475 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/address_types.c')
-rw-r--r--epan/address_types.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/epan/address_types.c b/epan/address_types.c
index 9f5fa5b5ec..5601ae65ed 100644
--- a/epan/address_types.c
+++ b/epan/address_types.c
@@ -929,6 +929,58 @@ void address_to_str_buf(const address* addr, gchar *buf, int buf_len)
at->addr_to_str(addr, buf, buf_len);
}
+const gchar *
+address_to_name(const address *addr)
+{
+ address_type_t *at;
+
+ ADDR_TYPE_LOOKUP(addr->type, at);
+
+ if (at == NULL)
+ {
+ return NULL;
+ }
+
+ /*
+ * XXX - addr_name_res_str is expected to return a string from
+ * a persistent database, so that it lives a long time, past
+ * the lifetime of addr itself.
+ *
+ * We'd like to avoid copying, so this is what we do here.
+ */
+ switch (addr->type) {
+
+ case AT_STRINGZ:
+ return (const gchar *)addr->data;
+
+ default:
+ if (at->addr_name_res_str != NULL)
+ return at->addr_name_res_str(addr);
+ else
+ return NULL;
+ }
+}
+
+const gchar *
+address_to_display(wmem_allocator_t *allocator, const address *addr)
+{
+ gchar *str = NULL;
+ const gchar *result = address_to_name(addr);
+
+ if (result != NULL) {
+ str = wmem_strdup(allocator, result);
+ }
+ else if (addr->type == AT_NONE) {
+ str = wmem_strdup(allocator, "NONE");
+ }
+ else {
+ str = (gchar *) wmem_alloc(allocator, MAX_ADDR_STR_LEN);
+ address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
+ }
+
+ return str;
+}
+
static void address_with_resolution_to_str_buf(const address* addr, gchar *buf, int buf_len)
{
address_type_t *at;