aboutsummaryrefslogtreecommitdiffstats
path: root/capinfos.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-06-05 18:04:23 -0700
committerGuy Harris <guy@alum.mit.edu>2016-06-06 01:04:55 +0000
commitf9be95c4c8ab3484e6cf396e0cf4242b18ff8841 (patch)
treede6b8561e7ed4519aab54e029fc15d84a5fb1885 /capinfos.c
parentadee6850898a5469850a157c5816996691855ed2 (diff)
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 <guy@alum.mit.edu>
Diffstat (limited to 'capinfos.c')
-rw-r--r--capinfos.c223
1 files changed, 60 insertions, 163 deletions
diff --git a/capinfos.c b/capinfos.c
index d1cfa23837..55554ae8da 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -559,86 +559,15 @@ string_replace_newlines(gchar *str)
}
static void
-show_comment(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
+show_option_string(const char *prefix, const char *option_str)
{
- char *opt_str;
-
- switch(option_id)
- {
- case OPT_COMMENT:
- if (option != NULL && option->stringval != NULL) {
- opt_str = g_strdup(option->stringval);
- string_replace_newlines(opt_str);
- printf("Capture comment: %s\n", opt_str);
- g_free(opt_str);
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
-show_capture_hardware(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- char *opt_str;
-
- switch(option_id)
- {
- case OPT_SHB_HARDWARE:
- if (option != NULL && option->stringval != NULL) {
- opt_str = g_strdup(option->stringval);
- string_replace_newlines(opt_str);
- printf("Capture hardware: %s\n", opt_str);
- g_free(opt_str);
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
+ char *str;
-static void
-show_capture_os(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- char *opt_str;
-
- switch(option_id)
- {
- case OPT_SHB_OS:
- if (option != NULL && option->stringval != NULL) {
- opt_str = g_strdup(option->stringval);
- string_replace_newlines(opt_str);
- printf("Capture oper-sys: %s\n", opt_str);
- g_free(opt_str);
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
-show_capture_userappl(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- char *opt_str;
-
- switch(option_id)
- {
- case OPT_SHB_USERAPPL:
- if (option != NULL && option->stringval != NULL) {
- opt_str = g_strdup(option->stringval);
- string_replace_newlines(opt_str);
- printf("Capture application: %s\n", opt_str);
- g_free(opt_str);
- }
- break;
- default:
- /* Don't show other options */
- break;
+ if (option_str != NULL && option_str[0] != '\0') {
+ str = g_strdup(option_str);
+ string_replace_newlines(str);
+ printf("%s%s\n", prefix, str);
+ g_free(str);
}
}
@@ -766,12 +695,24 @@ print_stats(const gchar *filename, capture_info *cf_info)
if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order));
if (cap_comment) {
- wtap_optionblock_foreach_option(cf_info->shb, show_comment, NULL);
+ GArray *opts;
+ unsigned int i;
+
+ wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts);
+ for (i = 0; i < opts->len; i++) {
+ show_option_string("Capture comment: ", g_array_index(opts, char *, i));
+ }
+ g_array_free(opts, TRUE);
}
if (cap_file_more_info) {
- wtap_optionblock_foreach_option(cf_info->shb, show_capture_hardware, NULL);
- wtap_optionblock_foreach_option(cf_info->shb, show_capture_os, NULL);
- wtap_optionblock_foreach_option(cf_info->shb, show_capture_userappl, NULL);
+ char *str;
+
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str);
+ show_option_string("Capture hardware: ", str);
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str);
+ show_option_string("Capture oper-sys: ", str);
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str);
+ show_option_string("Capture application: ", str);
}
if (cap_file_idb && cf_info->num_interfaces != 0) {
@@ -850,82 +791,6 @@ print_stats_table_header(void)
}
static void
-put_comment(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- switch(option_id)
- {
- case OPT_COMMENT:
- if (option != NULL && option->stringval != NULL) {
- putsep();
- putquote();
- printf("%s", option->stringval);
- putquote();
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
-put_capture_hardware(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- switch(option_id)
- {
- case OPT_SHB_HARDWARE:
- if (option != NULL && option->stringval != NULL) {
- putsep();
- putquote();
- printf("%s", option->stringval);
- putquote();
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
-put_capture_os(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- switch(option_id)
- {
- case OPT_SHB_OS:
- if (option != NULL && option->stringval != NULL) {
- putsep();
- putquote();
- printf("%s", option->stringval);
- putquote();
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
-put_capture_userappl(wtap_optionblock_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_option_type* option, void* user_data _U_)
-{
- switch(option_id)
- {
- case OPT_SHB_USERAPPL:
- if (option != NULL && option->stringval != NULL) {
- putsep();
- putquote();
- printf("%s", option->stringval);
- putquote();
- }
- break;
- default:
- /* Don't show other options */
- break;
- }
-}
-
-static void
print_stats_table(const gchar *filename, capture_info *cf_info)
{
const gchar *file_type_string, *file_encap_string;
@@ -1107,15 +972,47 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
* of options
*/
if (cap_comment) {
- wtap_optionblock_foreach_option(cf_info->shb, put_comment, NULL);
+ GArray *opts;
+ unsigned int i;
+
+ wtap_optionblock_get_string_options(cf_info->shb, OPT_COMMENT, &opts);
+ for (i = 0; i < opts->len; i++) {
+ const char *opt_comment = g_array_index(opts, char *, i);
+
+ if (opt_comment != NULL) {
+ putsep();
+ putquote();
+ printf("%s", opt_comment);
+ putquote();
+ }
+ }
+ g_array_free(opts, TRUE);
}
if (cap_file_more_info) {
- wtap_optionblock_foreach_option(cf_info->shb, put_capture_hardware, NULL);
-
- wtap_optionblock_foreach_option(cf_info->shb, put_capture_os, NULL);
+ char *str;
- wtap_optionblock_foreach_option(cf_info->shb, put_capture_userappl, NULL);
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_HARDWARE, &str);
+ if (str != NULL) {
+ putsep();
+ putquote();
+ printf("%s", str);
+ putquote();
+ }
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_OS, &str);
+ if (str != NULL) {
+ putsep();
+ putquote();
+ printf("%s", str);
+ putquote();
+ }
+ wtap_optionblock_get_option_string(cf_info->shb, OPT_SHB_USERAPPL, &str);
+ if (str != NULL) {
+ putsep();
+ putquote();
+ printf("%s", str);
+ putquote();
+ }
}
printf("\n");