Adjust proto_tree_add_xxx_format_value calls to use unit string
authorMichael Mann <mmann78@netscape.net>
Wed, 14 Dec 2016 22:34:56 +0000 (17:34 -0500)
committerMichael Mann <mmann78@netscape.net>
Fri, 16 Dec 2016 01:55:10 +0000 (01:55 +0000)
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>
debian/libwireshark0.symbols
epan/dissectors/packet-ieee80211-radio.c
epan/dissectors/packet-ieee80211-radiotap.c
epan/dissectors/packet-ixveriwave.c
epan/dissectors/packet-osc.c
epan/dissectors/packet-tcp.c
epan/dissectors/packet-windows-common.c
epan/unit_strings.c
epan/unit_strings.h

index 3ebf20756cea8c6ae0da46e7a6e3cdcee52a062d..1a2641f84b1373e57f58231ea50de603fdd35ae6 100644 (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
index c5205db1b4577bcab8ea9993a340d9cdc5d9d343..26c1171cbbfd04b28ebe7b48e50495283cf69051 100644 (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,
index cd4ffa9ef530587b66fa29928d6ba7a686d579e6..901fc2787900b09557a3124eebb3ce7d37b5a11e 100644 (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}},
 
index d50f4dd7820a80ec7ffd45d365d1490066752073..d0cd5c1c7ec8ed878ea1e74c27799eb1823f2ef1 100644 (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 */
index d62acb5acf1447ee3f2b682ecfc1da2dbcd207de..ccbd9ba838ae38a35115d3f37ff442692951eaff 100644 (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,
index ba52c1ff9eeea803cede459d1f7fda4a47e0dd77..3b412f4eb0f0c6fdf2f1ec0b2a1ad83886e2dfdd 100644 (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,
index 5b22b384acaa705f5d8830a839fd766fc1cccf43..1209d76c4d098d181341b9f3830425c36f47a6f6 100644 (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,
index cfcfeb9bcef7db7cba4ab4d90435c9188b381a51..4614eb2ce560edfa18b1579cf0f59c21922a2b0b 100644 (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 };
index c703f12c6c1dd6e76243b51eef5612e722f717fb..5c4997ff7139063509af87b4f4df3bcf0a483923 100644 (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;