From f9be95c4c8ab3484e6cf396e0cf4242b18ff8841 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 5 Jun 2016 18:04:23 -0700 Subject: Add a routine to get an array of all instances of a string option. Use it for OPT_COMMENT in the SHB, as there may be ore than one instance of OPT_COMMENT in an SHB. Also, use wtap_optionblock_get_option_string for OPT_SHB_HARDWARE, OPT_SHB_OS, and OPT_SHB_USERAPPL; they're specified as "only one instance allowed". Change-Id: I23ad87e41e40b7ae1155e96c0523a6f8caad5204 Reviewed-on: https://code.wireshark.org/review/15750 Reviewed-by: Guy Harris --- wiretap/wtap_opttypes.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'wiretap/wtap_opttypes.c') diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c index d87fd3b805..296a6fb29d 100644 --- a/wiretap/wtap_opttypes.c +++ b/wiretap/wtap_opttypes.c @@ -374,6 +374,36 @@ wtap_opttype_return_val wtap_optionblock_get_option_string(wtap_optionblock_t bl return WTAP_OPTTYPE_SUCCESS; } +wtap_opttype_return_val wtap_optionblock_get_string_options(wtap_optionblock_t block, guint option_id, GArray **value) +{ + guint n_options; + guint i; + wtap_optblock_value_t* opt_value; + GArray *opt_values; + + n_options = 0; + for (i = 0; i < block->option_values->len; i++) + { + opt_value = g_array_index(block->option_values, wtap_optblock_value_t*, i); + if (opt_value->info->number == option_id) { + if (opt_value->info->type != WTAP_OPTTYPE_STRING) + return WTAP_OPTTYPE_TYPE_MISMATCH; + n_options++; + } + } + + opt_values = g_array_sized_new(FALSE, FALSE, sizeof (char *), n_options); + for (i = 0; i < block->option_values->len; i++) + { + opt_value = g_array_index(block->option_values, wtap_optblock_value_t*, i); + if (opt_value->info->number == option_id) + g_array_append_val(opt_values, opt_value->option.stringval); + } + + *value = opt_values; + return WTAP_OPTTYPE_SUCCESS; +} + wtap_opttype_return_val wtap_optionblock_set_option_uint64(wtap_optionblock_t block, guint option_id, guint64 value) { wtap_optblock_value_t* opt_value = wtap_optionblock_get_option(block, option_id); -- cgit v1.2.1