Adjust proto_tree_add_xxx_format_value calls to use unit string

proto_tree_add_uint_format_value had the most use of unit strings, this
patch handles all of the other proto_tree_add_xxx_format_value calls that
could be better served using BASE_UNIT_STRING with a "unit string" in hf_ field.

Added more "common" unit string values to unit_strings.[ch]

Change-Id: I0fb680be781e10037eb7bd40dd21a9ee20c1fb1c
Reviewed-on: https://code.wireshark.org/review/19288
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2016-12-14 17:34:56 -05:00
parent d706f9c221
commit 8efb7fece1
9 changed files with 45 additions and 57 deletions

View File

@ -1644,6 +1644,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
units_bit_bits@Base 2.3.0
units_bit_sec@Base 2.3.0
units_byte_bytes@Base 2.3.0
units_dbm@Base 2.3.0
units_decibals@Base 2.3.0
units_degree_degrees@Base 2.3.0
units_foot_feet@Base 2.3.0

View File

@ -693,10 +693,7 @@ dissect_wlan_radio_phdr (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
if (phdr->has_signal_dbm) {
col_add_fstr(pinfo->cinfo, COL_RSSI, "%d dBm", phdr->signal_dbm);
proto_tree_add_int_format_value(radio_tree, hf_wlan_radio_signal_dbm, tvb, 0, 0,
phdr->signal_dbm,
"%d dBm",
phdr->signal_dbm);
proto_tree_add_int(radio_tree, hf_wlan_radio_signal_dbm, tvb, 0, 0, phdr->signal_dbm);
}
if (phdr->has_noise_percent) {
@ -704,10 +701,7 @@ dissect_wlan_radio_phdr (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
}
if (phdr->has_noise_dbm) {
proto_tree_add_int_format_value(radio_tree, hf_wlan_radio_noise_dbm, tvb, 0, 0,
phdr->noise_dbm,
"%d dBm",
phdr->noise_dbm);
proto_tree_add_int(radio_tree, hf_wlan_radio_noise_dbm, tvb, 0, 0, phdr->noise_dbm);
}
if (phdr->has_tsf_timestamp) {
@ -1101,7 +1095,7 @@ static hf_register_info hf_wlan_radio[] = {
"Signal strength, as percentage of maximum RSSI", HFILL }},
{&hf_wlan_radio_signal_dbm,
{"Signal strength (dBm)", "wlan_radio.signal_dbm", FT_INT8, BASE_DEC, NULL, 0,
{"Signal strength (dBm)", "wlan_radio.signal_dbm", FT_INT8, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0,
NULL, HFILL }},
{&hf_wlan_radio_noise_percent,
@ -1109,7 +1103,7 @@ static hf_register_info hf_wlan_radio[] = {
NULL, HFILL }},
{&hf_wlan_radio_noise_dbm,
{"Noise level (dBm)", "wlan_radio.noise_dbm", FT_INT8, BASE_DEC, NULL, 0,
{"Noise level (dBm)", "wlan_radio.noise_dbm", FT_INT8, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0,
NULL, HFILL }},
{&hf_wlan_radio_timestamp,

View File

@ -1167,11 +1167,9 @@ dissect_radiotap(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* u
phdr.has_signal_dbm = TRUE;
phdr.signal_dbm = dbm;
col_add_fstr(pinfo->cinfo, COL_RSSI, "%d dBm", dbm);
proto_tree_add_int_format_value(radiotap_tree,
proto_tree_add_int(radiotap_tree,
hf_radiotap_dbm_antsignal,
tvb, offset, 1, dbm,
"%d dBm",
dbm);
tvb, offset, 1, dbm);
radiotap_info->dbm_antsignal = dbm;
break;
@ -1180,11 +1178,9 @@ dissect_radiotap(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* u
phdr.has_noise_dbm = TRUE;
phdr.noise_dbm = dbm;
if (tree) {
proto_tree_add_int_format_value(radiotap_tree,
proto_tree_add_int(radiotap_tree,
hf_radiotap_dbm_antnoise,
tvb, offset, 1, dbm,
"%d dBm",
dbm);
tvb, offset, 1, dbm);
}
radiotap_info->dbm_antnoise = dbm;
break;
@ -2312,7 +2308,7 @@ void proto_register_radiotap(void)
{&hf_radiotap_dbm_antsignal,
{"SSI Signal", "radiotap.dbm_antsignal",
FT_INT32, BASE_DEC, NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF signal power at the antenna from a fixed,"
" arbitrary value in decibels from one milliwatt", HFILL}},
@ -2323,13 +2319,13 @@ void proto_register_radiotap(void)
{&hf_radiotap_dbm_antnoise,
{"SSI Noise", "radiotap.dbm_antnoise",
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_decibals, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF noise power at the antenna from a fixed, arbitrary value"
" in decibels per one milliwatt", HFILL}},
{&hf_radiotap_db_antnoise,
{"SSI Noise", "radiotap.db_antnoise",
FT_UINT32, BASE_DEC, NULL, 0x0,
FT_UINT32, BASE_DEC|BASE_UNIT_STRING, &units_decibals, 0x0,
"RF noise power at the antenna from a fixed, arbitrary value"
" in decibels", HFILL}},

View File

@ -402,9 +402,8 @@ dissect_ixveriwave(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* da
if (length_remaining >= 8) {
vw_startt = tvb_get_letoh64(tvb, offset);
proto_tree_add_uint64_format_value(vw_times_tree, hf_ixveriwave_vw_startt,
tvb, offset, 8, vw_startt,
"%" G_GINT64_MODIFIER "u usec", vw_startt);
proto_tree_add_uint64(vw_times_tree, hf_ixveriwave_vw_startt,
tvb, offset, 8, vw_startt);
offset +=8;
length_remaining -=8;
@ -414,9 +413,8 @@ dissect_ixveriwave(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* da
if (length_remaining >= 8) {
vw_endt = tvb_get_letoh64(tvb, offset);
proto_tree_add_uint64_format_value(vw_times_tree, hf_ixveriwave_vw_endt,
tvb, offset, 8, vw_endt,
"%" G_GINT64_MODIFIER "u usec", vw_endt);
proto_tree_add_uint64(vw_times_tree, hf_ixveriwave_vw_endt,
tvb, offset, 8, vw_endt);
offset +=8;
length_remaining -=8;
@ -814,35 +812,31 @@ wlantap_dissect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree
phdr.signal_dbm = dbm;
col_add_fstr(pinfo->cinfo, COL_RSSI, "%d dBm", dbm);
if (tap_tree) {
proto_tree_add_int_format_value(tap_tree,
proto_tree_add_int(tap_tree,
hf_radiotap_dbm_antsignal,
tvb, offset, 1, dbm,
"%d dBm", dbm);
tvb, offset, 1, dbm);
}
offset++;
dbm = (gint8) tvb_get_guint8(tvb, offset);
if (tap_tree && dbm != 100) {
proto_tree_add_int_format_value(tap_tree,
proto_tree_add_int(tap_tree,
hf_radiotap_dbm_antb,
tvb, offset, 1, dbm,
"%d dBm", dbm);
tvb, offset, 1, dbm);
}
offset++;
dbm = (gint8) tvb_get_guint8(tvb, offset);
if (tap_tree && dbm != 100) {
proto_tree_add_int_format_value(tap_tree,
proto_tree_add_int(tap_tree,
hf_radiotap_dbm_antc,
tvb, offset, 1, dbm,
"%d dBm", dbm);
tvb, offset, 1, dbm);
}
offset++;
dbm = (gint8) tvb_get_guint8(tvb, offset);
if (tap_tree && dbm != 100) {
proto_tree_add_int_format_value(tap_tree,
proto_tree_add_int(tap_tree,
hf_radiotap_dbm_antd,
tvb, offset, 1, dbm,
"%d dBm", dbm);
tvb, offset, 1, dbm);
}
offset+=2;
@ -1274,11 +1268,11 @@ void proto_register_ixveriwave(void)
{ &hf_ixveriwave_vw_startt,
{ "Frame start timestamp", "ixveriwave.startt",
FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
FT_UINT64, BASE_DEC|BASE_UNIT_STRING, &units_microseconds, 0x0, NULL, HFILL } },
{ &hf_ixveriwave_vw_endt,
{ "Frame end timestamp", "ixveriwave.endt",
FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
FT_UINT64, BASE_DEC|BASE_UNIT_STRING, &units_microseconds, 0x0, NULL, HFILL } },
{ &hf_ixveriwave_vw_pktdur,
{ "Packet duration", "ixveriwave.pktdur",
@ -1447,22 +1441,22 @@ framing signal deasserted. this is caused by software setting the drain all reg
{ &hf_radiotap_dbm_antsignal,
{ "SSI Signal", "ixveriwave.dbm_antsignal",
FT_INT32, BASE_DEC, NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF signal power at the antenna from a fixed, arbitrary value in decibels from one milliwatt", HFILL } },
{ &hf_radiotap_dbm_antb,
{ "SSI Signal for Antenna B", "ixveriwave.dbm_antb",
FT_INT32, BASE_DEC, NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF signal power at the antenna from a fixed, arbitrary value in decibels from one milliwatt", HFILL } },
{ &hf_radiotap_dbm_antc,
{ "SSI Signal for Antenna C", "ixveriwave.dbm_antc",
FT_INT32, BASE_DEC, NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF signal power at the antenna from a fixed, arbitrary value in decibels from one milliwatt", HFILL } },
{ &hf_radiotap_dbm_antd,
{ "SSI Signal for Antenna D", "ixveriwave.dbm_antd",
FT_INT32, BASE_DEC, NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING, &units_dbm, 0x0,
"RF signal power at the antenna from a fixed, arbitrary value in decibels from one milliwatt", HFILL } },
/* Boolean 'present' flags */

View File

@ -475,7 +475,7 @@ dissect_osc_message(tvbuff_t *tvb, proto_item *ti, proto_tree *osc_tree, gint of
bi = proto_tree_add_none_format(message_tree, hf_osc_message_blob_type, tvb, offset, 4+slen, "Blob: %i bytes", blen);
blob_tree = proto_item_add_subtree(bi, ett_osc_blob);
proto_tree_add_int_format_value(blob_tree, hf_osc_message_blob_size_type, tvb, offset, 4, blen, "%i bytes", blen);
proto_tree_add_int(blob_tree, hf_osc_message_blob_size_type, tvb, offset, 4, blen);
offset += 4;
/* check for zero length blob */
@ -768,10 +768,10 @@ dissect_osc_bundle(tvbuff_t *tvb, proto_item *ti, proto_tree *osc_tree, gint off
while(offset < end)
{
/* peek bundle element size */
gint32 size = tvb_get_ntohl(tvb, offset);
gint32 size;
/* read bundle element size */
proto_tree_add_int_format_value(bundle_tree, hf_osc_bundle_element_size_type, tvb, offset, 4, size, "%i bytes", size);
proto_tree_add_item_ret_int(bundle_tree, hf_osc_bundle_element_size_type, tvb, offset, 4, ENC_BIG_ENDIAN, &size);
offset += 4;
/* check for zero size bundle element */
@ -1112,8 +1112,8 @@ proto_register_osc(void)
"Scheduled bundle execution time", HFILL } },
{ &hf_osc_bundle_element_size_type, { "Size", "osc.bundle.element.size",
FT_INT32, BASE_DEC,
NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING,
&units_byte_bytes, 0x0,
"Bundle element size", HFILL } },
{ &hf_osc_message_type, { "Message", "osc.message",
@ -1151,8 +1151,8 @@ proto_register_osc(void)
NULL, 0x0,
"Binary blob value", HFILL } },
{ &hf_osc_message_blob_size_type, { "Size", "osc.message.blob.size",
FT_INT32, BASE_DEC,
NULL, 0x0,
FT_INT32, BASE_DEC|BASE_UNIT_STRING,
&units_byte_bytes, 0x0,
"Binary blob size", HFILL } },
{ &hf_osc_message_blob_data_type, { "Data", "osc.message.blob.data",
FT_BYTES, BASE_NONE,

View File

@ -598,6 +598,7 @@ static const int *tcp_option_mptcp_dss_flags[] = {
NULL
};
const unit_name_string units_64bit_version = { " (64bits version)", NULL };
static void
tcp_src_prompt(packet_info *pinfo, gchar *result)
@ -4007,8 +4008,8 @@ dissect_tcpopt_mptcp(const ip_tcp_opt *optp _U_, tvbuff_t *tvb,
hf_mptcp_expected_token, tvb, offset, 0, tcpd->fwd->mptcp_subflow->meta->token);
PROTO_ITEM_SET_GENERATED(item);
item = proto_tree_add_uint64_format_value(mptcp_tree,
hf_mptcp_expected_idsn, tvb, offset, 0, tcpd->fwd->mptcp_subflow->meta->base_dsn, "%" G_GINT64_MODIFIER "u (64bits version)", tcpd->fwd->mptcp_subflow->meta->base_dsn);
item = proto_tree_add_uint64(mptcp_tree,
hf_mptcp_expected_idsn, tvb, offset, 0, tcpd->fwd->mptcp_subflow->meta->base_dsn);
PROTO_ITEM_SET_GENERATED(item);
/* last ACK of 3WHS, repeats both keys */
@ -7357,7 +7358,7 @@ proto_register_tcp(void)
{ &hf_mptcp_expected_idsn,
{ "Subflow expected IDSN", "mptcp.expected_idsn", FT_UINT64,
BASE_DEC, NULL, 0x0, NULL, HFILL}},
BASE_DEC|BASE_UNIT_STRING, &units_64bit_version, 0x0, NULL, HFILL}},
{ &hf_mptcp_analysis_subflows_stream_id,
{ "List subflow Stream IDs", "mptcp.analysis.subflows.streamid", FT_UINT16,

View File

@ -1557,9 +1557,9 @@ dissect_nt_sid(tvbuff_t *tvb, int offset, proto_tree *parent_tree,
/* Add revision, num_auth, and authority */
proto_tree_add_item(subtree, hf_nt_sid_revision, tvb, offset_sid_start, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(subtree, hf_nt_sid_num_auth, tvb, offset_sid_start+1, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_uint64_format_value(subtree,
proto_tree_add_uint64(subtree,
(sid_display_hex ? hf_nt_sid_auth_hex : hf_nt_sid_auth_dec),
tvb, offset_sid_start+2, 6, authority, "%" G_GINT64_MODIFIER "u", authority);
tvb, offset_sid_start+2, 6, authority);
/* Add subauthorities */
proto_tree_add_string_format_value(subtree, hf_nt_sid_subauth, tvb, sa_offset,

View File

@ -62,6 +62,7 @@ const unit_name_string units_nanosecond_nanoseconds = { " nanosecond", " nanosec
const unit_name_string units_nanometers = { "nm", NULL };
const unit_name_string units_degree_degrees = { " degree", " degrees" };
const unit_name_string units_decibals = { "dB", NULL };
const unit_name_string units_dbm = { "dBm", NULL };
const unit_name_string units_percent = { "%", NULL };
const unit_name_string units_mhz = { "MHz", NULL };
const unit_name_string units_ghz = { "GHz", NULL };

View File

@ -61,6 +61,7 @@ WS_DLL_PUBLIC const unit_name_string units_nanosecond_nanoseconds; // full unit
WS_DLL_PUBLIC const unit_name_string units_nanometers;
WS_DLL_PUBLIC const unit_name_string units_degree_degrees;
WS_DLL_PUBLIC const unit_name_string units_decibals;
WS_DLL_PUBLIC const unit_name_string units_dbm;
WS_DLL_PUBLIC const unit_name_string units_percent;
WS_DLL_PUBLIC const unit_name_string units_ghz;
WS_DLL_PUBLIC const unit_name_string units_mhz;