From f0f72927b4983bbb320acdd79f56a37fa570f8bc Mon Sep 17 00:00:00 2001 From: John Thacker Date: Sun, 25 Dec 2022 16:12:48 -0500 Subject: [PATCH] epan: Allow FT_IPv4, FT_IPv6 custom columns to be resolved or not. Similar to commit dbb9fe2a37c7fcf6281, proto_item_fill_display_label now uses address_to_display for FT_IPv4, FT_IPv6, and FT_FCWWN, the other three address types that double as field types and which have optional name resolution. Add these to the list of types that, if present in a custom column, has the GUI enable the checkbox to switch between "resolved" (names) and not (values). This allows adding custom columns with these field types with both resolved and non resolved text. Note that the appropriate Name Resolution preference settings must be enabled for the type as well. --- epan/proto.c | 15 +++++++++------ ui/packet_list_utils.c | 8 ++++++-- ui/preference_utils.c | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/epan/proto.c b/epan/proto.c index fe0cc114da..8f70c23cbf 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -6649,21 +6649,24 @@ proto_item_fill_display_label(field_info *finfo, gchar *display_label_str, const case FT_IPv4: ipv4 = fvalue_get_uinteger(&finfo->value); set_address (&addr, AT_IPv4, 4, &ipv4); - address_to_str_buf(&addr, display_label_str, label_str_size); - label_len = (int)strlen(display_label_str); + tmp_str = address_to_display(NULL, &addr); + label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size); + wmem_free(NULL, tmp_str); break; case FT_IPv6: bytes = fvalue_get_bytes(&finfo->value); set_address (&addr, AT_IPv6, sizeof(ws_in6_addr), bytes); - address_to_str_buf(&addr, display_label_str, label_str_size); - label_len = (int)strlen(display_label_str); + tmp_str = address_to_display(NULL, &addr); + label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size); + wmem_free(NULL, tmp_str); break; case FT_FCWWN: set_address (&addr, AT_FCWWN, FCWWN_ADDR_LEN, fvalue_get_bytes(&finfo->value)); - address_to_str_buf(&addr, display_label_str, label_str_size); - label_len = (int)strlen(display_label_str); + tmp_str = address_to_display(NULL, &addr); + label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size); + wmem_free(NULL, tmp_str); break; case FT_ETHER: diff --git a/ui/packet_list_utils.c b/ui/packet_list_utils.c index 367db3ff6b..301c5177c7 100644 --- a/ui/packet_list_utils.c +++ b/ui/packet_list_utils.c @@ -90,8 +90,12 @@ resolve_column (gint col, capture_file *cf) field_idx = (guint *) g_slist_nth_data(cf->cinfo.columns[col].col_custom_fields_ids, ii); hfi = proto_registrar_get_nth(*field_idx); - /* Check if we have an OID or a strings table with integer values */ - if ((hfi->type == FT_OID) || (hfi->type == FT_REL_OID) || (hfi->type == FT_ETHER) || (hfi->type == FT_BOOLEAN) || + /* Check if we have an OID, a (potentially) resolvable network + * address, a Boolean, or a strings table with integer values */ + /* XXX: Should this checkbox be disabled if the Name Resolution + * preference for a given type is off? + */ + if ((hfi->type == FT_OID) || (hfi->type == FT_REL_OID) || (hfi->type == FT_ETHER) || (hfi->type == FT_IPv4) || (hfi->type == FT_IPv6) || (hfi->type == FT_FCWWN) || (hfi->type == FT_BOOLEAN) || ((hfi->strings != NULL) && (IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)))) { diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 23f2d18b96..2416e5c1ea 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -242,7 +242,7 @@ column_prefs_custom_resolve(const gchar* custom_field) for (guint i = 0; i < g_strv_length(fields); i++) { if (fields[i] && *fields[i]) { hfi = proto_registrar_get_byname(fields[i]); - if (hfi && ((hfi->type == FT_OID) || (hfi->type == FT_REL_OID) || (hfi->type == FT_ETHER) || (hfi->type == FT_BOOLEAN) || + if (hfi && ((hfi->type == FT_OID) || (hfi->type == FT_REL_OID) || (hfi->type == FT_ETHER) || (hfi->type == FT_IPv4) || (hfi->type == FT_IPv6) || (hfi->type == FT_FCWWN) || (hfi->type == FT_BOOLEAN) || ((hfi->strings != NULL) && (IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type))))) {