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-06 01:19:42 +0000 |
commit | d96d0d5399c90fd25e0c44d5fd8e4fa128f10321 (patch) | |
tree | f096e302e9006218e6dbfa31970bcf82975f7cc8 /capture_ui_utils.c | |
parent | 2f87e4aa270b42829de1ee235bfc5e6edab1c195 (diff) | |
download | wireshark-d96d0d5399c90fd25e0c44d5fd8e4fa128f10321.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>
(cherry picked from commit d4bfa9c43b05ccbdef212f55fb56b73a5033e5f6)
Reviewed-on: https://code.wireshark.org/review/7935
Diffstat (limited to 'capture_ui_utils.c')
-rw-r--r-- | capture_ui_utils.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/capture_ui_utils.c b/capture_ui_utils.c index d0c5d2d0f5..f0b83a3cfa 100644 --- a/capture_ui_utils.c +++ b/capture_ui_utils.c @@ -593,4 +593,54 @@ 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 */ |