diff options
author | Michael Mann <mmann78@netscape.net> | 2016-12-11 19:16:52 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-12-13 13:08:39 +0000 |
commit | 4e97f74f1156db5c2cb139a404bc6423cebf7236 (patch) | |
tree | bce553ff7dbbe9977fb1adbfc2dc6440be0307c4 /epan/unit_strings.c | |
parent | 97b41a494c214161b358cc99fad843a6f061b283 (diff) | |
download | wireshark-4e97f74f1156db5c2cb139a404bc6423cebf7236.tar.gz |
Add support for adding unit names to hf_ fields.
This was inspired by the https://www.wireshark.org/lists/wireshark-dev/201505/msg00029.html thread.
Used TCP and NTP dissectors as the guinea pig with sample use.
Documentation updates includes some unrelated cleanup just because it was noticed.
Change-Id: I59b26e1ca3b95e3473e4757f1759d7ad82976965
Reviewed-on: https://code.wireshark.org/review/19211
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/unit_strings.c')
-rw-r--r-- | epan/unit_strings.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/epan/unit_strings.c b/epan/unit_strings.c new file mode 100644 index 0000000000..27b066937d --- /dev/null +++ b/epan/unit_strings.c @@ -0,0 +1,69 @@ +/* unit_strings.c + * Units to append to field values + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#include <wsutil/str_util.h> +#include "unit_strings.h" + +char* unit_name_string_get_value(guint32 value, unit_name_string* units) +{ + if (units->plural == NULL) + return units->singular; + + return plurality(value, units->singular, units->plural); +} + +char* unit_name_string_get_value64(guint64 value, unit_name_string* units) +{ + if (units->plural == NULL) + return units->singular; + + return plurality(value, units->singular, units->plural); +} + +/* + * A default set of unit strings that dissectors can use for + * header fields. Some units intentionally have a space + * character in them for spacing between unit and value + */ +const unit_name_string units_foot_feet = { " foot", " feet" }; +const unit_name_string units_bit_bits = { " bit", " bits" }; +const unit_name_string units_byte_bytes = { " byte", " bytes" }; +const unit_name_string units_word_words = { " word", " words" }; +const unit_name_string units_second_seconds = { " second", " seconds" }; +const unit_name_string units_seconds = { "s", NULL }; +const unit_name_string units_millisecond_milliseconds = { " millisecond", " milliseconds" }; +const unit_name_string units_milliseconds = { "ms", NULL }; + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */
\ No newline at end of file |