diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-04-19 04:04:12 -0700 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2014-04-19 14:20:06 +0000 |
commit | 80011ec03c034cbebbe901eb4ded1242efe8fc78 (patch) | |
tree | e10045f12229249b2e348fd8e288b6ecf6ad1074 /epan/addr_resolv.c | |
parent | 1d574597ec2dfed1ba7674866e8634d7f1ed988b (diff) |
Don't se_ allocate strings when mapping addresses to column strings.
This should significantly reduce memory usage, without increasing the
CPU time required to process a capture file in TShark or Wireshark.
As a result, se_address_to_str() is no longer used; eliminate it.
Fixes bug #9949.
Change-Id: I65a112a426c82cc73a957b81384c765c3d14f2c3
Reviewed-on: https://code.wireshark.org/review/1213
Reviewed-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'epan/addr_resolv.c')
-rw-r--r-- | epan/addr_resolv.c | 67 |
1 files changed, 28 insertions, 39 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 5ee4da70e4..bdc7c9650f 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -1055,34 +1055,6 @@ solve_address_to_name(const address *addr) } } -static const gchar * -se_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 se_strdup((const gchar *)addr->data); - - default: - return NULL; - } -} - /* * Ethernet / manufacturer resolution * @@ -3036,25 +3008,42 @@ get_addr_name(const address *addr) return ep_address_to_str(addr); } +/* + * XXX - we should rename get_addr_name() to ep_addr_name(), to indicate + * that the scope of the string it returns may be as short-lived as + * an ep_allocated string (although it may be longer-lived), and + * rename this to get_addr_name(), as its strings have the same scope + * as the get_XXX_name() routines it calls. + */ const gchar * se_get_addr_name(const address *addr) { - const gchar *result; + guint32 ip4_addr; + struct e_in6_addr ip6_addr; - result = se_solve_address_to_name(addr); + /* + * Try to look up a name for this address. + * If it's not found, this might return a string corresponding to + * the address, or it might return NULL. + * + * Whatever string is returned has at least session scope. + */ + switch (addr->type) { - if (result != NULL) - return result; + case AT_ETHER: + return get_ether_name((const guint8 *)addr->data); - /* if it gets here, either it is of type AT_NONE, */ - /* or it should be solvable in se_address_to_str -unless addr->type is wrongly defined */ + case AT_IPv4: + memcpy(&ip4_addr, addr->data, sizeof ip4_addr); + return get_hostname(ip4_addr); - if (addr->type == AT_NONE){ - return "NONE"; - } + case AT_IPv6: + memcpy(&ip6_addr.bytes, addr->data, sizeof ip6_addr.bytes); + return get_hostname6(&ip6_addr); - /* We need a "permanently" allocated string */ - return se_address_to_str(addr); + default: + return NULL; + } } void |