From cc5d7670bde3072fdc4aa738c7643e50133c2cb2 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 1 Apr 2010 21:55:01 +0000 Subject: [PATCH] Keep a copy of the interface description and capture filter around so that we can use it in the main window title during and after capture. Add a "-X" option for providing a description for stdin. svn path=/trunk/; revision=32357 --- capture.c | 13 +++++++++---- capture_ui_utils.c | 8 +++++++- cfile.c | 1 + cfile.h | 1 + file.c | 39 ++++++++++++++++++++++++++++++++++++++- file.h | 18 ++++++++++++++++++ gtk/main.c | 7 ++----- 7 files changed, 76 insertions(+), 11 deletions(-) diff --git a/capture.c b/capture.c index 68f2fbb9d68..6b799e0e24e 100644 --- a/capture.c +++ b/capture.c @@ -133,7 +133,7 @@ gboolean capture_start(capture_options *capture_opts) { gboolean ret; - + GString *source = g_string_new(""); /* close the currently loaded capture file */ cf_close(capture_opts->cf); @@ -143,6 +143,13 @@ capture_start(capture_options *capture_opts) g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ..."); + g_string_printf(source, "%s", get_iface_description(capture_opts)); + if(capture_opts->cfilter && capture_opts->cfilter[0]) { + g_string_append_printf(source, " (%s)", capture_opts->cfilter); + } + cf_set_tempfile_source(capture_opts->cf, source->str); + g_string_free(source, TRUE); + /* try to start the capture child process */ ret = sync_pipe_start(capture_opts); if(!ret) { @@ -209,13 +216,12 @@ guint32 drops) { int err; - /* Capture succeeded; attempt to open the capture file. */ if (cf_open(capture_opts->cf, capture_opts->save_file, is_tempfile, &err) != CF_OK) { /* We're not doing a capture any more, so we don't have a save file. */ return FALSE; } - + /* Set the read filter to NULL. */ /* XXX - this is odd here; try to put it somewhere where it fits better */ cf_set_rfcode(capture_opts->cf, NULL); @@ -301,7 +307,6 @@ capture_input_new_file(capture_options *capture_opts, gchar *new_file) gboolean is_tempfile; int err; - if(capture_opts->state == CAPTURE_PREPARING) { g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!"); } diff --git a/capture_ui_utils.c b/capture_ui_utils.c index f64e638993c..f6ff8c3fb85 100644 --- a/capture_ui_utils.c +++ b/capture_ui_utils.c @@ -34,7 +34,8 @@ #include #include -#include +#include "epan/prefs.h" +#include "epan/ex-opt.h" #include "capture_ifinfo.h" #include "capture_ui_utils.h" @@ -155,6 +156,11 @@ get_interface_descriptive_name(const char *if_name) if (descr != NULL) { /* Yes - make a copy of that. */ descr = g_strdup(descr); + } else if (strcmp(if_name, "-") == 0) { + descr = g_strdup(ex_opt_get_nth("stdin_descr", 0)); + if (!descr) { + descr = g_strdup("Standard input"); + } } else { /* No, we don't have a user-supplied description; did we get one from the OS or libpcap? */ diff --git a/cfile.c b/cfile.c index d7e53298bf8..89ab953d40b 100644 --- a/cfile.c +++ b/cfile.c @@ -41,6 +41,7 @@ cap_file_init(capture_file *cf) cf->plist_end = NULL; cf->wth = NULL; cf->filename = NULL; + cf->source = NULL; cf->user_saved = FALSE; cf->is_tempfile = FALSE; cf->rfcode = NULL; diff --git a/cfile.h b/cfile.h index d46c4962ce0..f98f1e74f7d 100644 --- a/cfile.h +++ b/cfile.h @@ -44,6 +44,7 @@ typedef enum { typedef struct _capture_file { file_state state; /* Current state of capture file */ gchar *filename; /* Name of capture file */ + gchar *source; /* Temp file source, e.g. "Pipe from elsewhere" */ gboolean is_tempfile; /* Is capture file a temporary file? */ gboolean user_saved; /* If capture file is temporary, has it been saved by user yet? */ gint64 f_datalen; /* Size of capture file data (uncompressed) */ diff --git a/file.c b/file.c index bf233d5c7ca..eb6b9f060d5 100644 --- a/file.c +++ b/file.c @@ -1024,11 +1024,35 @@ cf_get_display_name(capture_file *cf) } else { /* The file we read is a temporary file from a live capture; we don't mention its name. */ - displayname = "(Untitled)"; + if (cf->source) { + displayname = cf->source; + } else { + displayname = "(Untitled)"; + } } return displayname; } +void cf_set_tempfile_source(capture_file *cf, gchar *source) { + if (cf->source) { + g_free(cf->source); + } + + if (source) { + cf->source = g_strdup(source); + } else { + cf->source = g_strdup(""); + } +} + +const gchar *cf_get_tempfile_source(capture_file *cf) { + if (!cf->source) { + return ""; + } + + return cf->source; +} + /* XXX - use a macro instead? */ int cf_get_packet_count(capture_file *cf) @@ -4623,3 +4647,16 @@ cf_reload(capture_file *cf) { we should free up our copy. */ g_free(filename); } + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 2 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=2 expandtab + * :indentSize=2:tabSize=2:noTabs=true: + */ diff --git a/file.h b/file.h index 0fe0bb43f2f..b546f3e86ff 100644 --- a/file.h +++ b/file.h @@ -170,6 +170,24 @@ cf_status_t cf_save(capture_file * cf, const char *fname, packet_range_t *range, */ const gchar *cf_get_display_name(capture_file *cf); +/** + * Set the source of the capture data for temporary files, e.g. + * "Interface eth0" or "Pipe from Pong" + * + * @param cf the capture file + * @param source the source description. this will be copied internally. + */ +void cf_set_tempfile_source(capture_file *cf, gchar *source); + +/** + * Get the source of the capture data for temporary files. Guaranteed to + * return a non-null value. The returned value should not be freed. + * + * @param cf the capture file + * @param source the source description. this will be copied internally. + */ +const gchar *cf_get_tempfile_source(capture_file *cf); + /** * Get the number of packets in the capture file. * diff --git a/gtk/main.c b/gtk/main.c index 93d667f2ae1..c853bf37ca6 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1457,12 +1457,9 @@ main_capture_set_main_window_title(capture_options *capture_opts) { GString *title = g_string_new(""); - if(capture_opts->iface) { - g_string_append_printf(title, "%s: ", get_iface_description(capture_opts)); - } g_string_append(title, "Capturing "); - if(capture_opts->cfilter && capture_opts->cfilter[0]) { - g_string_append_printf(title, "(%s) ", capture_opts->cfilter); + if(capture_opts->iface) { + g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf)); } g_string_append(title, "- Wireshark");