summaryrefslogtreecommitdiff
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
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>
-rw-r--r--epan/addr_resolv.c54
-rw-r--r--epan/addr_resolv.h14
-rw-r--r--epan/address_types.c52
-rw-r--r--epan/column-utils.c2
-rw-r--r--epan/to_str.h27
5 files changed, 80 insertions, 69 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index 7fcfbcc057..76b9c7e078 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -1037,34 +1037,6 @@ try_resolv:
} /* host_lookup6 */
-static const gchar *
-solve_address_to_name(const address *addr)
-{
- switch (addr->type) {
-
- case AT_ETHER:
- return get_ether_name((const guint8 *)addr->data);
-
- case AT_IPv4: {
- guint32 ip4_addr;
- memcpy(&ip4_addr, addr->data, sizeof ip4_addr);
- return get_hostname(ip4_addr);
- }
-
- case AT_IPv6: {
- struct e_in6_addr ip6_addr;
- memcpy(&ip6_addr.bytes, addr->data, sizeof ip6_addr.bytes);
- return get_hostname6(&ip6_addr);
- }
-
- case AT_STRINGZ:
- return (const gchar *)addr->data;
-
- default:
- return NULL;
- }
-}
-
/*
* Ethernet / manufacturer resolution
*
@@ -3006,32 +2978,6 @@ sctp_port_to_display(wmem_allocator_t *allocator, guint port)
} /* sctp_port_to_display */
-const gchar *
-address_to_display(wmem_allocator_t *allocator, const address *addr)
-{
- gchar *str = NULL;
- const gchar *result = solve_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;
-}
-
-const gchar *
-get_addr_name(const address *addr)
-{
- return solve_address_to_name(addr);
-}
-
gchar *
get_ether_name(const guint8 *addr)
{
diff --git a/epan/addr_resolv.h b/epan/addr_resolv.h
index d6ac3a559e..25bd0156d1 100644
--- a/epan/addr_resolv.h
+++ b/epan/addr_resolv.h
@@ -131,20 +131,6 @@ extern gchar *dccp_port_to_display(wmem_allocator_t *allocator, guint port);
WS_DLL_PUBLIC gchar *sctp_port_to_display(wmem_allocator_t *allocator, guint port);
/*
- * address_to_display takes as input an "address", as defined in address.h */
-/* it returns a string that contains: */
-/* - if the address is of a type that can be translated into a name, and the user */
-/* has activated name resolution, the translated name */
-/* - if the address is of type AT_NONE, a pointer to the string "NONE" */
-/* - if the address is of any other type, the result of address_to_str on the argument, */
-/* which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
-/* address 10.10.10.10 */
-WS_DLL_PUBLIC
-const gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
-
-const gchar *get_addr_name(const address *addr);
-
-/*
* Asynchronous host name lookup initialization, processing, and cleanup
*/
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;
diff --git a/epan/column-utils.c b/epan/column-utils.c
index fbf8e85239..4dd0336623 100644
--- a/epan/column-utils.c
+++ b/epan/column-utils.c
@@ -1853,7 +1853,7 @@ col_set_addr(packet_info *pinfo, const int col, const address *addr, const gbool
return;
}
- if (res && (name = get_addr_name(addr)) != NULL)
+ if (res && (name = address_to_name(addr)) != NULL)
col_item->col_data = name;
else {
col_item->col_data = col_item->col_buf;
diff --git a/epan/to_str.h b/epan/to_str.h
index 56ac29b9cd..082aea99c4 100644
--- a/epan/to_str.h
+++ b/epan/to_str.h
@@ -55,6 +55,33 @@ WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr
WS_DLL_PUBLIC gchar* address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
+/*
+ * address_to_name takes as input an "address", as defined in address.h.
+ *
+ * If the address is of a type that can be translated into a name, and the
+ * user has activated name resolution, and the name can be resolved, it
+ * returns a string containing the translated name.
+ *
+ * Otherwise, it returns NULL.
+ */
+const gchar *address_to_name(const address *addr);
+
+/*
+ * address_to_display takes as input an "address", as defined in address.h .
+ *
+ * If the address is of a type that can be translated into a name, and the
+ * user has activated name resolution, and the name can be resolved, it
+ * returns a string containing the translated name.
+ *
+ * Otherwise, if the address is of type AT_NONE, it returns "NONE".
+ *
+ * Otherwise, it returns a string containing the result of address_to_str
+ * on the argument, which should be a string representation for the address,
+ * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
+ */
+WS_DLL_PUBLIC
+const gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
+
WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
#define tvb_ether_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_ETHER, offset)