Try to call get_interface_descriptive_name() as little as possible (storing the result in capture_opts) to avoid a performance hit during live capture (especially if you have lots of interfaces) and to avoid leaking memory. One issue with this is that capture_opts.c cannot (without adding significant dependencies) set the iface_descr so readers of that field (only gtk/main.c and tshark.c) use a macro to (set if not already set and) get the value of that field. svn path=/trunk/; revision=22587
This commit is contained in:
parent
914e885354
commit
2f77efce7d
|
@ -86,6 +86,7 @@ capture_opts_init(capture_options *capture_opts, void *cfile)
|
|||
capture_opts->cf = cfile;
|
||||
capture_opts->cfilter = g_strdup(""); /* No capture filter string specified */
|
||||
capture_opts->iface = NULL; /* Default is "pick the first interface" */
|
||||
capture_opts->iface_descr = NULL;
|
||||
#ifdef _WIN32
|
||||
capture_opts->buffer_size = 1; /* 1 MB */
|
||||
#endif
|
||||
|
@ -133,6 +134,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
|
|||
g_log(log_domain, log_level, "CFile : 0x%p", capture_opts->cf);
|
||||
g_log(log_domain, log_level, "Filter : %s", capture_opts->cfilter);
|
||||
g_log(log_domain, log_level, "Interface : %s", capture_opts->iface);
|
||||
g_log(log_domain, log_level, "Interface Descr : %s", capture_opts->iface_descr);
|
||||
#ifdef _WIN32
|
||||
g_log(log_domain, log_level, "BufferSize : %u (MB)", capture_opts->buffer_size);
|
||||
#endif
|
||||
|
@ -317,6 +319,10 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg)
|
|||
return 1;
|
||||
}
|
||||
capture_opts->iface = g_strdup(if_info->name);
|
||||
/* We don't set iface_descr here because doing so requires
|
||||
* capture_ui_utils.c which requires epan/prefs.c which is
|
||||
* probably a bit too much dependency for here...
|
||||
*/
|
||||
free_interface_list(if_list);
|
||||
} else {
|
||||
capture_opts->iface = g_strdup(optarg);
|
||||
|
@ -686,6 +692,10 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
|
|||
if (capture_device != NULL) {
|
||||
/* Yes - use it. */
|
||||
capture_opts->iface = g_strdup(capture_device);
|
||||
/* We don't set iface_descr here because doing so requires
|
||||
* capture_ui_utils.c which requires epan/prefs.c which is
|
||||
* probably a bit too much dependency for here...
|
||||
*/
|
||||
} else {
|
||||
/* No - pick the first one from the list of interfaces. */
|
||||
if_list = get_interface_list(&err, &err_str);
|
||||
|
@ -705,6 +715,10 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
|
|||
}
|
||||
if_info = if_list->data; /* first interface */
|
||||
capture_opts->iface = g_strdup(if_info->name);
|
||||
/* We don't set iface_descr here because doing so requires
|
||||
* capture_ui_utils.c which requires epan/prefs.c which is
|
||||
* probably a bit too much dependency for here...
|
||||
*/
|
||||
free_interface_list(if_list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,12 @@ typedef struct capture_options_tag {
|
|||
gboolean has_cfilter; /**< TRUE if capture filter specified on command line */
|
||||
gchar *cfilter; /**< Capture filter string */
|
||||
gchar *iface; /**< the network interface to capture from */
|
||||
gchar *iface_descr; /**< A human readable description of iface.
|
||||
*< NOTE: capture_opts.c is not able to
|
||||
*< set this field because doing so
|
||||
*< requires too many dependencies.
|
||||
*< Readers of this field should use
|
||||
*< GET_IFACE_DESCR to access it. */
|
||||
|
||||
#ifdef _WIN32
|
||||
int buffer_size; /**< the capture buffer size (MB) */
|
||||
|
@ -99,6 +105,14 @@ typedef struct capture_options_tag {
|
|||
gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
|
||||
} capture_options;
|
||||
|
||||
/* Get iface_descr (and set it if it's not set already).
|
||||
* It is assumed the caller includes capture_ui_utils.h (ugh, but what else
|
||||
* can we do?)
|
||||
*/
|
||||
#define GET_IFACE_DESCR(capture_opts) capture_opts->iface_descr ? \
|
||||
capture_opts->iface_descr : \
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface)
|
||||
|
||||
|
||||
/* initialize the capture_options with some reasonable values */
|
||||
extern void
|
||||
|
|
|
@ -100,6 +100,8 @@ capture_dev_user_descr_find(const gchar *if_name)
|
|||
* If the user has specified a comment, use that. Otherwise,
|
||||
* if get_interface_list() supplies a description, use that,
|
||||
* otherwise use the interface name.
|
||||
*
|
||||
* The result must be g_free()'d when you're done with it.
|
||||
*/
|
||||
char *
|
||||
get_interface_descriptive_name(const char *if_name)
|
||||
|
|
|
@ -696,6 +696,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
|
|||
make the one from the preferences file the default */
|
||||
if_device = g_strdup(prefs.capture_device);
|
||||
capture_opts->iface = g_strdup(get_if_name(if_device));
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
||||
g_free(if_device);
|
||||
}
|
||||
|
||||
|
@ -1316,7 +1317,8 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
|
|||
|
||||
/* everythings prepared, now it's really time to start the capture */
|
||||
void
|
||||
capture_start_confirmed(void) {
|
||||
capture_start_confirmed(void)
|
||||
{
|
||||
|
||||
|
||||
/* init iface, if never used before */
|
||||
|
@ -1338,6 +1340,7 @@ capture_start_confirmed(void) {
|
|||
if_device = g_strdup(prefs.capture_device);
|
||||
if_name = get_if_name(if_device);
|
||||
capture_opts->iface = g_strdup(if_name);
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
||||
|
||||
g_free(if_device);
|
||||
}
|
||||
|
@ -1516,7 +1519,10 @@ capture_dlg_prep(gpointer parent_w) {
|
|||
}
|
||||
if (capture_opts->iface)
|
||||
g_free(capture_opts->iface);
|
||||
if (capture_opts->iface_descr)
|
||||
g_free(capture_opts->iface_descr);
|
||||
capture_opts->iface = g_strdup(if_name);
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
||||
g_free(entry_text);
|
||||
/* The Linktype will be stored when the interface will be changed, or if not, not datalink option is used,
|
||||
the acquisition will be performed on the default datalink for the device */
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "capture_dlg.h"
|
||||
#include "capture_if_details_dlg.h"
|
||||
#include "capture_errs.h"
|
||||
#include "capture_ui_utils.h"
|
||||
#include "recent.h"
|
||||
#include <epan/prefs.h>
|
||||
|
||||
|
@ -136,8 +137,11 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data)
|
|||
|
||||
if (capture_opts->iface)
|
||||
g_free(capture_opts->iface);
|
||||
if (capture_opts->iface_descr)
|
||||
g_free(capture_opts->iface_descr);
|
||||
|
||||
capture_opts->iface = g_strdup(if_dlg_data->device);
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
||||
|
||||
/* XXX - remove this? */
|
||||
if (capture_opts->save_file) {
|
||||
|
@ -160,8 +164,11 @@ capture_prepare_cb(GtkWidget *prepare_bt _U_, gpointer if_data)
|
|||
|
||||
if (capture_opts->iface)
|
||||
g_free(capture_opts->iface);
|
||||
if (capture_opts->iface_descr)
|
||||
g_free(capture_opts->iface_descr);
|
||||
|
||||
capture_opts->iface = g_strdup(if_dlg_data->device);
|
||||
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
|
||||
|
||||
/* stop capturing from all interfaces, we are going to do real work now ... */
|
||||
window_destroy(cap_if_w);
|
||||
|
|
60
gtk/main.c
60
gtk/main.c
|
@ -1608,7 +1608,7 @@ main_cf_cb_live_capture_prepared(capture_options *capture_opts)
|
|||
|
||||
if(capture_opts->iface) {
|
||||
title = g_strdup_printf("%s: Capturing - Wireshark",
|
||||
get_interface_descriptive_name(capture_opts->iface));
|
||||
GET_IFACE_DESCR(capture_opts));
|
||||
} else {
|
||||
title = g_strdup_printf("Capturing - Wireshark");
|
||||
}
|
||||
|
@ -1643,7 +1643,7 @@ main_cf_cb_live_capture_update_started(capture_options *capture_opts)
|
|||
switching to the next multiple file. */
|
||||
if(capture_opts->iface) {
|
||||
title = g_strdup_printf("%s: Capturing - Wireshark",
|
||||
get_interface_descriptive_name(capture_opts->iface));
|
||||
GET_IFACE_DESCR(capture_opts));
|
||||
} else {
|
||||
title = g_strdup_printf("Capturing - Wireshark");
|
||||
}
|
||||
|
@ -1660,8 +1660,8 @@ main_cf_cb_live_capture_update_started(capture_options *capture_opts)
|
|||
|
||||
if(capture_opts->iface) {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
(capture_opts->save_file) ? capture_opts->save_file : "");
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
(capture_opts->save_file) ? capture_opts->save_file : "");
|
||||
} else {
|
||||
capture_msg = g_strdup_printf(" <live capture in progress> to file: %s",
|
||||
(capture_opts->save_file) ? capture_opts->save_file : "");
|
||||
|
@ -1687,39 +1687,45 @@ main_cf_cb_live_capture_update_continue(capture_file *cf)
|
|||
/* XXX - don't show the highest expert level unless the TCP checksum offloading is "solved" */
|
||||
if (cf->f_datalen/1024/1024 > 10) {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %lld MB [Expert: %s]",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024/1024,
|
||||
val_to_str(expert_get_highest_severity(), expert_severity_vals, "Unknown (%u)"));
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024/1024,
|
||||
val_to_str(expert_get_highest_severity(),
|
||||
expert_severity_vals,
|
||||
"Unknown (%u)"));
|
||||
} else if (cf->f_datalen/1024 > 10) {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %lld KB [Expert: %s]",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024,
|
||||
val_to_str(expert_get_highest_severity(), expert_severity_vals, "Unknown (%u)"));
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024,
|
||||
val_to_str(expert_get_highest_severity(),
|
||||
expert_severity_vals,
|
||||
"Unknown (%u)"));
|
||||
} else {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %lld Bytes [Expert: %s]",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen,
|
||||
val_to_str(expert_get_highest_severity(), expert_severity_vals, "Unknown (%u)"));
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen,
|
||||
val_to_str(expert_get_highest_severity(),
|
||||
expert_severity_vals,
|
||||
"Unknown (%u)"));
|
||||
}
|
||||
#endif
|
||||
if (cf->f_datalen/1024/1024 > 10) {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d MB",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024/1024);
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024/1024);
|
||||
} else if (cf->f_datalen/1024 > 10) {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d KB",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024);
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen/1024);
|
||||
} else {
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d Bytes",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen);
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
capture_opts->save_file,
|
||||
cf->f_datalen);
|
||||
}
|
||||
|
||||
statusbar_push_file_msg(capture_msg);
|
||||
|
@ -1782,8 +1788,8 @@ main_cf_cb_live_capture_fixed_started(capture_options *capture_opts)
|
|||
statusbar_pop_file_msg();
|
||||
|
||||
capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
|
||||
get_interface_descriptive_name(capture_opts->iface),
|
||||
(capture_opts->save_file) ? capture_opts->save_file : "");
|
||||
GET_IFACE_DESCR(capture_opts),
|
||||
(capture_opts->save_file) ? capture_opts->save_file : "");
|
||||
|
||||
statusbar_push_file_msg(capture_msg);
|
||||
gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, " P: 0");
|
||||
|
|
|
@ -123,10 +123,6 @@ summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
|
|||
{
|
||||
st->cfilter = capture_opts->cfilter;
|
||||
st->iface = capture_opts->iface;
|
||||
if(st->iface) {
|
||||
st->iface_descr = get_interface_descriptive_name(st->iface);
|
||||
} else {
|
||||
st->iface_descr = NULL;
|
||||
}
|
||||
st->iface_descr = GET_IFACE_DESCR(capture_opts);
|
||||
}
|
||||
#endif
|
||||
|
|
6
tshark.c
6
tshark.c
|
@ -1593,7 +1593,6 @@ capture(void)
|
|||
int pcap_cnt;
|
||||
condition *volatile cnd_autostop_size = NULL;
|
||||
condition *volatile cnd_autostop_duration = NULL;
|
||||
char *descr;
|
||||
#ifndef _WIN32
|
||||
void (*oldhandler)(int);
|
||||
#endif
|
||||
|
@ -1692,9 +1691,8 @@ capture(void)
|
|||
#endif /* _WIN32 */
|
||||
|
||||
/* Let the user know what interface was chosen. */
|
||||
descr = get_interface_descriptive_name(capture_opts.iface);
|
||||
fprintf(stderr, "Capturing on %s\n", descr);
|
||||
g_free(descr);
|
||||
capture_opts.iface_descr = get_interface_descriptive_name(capture_opts.iface);
|
||||
fprintf(stderr, "Capturing on %s\n", capture_opts.iface_descr);
|
||||
|
||||
/* initialize capture stop conditions */
|
||||
init_capture_stop_conditions();
|
||||
|
|
Loading…
Reference in New Issue