forked from osmocom/wireshark
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>
This commit is contained in:
parent
24af6eeeea
commit
d4bfa9c43b
27
tshark.c
27
tshark.c
|
@ -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);
|
||||
|
|
31
ui/capture.c
31
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 */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
/*
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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, ":");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue