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 /ui/capture_ui_utils.c | |
parent | 24af6eeeea3828bbf4e41ad70377aabc3f26252e (diff) | |
download | wireshark-d4bfa9c43b05ccbdef212f55fb56b73a5033e5f6.tar.gz |
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>
Diffstat (limited to 'ui/capture_ui_utils.c')
-rw-r--r-- | ui/capture_ui_utils.c | 50 |
1 files changed, 50 insertions, 0 deletions
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 */ /* |