Commit 95ae2fe1 authored by Michael Tüxen's avatar Michael Tüxen

Use a global list containing all interfaces and only change

properties of the entries when changes are made in the GUI.
Do not misuse the list of interfaces specified on the command
line anymore.

This patch does not provide any new functionality, it just
provides the base for future extensions like removing
remote interface, mulitple airpcap devices and multiple
pipes.

This patch was provided by Irene Ruengeler.

svn path=/trunk/; revision=39495
parent 151acb8f
......@@ -143,6 +143,7 @@ capture_start(capture_options *capture_opts)
/* close the currently loaded capture file */
cf_close(capture_opts->cf);
collect_ifaces(capture_opts);
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
#ifdef _WIN32
......@@ -651,6 +652,9 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
}
/* ... and start the capture again */
if (capture_opts->ifaces->len == 0) {
collect_ifaces(capture_opts);
}
capture_start(capture_opts);
} else {
/* We're not doing a capture any more, so we don't have a save file. */
......@@ -660,13 +664,13 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
}
if_stat_cache_t *
capture_stat_start(GList *if_list) {
capture_stat_start(capture_options *capture_opts) {
int stat_fd, fork_child;
gchar *msg;
if_stat_cache_t *sc = NULL;
GList *if_entry;
if_info_t *if_info;
if_stat_cache_item_t *sc_item;
guint i;
interface_t device;
/* Fire up dumpcap. */
/*
......@@ -694,11 +698,11 @@ capture_stat_start(GList *if_list) {
sc->cache_list = NULL;
/* Initialize the cache */
for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
if_info = if_entry->data;
if (if_info) {
for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i);
if (&(device.if_info)) {
sc_item = g_malloc0(sizeof(if_stat_cache_item_t));
sc_item->name = g_strdup(if_info->name);
sc_item->name = g_strdup(device.if_info.name);
sc->cache_list = g_list_append(sc->cache_list, sc_item);
}
}
......
......@@ -110,7 +110,7 @@ typedef struct if_stat_cache_s if_stat_cache_t;
* @param if_list A GList of if_info_t items
* @return A pointer to the statistics state data.
*/
extern if_stat_cache_t * capture_stat_start(GList *if_list);
extern if_stat_cache_t * capture_stat_start(capture_options *capture_opts);
/**
* Fetch capture statistics, similar to pcap_stats().
......
......@@ -38,6 +38,9 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include "simple_dialog.h"
#include "capture_ui_utils.h"
#include "capture_opts.h"
#include "ringbuffer.h"
......@@ -57,6 +60,8 @@ capture_opts_init(capture_options *capture_opts, void *cf)
{
capture_opts->cf = cf;
capture_opts->ifaces = g_array_new(FALSE, FALSE, sizeof(interface_options));
capture_opts->all_ifaces = g_array_new(FALSE, FALSE, sizeof(interface_t));
capture_opts->num_selected = 0;
capture_opts->default_options.name = NULL;
capture_opts->default_options.descr = NULL;
capture_opts->default_options.cfilter = NULL;
......@@ -522,7 +527,83 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
#endif
g_array_append_val(capture_opts->ifaces, interface_opts);
return 0;
}
int
capture_opts_select_iface(capture_options *capture_opts, const char *optarg_str_p)
{
long adapter_index;
char *p;
GList *if_list;
if_info_t *if_info;
int err;
guint i;
gchar *err_str, *name = NULL;
interface_t device;
/*
* If the argument is a number, treat it as an index into the list
* of adapters, as printed by "tshark -D".
*
* This should be OK on UNIX systems, as interfaces shouldn't have
* names that begin with digits. It can be useful on Windows, where
* more than one interface can have the same name.
*/
adapter_index = strtol(optarg_str_p, &p, 10);
if (p != NULL && *p == '\0') {
if (adapter_index < 0) {
cmdarg_err("The specified adapter index is a negative number");
return 1;
}
if (adapter_index > INT_MAX) {
cmdarg_err("The specified adapter index is too large (greater than %d)",
INT_MAX);
return 1;
}
if (adapter_index == 0) {
cmdarg_err("There is no interface with that adapter index");
return 1;
}
if_list = capture_interface_list(&err, &err_str);
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
cmdarg_err("%s", err_str);
g_free(err_str);
break;
case NO_INTERFACES_FOUND:
cmdarg_err("There are no interfaces on which a capture can be done");
break;
}
return 2;
}
if_info = (if_info_t *)g_list_nth_data(if_list, adapter_index - 1);
if (if_info == NULL) {
cmdarg_err("There is no interface with that adapter index");
return 1;
}
name = 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 {
name = g_strdup(optarg_str_p);
}
for(i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i);
if (strcmp(device.name, name) == 0) {
device.selected = TRUE;
capture_opts->num_selected++;
capture_opts->all_ifaces = g_array_remove_index(capture_opts->all_ifaces, i);
g_array_insert_val(capture_opts->all_ifaces, i, device);
break;
}
}
return 0;
}
......@@ -826,7 +907,7 @@ gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capt
/* Did the user specify an interface to use? */
if (capture_opts->ifaces->len == 0) {
if (capture_opts->num_selected == 0 && capture_opts->ifaces->len == 0) {
/* No - is a default specified in the preferences file? */
if (capture_device != NULL) {
/* Yes - use it. */
......@@ -957,4 +1038,49 @@ static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_
return 0;
}
void
collect_ifaces(capture_options *capture_opts)
{
guint i;
interface_t device;
interface_options interface_opts;
for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i);
if (device.selected) {
interface_opts.name = g_strdup(device.name);
interface_opts.descr = g_strdup(device.display_name);
interface_opts.monitor_mode = device.monitor_mode_enabled;
interface_opts.linktype = device.active_dlt;
interface_opts.cfilter = g_strdup(device.cfilter);
interface_opts.snaplen = device.snaplen;
interface_opts.has_snaplen = device.has_snaplen;
interface_opts.promisc_mode = device.pmode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = device.buffer;
#endif
if (device.type == IF_REMOTE) {
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = device.type;
interface_opts.remote_host = g_strdup(device.remote_opts.remote_host_opts.remote_host);
interface_opts.remote_port = g_strdup(device.remote_opts.remote_host_opts.remote_port);
interface_opts.auth_type = device.remote_opts.remote_host_opts.auth_type;
interface_opts.auth_username = g_strdup(device.remote_opts.remote_host_opts.auth_username);
interface_opts.auth_password = g_strdup(device.remote_opts.remote_host_opts.auth_password);
interface_opts.datatx_udp = device.remote_opts.remote_host_opts.datatx_udp;
interface_opts.nocap_rpcap = device.remote_opts.remote_host_opts.nocap_rpcap;
interface_opts.nocap_local = device.remote_opts.remote_host_opts.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = device.remote_opts.sampling_method;
interface_opts.sampling_param = device.remote_opts.sampling_param;
#endif
}
g_array_append_val(capture_opts->ifaces, interface_opts);
} else {
continue;
}
}
}
#endif /* HAVE_LIBPCAP */
......@@ -73,6 +73,66 @@ typedef enum {
} capture_sampling;
#endif
typedef enum {
IF_LOCAL,
IF_REMOTE,
IF_AIRPCAP
} interface_type;
#ifdef HAVE_PCAP_REMOTE
struct remote_host {
gchar *remote_host; /**< Host name or network address for remote capturing */
gchar *remote_port; /**< TCP port of remote RPCAP server */
gint auth_type; /**< Authentication type */
gchar *auth_username; /**< Remote authentication parameters */
gchar *auth_password; /**< Remote authentication parameters */
gboolean datatx_udp;
gboolean nocap_rpcap;
gboolean nocap_local;
};
typedef struct remote_options_tag {
capture_source src_type;
struct remote_host remote_host_opts;
#ifdef HAVE_PCAP_SETSAMPLING
capture_sampling sampling_method;
int sampling_param;
#endif
} remote_options;
#endif /* HAVE_PCAP_REMOTE */
typedef struct interface_tag {
gchar *name;
gchar *display_name;
guint type;
gchar *addresses;
gint no_addresses;
gchar *cfilter;
GList *links;
gint active_dlt;
gboolean pmode;
gboolean has_snaplen;
guint snaplen;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
gint buffer;
gboolean monitor_mode_enabled;
gboolean monitor_mode_supported;
#endif
#ifdef HAVE_PCAP_REMOTE
remote_options remote_opts;
#endif
guint32 last_packets;
if_info_t if_info;
gboolean selected;
gboolean hidden;
gboolean locked;
} interface_t;
typedef struct link_row_tag {
gchar *name;
gint dlt;
} link_row;
typedef struct interface_options_tag {
gchar *name;
gchar *descr;
......@@ -108,6 +168,8 @@ typedef struct capture_options_tag {
void *cf; /**< handle to cfile (note: untyped handle) */
GArray *ifaces; /**< array of interfaces.
Currently only used by dumpcap. */
GArray *all_ifaces;
guint num_selected;
interface_options default_options;
gboolean saving_to_file; /**< TRUE if capture is writing to a file */
gchar *save_file; /**< the capture file name */
......@@ -190,4 +252,25 @@ capture_opts_trim_ring_num_files(capture_options *capture_opts);
extern gboolean
capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device);
extern void
collect_ifaces(capture_options *capture_opts);
typedef struct {
gboolean monitor_mode;
int linktype;
} cap_settings_t;
/** Get capture settings for interface
*
* @param if_name interface name
*/
cap_settings_t
capture_get_cap_settings (gchar *if_name);
extern void
scan_local_interfaces(capture_options* capture_opts);
int
capture_opts_select_iface(capture_options *capture_opts, const char *optarg_str_p);
#endif /* capture_opts.h */
......@@ -461,9 +461,11 @@ sync_pipe_start(capture_options *capture_opts) {
}
#endif
#ifdef HAVE_PCAP_CREATE
if (interface_opts.monitor_mode) {
argv = sync_pipe_add_arg(argv, &argc, "-I");
}
#endif
#ifdef HAVE_PCAP_REMOTE
if (interface_opts.datatx_udp)
......
......@@ -38,6 +38,9 @@
#include "epan/ex-opt.h"
#include "capture_ifinfo.h"
#include "capture_ui_utils.h"
#include "simple_dialog.h"
#include "wiretap/wtap.h"
#include "epan/to_str.h"
/*
* Find user-specified capture device description that matches interface
......
This diff is collapsed.
......@@ -32,60 +32,12 @@
* @ingroup dialog_group
*/
#include "capture_opts.h"
#ifdef HAVE_PCAP_REMOTE
struct remote_host {
gchar *remote_host; /**< Host name or network address for remote capturing */
gchar *remote_port; /**< TCP port of remote RPCAP server */
gint auth_type; /**< Authentication type */
gchar *auth_username; /**< Remote authentication parameters */
gchar *auth_password; /**< Remote authentication parameters */
gboolean datatx_udp;
gboolean nocap_rpcap;
gboolean nocap_local;
};
typedef struct remote_options_tag {
capture_source src_type;
struct remote_host remote_host_opts;
#ifdef HAVE_PCAP_SETSAMPLING
capture_sampling sampling_method;
int sampling_param;
#endif
} remote_options;
#endif /* HAVE_PCAP_REMOTE */
typedef struct row_options_tag {
gchar *name;
gchar *display_name;
gchar *addresses;
gint no_addresses;
gchar *cfilter;
GList *links;
gint active_dlt;
gboolean pmode;
#ifdef HAVE_PCAP_CREATE
gboolean monitor_mode_enabled;
gboolean monitor_mode_supported;
#endif
gboolean has_snaplen;
guint snaplen;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
gint buffer;
#endif
#ifdef HAVE_PCAP_REMOTE
remote_options remote_opts;
#endif
} interface_row;
typedef struct link_row_tag {
gchar *name;
gint dlt;
} link_row;
#include <gtk/gtk.h>
enum
{
CAPTURE = 0,
IFACE_HIDDEN_NAME,
INTERFACE,
LINK,
PMODE,
......@@ -143,6 +95,7 @@ void capture_start_confirmed(void);
void
capture_air_cb(GtkWidget *widget, gpointer data);
#if 0
/*
* We remember the capture settings for each interface when a capture
* is started on it; the next time we select that interface we start
......@@ -163,6 +116,7 @@ typedef struct {
*/
cap_settings_t
capture_get_cap_settings (gchar *if_name);
#endif
GtkTreeModel*
create_and_fill_model (GtkTreeView *view);
......@@ -202,9 +156,12 @@ gboolean
dlg_window_present(void);
void
enable_selected_interface(gchar *name, gboolean enable);
enable_selected_interface(gchar *name, gboolean selected);
void
options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column _U_, gpointer userdata);
void
update_all_rows(void);
#endif /* capture_dlg.h */
This diff is collapsed.
......@@ -51,7 +51,7 @@ GtkWidget *
capture_get_if_icon(const if_info_t* if_info);
void
update_selected_interface(gchar *name, gboolean activate);
update_selected_interface(gchar *name);
gboolean
interfaces_dialog_window_present(void);
......@@ -65,6 +65,9 @@ select_all_interfaces(gboolean enable);
void
destroy_if_window(void);
gint
if_list_comparator_alph (const void *first_arg, const void *second_arg);
#endif /* HAVE_LIBPCAP */
#endif /* capture_if_dlg.h */
......
This diff is collapsed.
......@@ -26,6 +26,7 @@
#define __MAIN_H__
#include "globals.h"
#include "capture_opts.h"
/** @defgroup main_window_group Main window
* The main window has the following submodules:
......@@ -365,4 +366,6 @@ extern GList *get_ip_address_list_from_packet_list_row(gpointer data);
extern GtkWidget *pkt_scrollw;
void hide_interface(gchar* new_hide);
#endif /* __MAIN_H__ */
This diff is collapsed.
......@@ -40,15 +40,6 @@ typedef struct selected_name_s {
gboolean activate;
} selected_name_t;
typedef struct displayed_interface_s {
gchar *name;
gchar *descr;
GtkWidget *icon;
#ifdef HAVE_PCAP_REMOTE
remote_options remote_opts;
#endif
} displayed_interface;
GtkWidget *welcome_new(void);
/* reset the list of recently used files */
......@@ -60,6 +51,8 @@ void main_welcome_add_recent_capture_file(const char *widget_cf_name, GObject *m
/* reload the list of interfaces */
void welcome_if_panel_reload(void);
void welcome_if_tree_load(void);
/** Push a status message into the welcome screen header similar to
* statusbar_push_*_msg(). This hides everything under the header.
* If msg is dynamically allocated, it is up to the caller to free
......@@ -85,10 +78,10 @@ void change_interface_selection(gchar* name, gboolean activate);
void change_selection_for_all(gboolean enable);
void update_welcome_list(void);
#ifdef HAVE_PCAP_REMOTE
void add_interface_to_list(gchar *name, gchar *descr, remote_options *remote_opts);
void add_interface_to_list(guint index);
#endif
displayed_interface get_interface_data(gint index);
#endif /* __MAIN_WELCOME_H__ */
......@@ -1434,6 +1434,7 @@ ifopts_write_new_hide(void)
g_free(new_hide);
prefs.capture_devices_hide = NULL;
}
hide_interface(strdup(new_hide));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment