Add preference to display spaces between bytes for FT_BYTES fields.

I think this can make fields more readable (for a small amount of bytes).

Converted DeviceNet dissector to use proto_tree_add_item for some FT_BYTES field as tvb_bytes_to_str_punct was used to create this effect "manually".

Change-Id: I59e2acf9b00a4eb1279e6c2b2b7bd8ecef20db9b
Reviewed-on: https://code.wireshark.org/review/6304
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2015-01-04 11:17:53 -05:00
parent 02fb2908ff
commit effc8266ce
4 changed files with 30 additions and 14 deletions

View File

@ -298,8 +298,7 @@ static gint body_type_8_over_8_dissection(guint8 data_length, proto_tree *device
if (data_length > 4)
{
length = offset-start_offset;
proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, length,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, length, ' '));
proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, length, ENC_NA);
offset += length;
}
return offset;
@ -455,8 +454,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
message_id = can_id.id & MESSAGE_GROUP_1_MSG_MASK;
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message"));
proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' '));
proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
}
/*
* Message group 2
@ -488,13 +486,11 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
case 0x3:
case 0x4:
case 0x5:
proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' '));
proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
break;
case 0x6:
proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' '));
proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
break;
case 0x7:
@ -646,8 +642,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
default:
if(service_rr & CIP_SC_MASK)
{
proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length - 2, ' '));
proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2, ENC_NA);
}
else
{
@ -672,8 +667,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
body_type_16_over_16_dissection(data_length, content_tree, tvb, pinfo, offset);
break;
default:
proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' '));
proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
break;
}
}

View File

@ -2564,6 +2564,11 @@ prefs_register_modules(void)
"Display all hidden protocol items in the packet list.",
&prefs.display_hidden_proto_items);
prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
"Display byte fields with a space character between bytes",
"Display all byte fields with a space character between each byte in the packet list.",
&prefs.display_byte_fields_with_spaces);
/* Obsolete preferences
* These "modules" were reorganized/renamed to correspond to their GUI
* configuration screen within the preferences dialog
@ -3002,6 +3007,7 @@ pre_init_prefs(void)
prefs.st_sort_defdescending = TRUE;
prefs.st_sort_showfullname = FALSE;
prefs.display_hidden_proto_items = FALSE;
prefs.display_byte_fields_with_spaces = FALSE;
prefs_pre_initialized = TRUE;
}

View File

@ -203,6 +203,7 @@ typedef struct _e_prefs {
guint rtp_player_max_visible;
guint tap_update_interval;
gboolean display_hidden_proto_items;
gboolean display_byte_fields_with_spaces;
gpointer filter_expressions;/* Actually points to &head */
gboolean gui_update_enabled;
software_update_channel_e gui_update_channel;

View File

@ -4281,7 +4281,15 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
case BASE_NONE:
default:
if (bytes) {
char* str = (char*)bytes_to_str(NULL, bytes, fvalue_length(&finfo->value));
char* str;
if (prefs.display_byte_fields_with_spaces)
{
str = (char*)bytestring_to_str(NULL, bytes, fvalue_length(&finfo->value), ' ');
}
else
{
str = (char*)bytes_to_str(NULL, bytes, fvalue_length(&finfo->value));
}
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
} else {
@ -6043,7 +6051,14 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
break;
case BASE_NONE:
default:
str = (char*)bytes_to_str(NULL, bytes, fvalue_length(&fi->value));
if (prefs.display_byte_fields_with_spaces)
{
str = (char*)bytestring_to_str(NULL, bytes, fvalue_length(&fi->value), ' ');
}
else
{
str = (char*)bytes_to_str(NULL, bytes, fvalue_length(&fi->value));
}
break;
}
label_fill(label_str, 0, hfinfo, str);