Skip to content

Commit

Permalink
Keep a copy of the interface description and capture filter around so…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
geraldcombs committed Apr 1, 2010
1 parent dc5e066 commit cc5d767
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
13 changes: 9 additions & 4 deletions capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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!");
}
Expand Down
8 changes: 7 additions & 1 deletion capture_ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include <ctype.h>
#include <glib.h>

#include <epan/prefs.h>
#include "epan/prefs.h"
#include "epan/ex-opt.h"
#include "capture_ifinfo.h"
#include "capture_ui_utils.h"

Expand Down Expand Up @@ -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? */
Expand Down
1 change: 1 addition & 0 deletions cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
39 changes: 38 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
*/
18 changes: 18 additions & 0 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 2 additions & 5 deletions gtk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit cc5d767

Please sign in to comment.