diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-04-05 16:42:35 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-04-05 23:43:01 +0000 |
commit | d4bfa9c43b05ccbdef212f55fb56b73a5033e5f6 (patch) | |
tree | 50d7e2029b9a8f002cd2e808bdf695a76a1173db | |
parent | 24af6eeeea3828bbf4e41ad70377aabc3f26252e (diff) |
Have a common routine for constructing strings listing interfaces.
We have a bunch of duplicated code to make those lists; make a common
routine for that. (dumpcap currently doesn't use it, as the routine in
question uses a routine in libui, which dumpcap doesn't use. We should
probably fix that.)
Change-Id: I9058bf3320d420b8713e90743618972da1d1c6ed
Reviewed-on: https://code.wireshark.org/review/7934
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | tshark.c | 27 | ||||
-rw-r--r-- | ui/capture.c | 31 | ||||
-rw-r--r-- | ui/capture_ui_utils.c | 50 | ||||
-rw-r--r-- | ui/capture_ui_utils.h | 17 | ||||
-rw-r--r-- | ui/gtk/capture_info_dlg.c | 39 | ||||
-rw-r--r-- | ui/gtk/main_statusbar.c | 18 |
6 files changed, 75 insertions, 107 deletions
@@ -2418,7 +2418,7 @@ capture(void) { gboolean ret; guint i; - GString *str = g_string_new(""); + GString *str; #ifdef USE_TSHARK_SELECT fd_set readfds; #endif @@ -2477,30 +2477,7 @@ capture(void) global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i); g_array_insert_val(global_capture_opts.ifaces, i, interface_opts); } -#ifdef _WIN32 - if (global_capture_opts.ifaces->len < 2) -#else - if (global_capture_opts.ifaces->len < 4) -#endif - { - for (i = 0; i < global_capture_opts.ifaces->len; i++) { - interface_options interface_opts; - - interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); - if (i > 0) { - if (global_capture_opts.ifaces->len > 2) { - g_string_append_printf(str, ","); - } - g_string_append_printf(str, " "); - if (i == global_capture_opts.ifaces->len - 1) { - g_string_append_printf(str, "and "); - } - } - g_string_append_printf(str, "'%s'", interface_opts.descr); - } - } else { - g_string_append_printf(str, "%u interfaces", global_capture_opts.ifaces->len); - } + str = get_iface_list_string(&global_capture_opts, IFLIST_QUOTE_IF_DESCRIPTION); if (really_quiet == FALSE) fprintf(stderr, "Capturing on %s\n", str->str); fflush(stderr); diff --git a/ui/capture.c b/ui/capture.c index 64f28dbf50..011421c550 100644 --- a/ui/capture.c +++ b/ui/capture.c @@ -132,38 +132,11 @@ gboolean capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void)) { gboolean ret; - guint i; - GString *source = g_string_new(""); + GString *source; cap_session->state = CAPTURE_PREPARING; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ..."); -#ifdef _WIN32 - if (capture_opts->ifaces->len < 2) { -#else - if (capture_opts->ifaces->len < 4) { -#endif - for (i = 0; i < capture_opts->ifaces->len; i++) { - interface_options interface_opts; - - interface_opts = g_array_index(capture_opts->ifaces, interface_options, i); - if (i > 0) { - if (capture_opts->ifaces->len > 2) { - g_string_append_printf(source, ","); - } - g_string_append_printf(source, " "); - if (i == capture_opts->ifaces->len - 1) { - g_string_append_printf(source, "and "); - } - } - g_string_append_printf(source, "%s", get_iface_description_for_interface(capture_opts, i)); - if ((interface_opts.cfilter != NULL) && - (strlen(interface_opts.cfilter) > 0)) { - g_string_append_printf(source, " (%s)", interface_opts.cfilter); - } - } - } else { - g_string_append_printf(source, "%u interfaces", capture_opts->ifaces->len); - } + source = get_iface_list_string(capture_opts, IFLIST_SHOW_FILTER); cf_set_tempfile_source((capture_file *)cap_session->cf, source->str); g_string_free(source, TRUE); /* try to start the capture child process */ diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index 1d60aed891..b6aa4ad1d8 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -549,6 +549,56 @@ set_active_dlt(interface_t *device, int global_default_dlt) } } +GString * +get_iface_list_string(capture_options *capture_opts, guint32 style) +{ + GString *iface_list_string = g_string_new(""); + guint i; + + /* + * If we have a descriptive name for the interface, show that, + * rather than its raw name. On NT 5.x (2K/XP/Server2K3), the + * interface name is something like "\Device\NPF_{242423..." + * which is pretty useless to the normal user. On other platforms, + * it might be less cryptic, but if a more descriptive name is + * available, we should still use that. + */ +#ifdef _WIN32 + if (capture_opts->ifaces->len < 2) { +#else + if (capture_opts->ifaces->len < 4) { +#endif + for (i = 0; i < capture_opts->ifaces->len; i++) { + if (i > 0) { + if (capture_opts->ifaces->len > 2) { + g_string_append_printf(iface_list_string, ","); + } + g_string_append_printf(iface_list_string, " "); + if (i == capture_opts->ifaces->len - 1) { + g_string_append_printf(iface_list_string, "and "); + } + } + if (style & IFLIST_QUOTE_IF_DESCRIPTION) + g_string_append_printf(iface_list_string, "'"); + g_string_append_printf(iface_list_string, "%s", get_iface_description_for_interface(capture_opts, i)); + if (style & IFLIST_QUOTE_IF_DESCRIPTION) + g_string_append_printf(iface_list_string, "'"); + if (style & IFLIST_SHOW_FILTER) { + interface_options interface_opts; + + interface_opts = g_array_index(capture_opts->ifaces, interface_options, i); + if (interface_opts.cfilter != NULL && + strlen(interface_opts.cfilter) > 0) { + g_string_append_printf(iface_list_string, " (%s)", interface_opts.cfilter); + } + } + } + } else { + g_string_append_printf(iface_list_string, "%u interfaces", capture_opts->ifaces->len); + } + return iface_list_string; +} + #endif /* HAVE_LIBPCAP */ /* diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h index 50fb13073a..eb4cdf9db5 100644 --- a/ui/capture_ui_utils.h +++ b/ui/capture_ui_utils.h @@ -158,6 +158,23 @@ const char *get_iface_description_for_interface(capture_options *capture_opts, g */ extern void set_active_dlt(interface_t *device, int global_default_dlt); +/** Get a descriptive string for a list of interfaces. + * + * @param capture_opts The capture_options structure that contains the interfaces + * @param style flags to indicate the style of string to use: + * + * IFLIST_QUOTE_IF_DESCRIPTION: put the interface descriptive string in + * single quotes + * + * IFLIST_SHOW_FILTER: include the capture filters in the string + * + * @return A GString set to the descriptive string + */ +#define IFLIST_QUOTE_IF_DESCRIPTION 0x00000001 +#define IFLIST_SHOW_FILTER 0x00000002 + +extern GString *get_iface_list_string(capture_options *capture_opts, guint32 style); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ui/gtk/capture_info_dlg.c b/ui/gtk/capture_info_dlg.c index 63158944f2..a3b392c0c8 100644 --- a/ui/gtk/capture_info_dlg.c +++ b/ui/gtk/capture_info_dlg.c @@ -118,7 +118,6 @@ capture_info_ui_create(capture_info *cinfo, capture_session *cap_session) capture_info_ui_t *info; gchar *cap_w_title; gchar *title_iface; - gchar *descr; GString *str; info = g_new0(capture_info_ui_t,1); @@ -152,42 +151,10 @@ capture_info_ui_create(capture_info *cinfo, capture_session *cap_session) info->counts[13].value_ptr = &(cinfo->counts->i2c_data); /* - * Create the dialog window, with a title that includes the interface. - * - * If we have a descriptive name for the interface, show that, - * rather than its raw name. On NT 5.x (2K/XP/Server2K3), the - * interface name is something like "\Device\NPF_{242423..." - * which is pretty useless to the normal user. On other platforms, - * it might be less cryptic, but if a more descriptive name is - * available, we should still use that. + * Create the dialog window, with a title that includes the interfaces + * on which we're capturing. */ - str = g_string_new(""); -#ifdef _WIN32 - if (capture_opts->ifaces->len < 2) -#else - if (capture_opts->ifaces->len < 4) -#endif - { - for (i = 0; i < capture_opts->ifaces->len; i++) { - interface_options interface_opts; - - interface_opts = g_array_index(capture_opts->ifaces, interface_options, i); - descr = get_interface_descriptive_name(interface_opts.name); - if (i > 0) { - if (capture_opts->ifaces->len > 2) { - g_string_append_printf(str, ","); - } - g_string_append_printf(str, " "); - if (i == capture_opts->ifaces->len - 1) { - g_string_append_printf(str, "and "); - } - } - g_string_append_printf(str, "%s", descr); - g_free(descr); - } - } else { - g_string_append_printf(str, "%u interfaces", capture_opts->ifaces->len); - } + str = get_iface_list_string(capture_opts, 0); title_iface = g_strdup_printf("Wireshark: Capture from %s", str->str); g_string_free(str, TRUE); cap_w_title = create_user_window_title(title_iface); diff --git a/ui/gtk/main_statusbar.c b/ui/gtk/main_statusbar.c index 1e5cb23d8a..44cd1207bd 100644 --- a/ui/gtk/main_statusbar.c +++ b/ui/gtk/main_statusbar.c @@ -811,25 +811,9 @@ statusbar_capture_prepared_cb(capture_session *cap_session _U_) static GString * statusbar_get_interface_names(capture_options *capture_opts) { - guint i; GString *interface_names; - interface_names = g_string_new(""); - -#ifdef _WIN32 - if (capture_opts->ifaces->len < 2) { -#else - if (capture_opts->ifaces->len < 4) { -#endif - for (i = 0; i < capture_opts->ifaces->len; i++) { - if (i > 0) { - g_string_append_printf(interface_names, ", "); - } - g_string_append_printf(interface_names, "%s", get_iface_description_for_interface(capture_opts, i)); - } - } else { - g_string_append_printf(interface_names, "%u interfaces", capture_opts->ifaces->len); - } + interface_names = get_iface_list_string(capture_opts, 0); if (strlen (interface_names->str) > 0) { g_string_append(interface_names, ":"); } |