Separate the promiscuous mode, "Update list of packets in real time",

and "Automatic scrolling in live capture" options from the preference
settings for them, so that the preference settings affect the initial
values of those options, but changing those values in a capture don't
affect the preferences, and don't automatically get saved when you save
the preferences.

If we're building without libpcap, don't have an "Automatic scrolling in
live capture" option anywhere.

svn path=/trunk/; revision=4514
This commit is contained in:
Guy Harris 2002-01-10 11:05:50 +00:00
parent d663cdb4a1
commit b3f81eb30c
7 changed files with 68 additions and 35 deletions

View File

@ -1,7 +1,7 @@
/* capture.c /* capture.c
* Routines for packet capture windows * Routines for packet capture windows
* *
* $Id: capture.c,v 1.166 2002/01/08 09:32:14 guy Exp $ * $Id: capture.c,v 1.167 2002/01/10 11:05:48 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -169,6 +169,8 @@
#include "capture-wpcap.h" #include "capture-wpcap.h"
#endif #endif
int promisc_mode; /* capture in promiscuous mode */
int sync_mode; /* fork a child to do the capture, and sync between them */
static int sync_pipe[2]; /* used to sync father */ static int sync_pipe[2]; /* used to sync father */
enum PIPES { READ, WRITE }; /* Constants 0 and 1 for READ and WRITE */ enum PIPES { READ, WRITE }; /* Constants 0 and 1 for READ and WRITE */
int quit_after_cap; /* Makes a "capture only mode". Implies -k */ int quit_after_cap; /* Makes a "capture only mode". Implies -k */
@ -321,7 +323,7 @@ do_capture(char *capfile_name)
g_assert(cfile.save_file == NULL); g_assert(cfile.save_file == NULL);
cfile.save_file = capfile_name; cfile.save_file = capfile_name;
if (prefs.capture_real_time) { /* do the capture in a child process */ if (sync_mode) { /* do the capture in a child process */
char ssnap[24]; char ssnap[24];
char scount[24]; /* need a constant for len of numbers */ char scount[24]; /* need a constant for len of numbers */
char sautostop_filesize[24]; /* need a constant for len of numbers */ char sautostop_filesize[24]; /* need a constant for len of numbers */
@ -372,7 +374,7 @@ do_capture(char *capfile_name)
sprintf(sautostop_duration,"duration:%d",cfile.autostop_duration); sprintf(sautostop_duration,"duration:%d",cfile.autostop_duration);
argv = add_arg(argv, &argc, sautostop_duration); argv = add_arg(argv, &argc, sautostop_duration);
if (!prefs.capture_prom_mode) if (!promisc_mode)
argv = add_arg(argv, &argc, "-p"); argv = add_arg(argv, &argc, "-p");
#ifdef _WIN32 #ifdef _WIN32
@ -1343,7 +1345,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
if they succeed; to tell if that's happened, we have to clear if they succeed; to tell if that's happened, we have to clear
the error buffer, and check if it's still a null string. */ the error buffer, and check if it's still a null string. */
open_err_str[0] = '\0'; open_err_str[0] = '\0';
pch = pcap_open_live(cfile.iface, cfile.snap, prefs.capture_prom_mode, pch = pcap_open_live(cfile.iface, cfile.snap, promisc_mode,
CAP_READ_TIMEOUT, open_err_str); CAP_READ_TIMEOUT, open_err_str);
if (pch == NULL) { if (pch == NULL) {

View File

@ -1,7 +1,7 @@
/* capture.h /* capture.h
* Definitions for packet capture windows * Definitions for packet capture windows
* *
* $Id: capture.h,v 1.27 2002/01/08 09:32:14 guy Exp $ * $Id: capture.h,v 1.28 2002/01/10 11:05:48 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -31,6 +31,8 @@
/* Name we give to the child process when doing a "-S" capture. */ /* Name we give to the child process when doing a "-S" capture. */
#define CHILD_NAME "ethereal-capture" #define CHILD_NAME "ethereal-capture"
extern int promisc_mode; /* capture in promiscuous mode */
extern int sync_mode; /* fork a child to do the capture, and sync between them */
extern int sync_pipe[2]; /* used to sync father */ extern int sync_pipe[2]; /* used to sync father */
extern int quit_after_cap; /* Makes a "capture only mode". Implies -k */ extern int quit_after_cap; /* Makes a "capture only mode". Implies -k */
extern gboolean capture_child; /* if this is the child for "-S" */ extern gboolean capture_child; /* if this is the child for "-S" */

10
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.257 2002/01/05 04:12:14 gram Exp $ * $Id: file.c,v 1.258 2002/01/10 11:05:48 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -96,6 +96,10 @@
extern GtkWidget *packet_list, *byte_nb_ptr, *tree_view; extern GtkWidget *packet_list, *byte_nb_ptr, *tree_view;
#ifdef HAVE_LIBPCAP
gboolean auto_scroll_live;
#endif
static guint32 firstsec, firstusec; static guint32 firstsec, firstusec;
static guint32 prevsec, prevusec; static guint32 prevsec, prevusec;
@ -502,7 +506,7 @@ continue_tail_cap_file(capture_file *cf, int to_read, int *err)
/* XXX - this cheats and looks inside the packet list to find the final /* XXX - this cheats and looks inside the packet list to find the final
row number. */ row number. */
if (prefs.capture_auto_scroll && cf->plist_end != NULL) if (auto_scroll_live && cf->plist_end != NULL)
gtk_clist_moveto(GTK_CLIST(packet_list), gtk_clist_moveto(GTK_CLIST(packet_list),
GTK_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0); GTK_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0);
@ -549,7 +553,7 @@ finish_tail_cap_file(capture_file *cf, int *err)
} }
thaw_clist(cf); thaw_clist(cf);
if (prefs.capture_auto_scroll && cf->plist_end != NULL) if (auto_scroll_live && cf->plist_end != NULL)
/* XXX - this cheats and looks inside the packet list to find the final /* XXX - this cheats and looks inside the packet list to find the final
row number. */ row number. */
gtk_clist_moveto(GTK_CLIST(packet_list), gtk_clist_moveto(GTK_CLIST(packet_list),

View File

@ -1,7 +1,7 @@
/* globals.h /* globals.h
* Global defines, etc. * Global defines, etc.
* *
* $Id: globals.h,v 1.26 2001/06/05 07:38:33 guy Exp $ * $Id: globals.h,v 1.27 2002/01/10 11:05:48 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -34,6 +34,9 @@
extern capture_file cfile; extern capture_file cfile;
extern gchar *ethereal_path; extern gchar *ethereal_path;
extern gchar *last_open_dir; extern gchar *last_open_dir;
#ifdef HAVE_LIBPCAP
extern gboolean auto_scroll_live;
#endif
extern field_info *finfo_selected; extern field_info *finfo_selected;
extern ts_type timestamp_type; extern ts_type timestamp_type;

View File

@ -1,7 +1,7 @@
/* capture_dlg.c /* capture_dlg.c
* Routines for packet capture windows * Routines for packet capture windows
* *
* $Id: capture_dlg.c,v 1.53 2002/01/10 07:43:39 guy Exp $ * $Id: capture_dlg.c,v 1.54 2002/01/10 11:05:50 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -333,7 +333,7 @@ capture_prep_cb(GtkWidget *w, gpointer d)
promisc_cb = dlg_check_button_new_with_label_with_mnemonic( promisc_cb = dlg_check_button_new_with_label_with_mnemonic(
"Capture packets in _promiscuous mode", accel_group); "Capture packets in _promiscuous mode", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb), prefs.capture_prom_mode); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb), promisc_mode);
gtk_container_add(GTK_CONTAINER(main_vb), promisc_cb); gtk_container_add(GTK_CONTAINER(main_vb), promisc_cb);
gtk_widget_show(promisc_cb); gtk_widget_show(promisc_cb);
@ -347,7 +347,7 @@ capture_prep_cb(GtkWidget *w, gpointer d)
/* Ring buffer mode is allowed only if we're not doing an "Update list of /* Ring buffer mode is allowed only if we're not doing an "Update list of
packets in real time" capture, so force it off if we're doing such packets in real time" capture, so force it off if we're doing such
a capture. */ a capture. */
if (prefs.capture_real_time) if (sync_mode)
cfile.ringbuffer_on = FALSE; cfile.ringbuffer_on = FALSE;
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_on_tb),cfile.ringbuffer_on); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_on_tb),cfile.ringbuffer_on);
gtk_signal_connect(GTK_OBJECT(ringbuffer_on_tb), "toggled", gtk_signal_connect(GTK_OBJECT(ringbuffer_on_tb), "toggled",
@ -371,7 +371,7 @@ capture_prep_cb(GtkWidget *w, gpointer d)
/* Misc row: Capture file checkboxes */ /* Misc row: Capture file checkboxes */
sync_cb = dlg_check_button_new_with_label_with_mnemonic( sync_cb = dlg_check_button_new_with_label_with_mnemonic(
"_Update list of packets in real time", accel_group); "_Update list of packets in real time", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb), prefs.capture_real_time); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb), sync_mode);
gtk_signal_connect(GTK_OBJECT(sync_cb), "toggled", gtk_signal_connect(GTK_OBJECT(sync_cb), "toggled",
GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w));
gtk_container_add(GTK_CONTAINER(main_vb), sync_cb); gtk_container_add(GTK_CONTAINER(main_vb), sync_cb);
@ -379,7 +379,7 @@ capture_prep_cb(GtkWidget *w, gpointer d)
auto_scroll_cb = dlg_check_button_new_with_label_with_mnemonic( auto_scroll_cb = dlg_check_button_new_with_label_with_mnemonic(
"_Automatic scrolling in live capture", accel_group); "_Automatic scrolling in live capture", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(auto_scroll_cb), prefs.capture_auto_scroll); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(auto_scroll_cb), auto_scroll_live);
gtk_container_add(GTK_CONTAINER(main_vb), auto_scroll_cb); gtk_container_add(GTK_CONTAINER(main_vb), auto_scroll_cb);
gtk_widget_show(auto_scroll_cb); gtk_widget_show(auto_scroll_cb);
@ -682,18 +682,18 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
else if (cfile.snap < MIN_PACKET_SIZE) else if (cfile.snap < MIN_PACKET_SIZE)
cfile.snap = MIN_PACKET_SIZE; cfile.snap = MIN_PACKET_SIZE;
prefs.capture_prom_mode = GTK_TOGGLE_BUTTON (promisc_cb)->active; promisc_mode = GTK_TOGGLE_BUTTON (promisc_cb)->active;
prefs.capture_real_time = GTK_TOGGLE_BUTTON (sync_cb)->active; sync_mode = GTK_TOGGLE_BUTTON (sync_cb)->active;
prefs.capture_auto_scroll = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active; auto_scroll_live = GTK_TOGGLE_BUTTON (auto_scroll_cb)->active;
prefs.name_resolve = PREFS_RESOLV_NONE; prefs.name_resolve = PREFS_RESOLV_NONE;
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE); prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? PREFS_RESOLV_MAC : PREFS_RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE); prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? PREFS_RESOLV_NETWORK : PREFS_RESOLV_NONE);
prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE); prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? PREFS_RESOLV_TRANSPORT : PREFS_RESOLV_NONE);
cfile.ringbuffer_on = GTK_TOGGLE_BUTTON (ringbuffer_on_tb)->active && !(prefs.capture_real_time); cfile.ringbuffer_on = GTK_TOGGLE_BUTTON (ringbuffer_on_tb)->active && !(sync_mode);
if (cfile.ringbuffer_on == TRUE) { if (cfile.ringbuffer_on == TRUE) {
if (save_file == NULL) { if (save_file == NULL) {
simple_dialog(ESD_TYPE_CRIT, NULL, simple_dialog(ESD_TYPE_CRIT, NULL,

View File

@ -1,7 +1,7 @@
/* display_opts.c /* display_opts.c
* Routines for packet display windows * Routines for packet display windows
* *
* $Id: display_opts.c,v 1.22 2001/06/18 06:18:03 guy Exp $ * $Id: display_opts.c,v 1.23 2002/01/10 11:05:50 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -64,11 +64,13 @@
extern capture_file cfile; extern capture_file cfile;
/* Display callback data keys */ /* Display callback data keys */
#define E_DISPLAY_TIME_ABS_KEY "display_time_abs" #define E_DISPLAY_TIME_ABS_KEY "display_time_abs"
#define E_DISPLAY_DATE_TIME_ABS_KEY "display_date_time_abs" #define E_DISPLAY_DATE_TIME_ABS_KEY "display_date_time_abs"
#define E_DISPLAY_TIME_REL_KEY "display_time_rel" #define E_DISPLAY_TIME_REL_KEY "display_time_rel"
#define E_DISPLAY_TIME_DELTA_KEY "display_time_delta" #define E_DISPLAY_TIME_DELTA_KEY "display_time_delta"
#define E_DISPLAY_AUTO_SCROLL_KEY "display_auto_scroll" #ifdef HAVE_LIBPCAP
#define E_DISPLAY_AUTO_SCROLL_KEY "display_auto_scroll"
#endif
#define E_DISPLAY_M_NAME_RESOLUTION_KEY "display_mac_name_resolution" #define E_DISPLAY_M_NAME_RESOLUTION_KEY "display_mac_name_resolution"
#define E_DISPLAY_N_NAME_RESOLUTION_KEY "display_network_name_resolution" #define E_DISPLAY_N_NAME_RESOLUTION_KEY "display_network_name_resolution"
#define E_DISPLAY_T_NAME_RESOLUTION_KEY "display_transport_name_resolution" #define E_DISPLAY_T_NAME_RESOLUTION_KEY "display_transport_name_resolution"
@ -169,13 +171,15 @@ display_opt_cb(GtkWidget *w, gpointer d) {
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
gtk_widget_show(button); gtk_widget_show(button);
#ifdef HAVE_LIBPCAP
button = dlg_check_button_new_with_label_with_mnemonic( button = dlg_check_button_new_with_label_with_mnemonic(
"_Automatic scrolling in live capture", accel_group); "_Automatic scrolling in live capture", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), prefs.capture_auto_scroll); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), auto_scroll_live);
gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_AUTO_SCROLL_KEY, gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_AUTO_SCROLL_KEY,
button); button);
gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
gtk_widget_show(button); gtk_widget_show(button);
#endif
button = dlg_check_button_new_with_label_with_mnemonic( button = dlg_check_button_new_with_label_with_mnemonic(
"Enable _MAC name resolution", accel_group); "Enable _MAC name resolution", accel_group);
@ -282,9 +286,11 @@ get_display_options(GtkWidget *parent_w)
if (GTK_TOGGLE_BUTTON (button)->active) if (GTK_TOGGLE_BUTTON (button)->active)
timestamp_type = DELTA; timestamp_type = DELTA;
#ifdef HAVE_LIBPCAP
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w), button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
E_DISPLAY_AUTO_SCROLL_KEY); E_DISPLAY_AUTO_SCROLL_KEY);
prefs.capture_auto_scroll = (GTK_TOGGLE_BUTTON (button)->active); auto_scroll_live = (GTK_TOGGLE_BUTTON (button)->active);
#endif
prefs.name_resolve = PREFS_RESOLV_NONE; prefs.name_resolve = PREFS_RESOLV_NONE;
button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w), button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),

View File

@ -1,6 +1,6 @@
/* main.c /* main.c
* *
* $Id: main.c,v 1.224 2002/01/10 09:51:23 guy Exp $ * $Id: main.c,v 1.225 2002/01/10 11:05:50 guy Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com> * By Gerald Combs <gerald@ethereal.com>
@ -1062,9 +1062,20 @@ main(int argc, char *argv[])
to the "prefs.capture_prom_mode" setting in the preferences file; to the "prefs.capture_prom_mode" setting in the preferences file;
it should do what the parent process tells it to do, and if it should do what the parent process tells it to do, and if
the parent process wants it not to run in promiscuous mode, it'll the parent process wants it not to run in promiscuous mode, it'll
tell it so with a "-p" flag. */ tell it so with a "-p" flag.
Otherwise, set promiscuous mode from the preferences setting. */
if (capture_child) if (capture_child)
prefs->capture_prom_mode = TRUE; promisc_mode = TRUE;
else
promisc_mode = prefs->capture_prom_mode;
/* Set "Update list of packets in real time" mode from the preferences
setting. */
sync_mode = prefs->capture_real_time;
/* And do the same for "Automatic scrolling in live capture" mode. */
auto_scroll_live = prefs->capture_auto_scroll;
#endif #endif
/* Read the capture filter file. */ /* Read the capture filter file. */
@ -1226,7 +1237,12 @@ main(int argc, char *argv[])
#endif #endif
break; break;
case 'l': /* Automatic scrolling in live capture mode */ case 'l': /* Automatic scrolling in live capture mode */
prefs->capture_auto_scroll = TRUE; #ifdef HAVE_LIBPCAP
auto_scroll_live = TRUE;
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#endif
break; break;
case 'm': /* Fixed-width font for the display */ case 'm': /* Fixed-width font for the display */
if (prefs->gui_font_name != NULL) if (prefs->gui_font_name != NULL)
@ -1264,7 +1280,7 @@ main(int argc, char *argv[])
break; break;
case 'p': /* Don't capture in promiscuous mode */ case 'p': /* Don't capture in promiscuous mode */
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
prefs->capture_prom_mode = FALSE; promisc_mode = FALSE;
#else #else
capture_option_specified = TRUE; capture_option_specified = TRUE;
arg_error = TRUE; arg_error = TRUE;
@ -1301,7 +1317,7 @@ main(int argc, char *argv[])
break; break;
case 'S': /* "Sync" mode: used for following file ala tail -f */ case 'S': /* "Sync" mode: used for following file ala tail -f */
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
prefs->capture_real_time = TRUE; sync_mode = TRUE;
#else #else
capture_option_specified = TRUE; capture_option_specified = TRUE;
arg_error = TRUE; arg_error = TRUE;
@ -1411,15 +1427,15 @@ main(int argc, char *argv[])
if (cfile.ringbuffer_on) { if (cfile.ringbuffer_on) {
/* Ring buffer works only under certain conditions: /* Ring buffer works only under certain conditions:
a) ring buffer does not work with temporary files; a) ring buffer does not work with temporary files;
b) prefs->capture_real_time and cfile.ringbuffer_on are mutually b) sync_mode and cfile.ringbuffer_on are mutually exclusive -
exclusive - prefs->capture_real_time takes precedence; sync_mode takes precedence;
c) it makes no sense to enable the ring buffer if the maximum c) it makes no sense to enable the ring buffer if the maximum
file size is set to "infinite". */ file size is set to "infinite". */
if (cfile.save_file == NULL) { if (cfile.save_file == NULL) {
fprintf(stderr, "ethereal: Ring buffer requested, but capture isn't being saved to a permanent file.\n"); fprintf(stderr, "ethereal: Ring buffer requested, but capture isn't being saved to a permanent file.\n");
cfile.ringbuffer_on = FALSE; cfile.ringbuffer_on = FALSE;
} }
if (prefs->capture_real_time == TRUE) { if (sync_mode) {
fprintf(stderr, "ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.\n"); fprintf(stderr, "ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.\n");
cfile.ringbuffer_on = FALSE; cfile.ringbuffer_on = FALSE;
} }