From 541c654ff07e1f85dbd1a54b18fea0579d79dfa3 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 24 Feb 2002 09:25:36 +0000 Subject: Put all the capture options into a structure. Move the ringbuffer capture options from the "capture_file" structure to the structure for capture options, as they're a property of an in-progress capture, not a property of a particular capture file. svn path=/trunk/; revision=4799 --- capture.c | 75 ++++++++++++++++++------------------ capture.h | 33 ++++++++++------ file.h | 6 +-- gtk/capture_dlg.c | 101 ++++++++++++++++++++++++++++-------------------- gtk/main.c | 87 +++++++++++++++++++++--------------------- tethereal.c | 112 ++++++++++++++++++++++++++++++++---------------------- 6 files changed, 227 insertions(+), 187 deletions(-) diff --git a/capture.c b/capture.c index 82f4bbc94c..25a09cfed9 100644 --- a/capture.c +++ b/capture.c @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.170 2002/02/24 03:33:04 guy Exp $ + * $Id: capture.c,v 1.171 2002/02/24 09:25:34 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -172,16 +172,7 @@ /* * Capture options. */ -gboolean has_snaplen; -int snaplen; -int promisc_mode; /* capture in promiscuous mode */ -int sync_mode; /* fork a child to do the capture, and sync between them */ -gboolean has_autostop_count; -int autostop_count; -gboolean has_autostop_filesize; -gint32 autostop_filesize; -gboolean has_autostop_duration; -gint32 autostop_duration; +capture_options capture_opts; static int sync_pipe[2]; /* used to sync father */ enum PIPES { READ, WRITE }; /* Constants 0 and 1 for READ and WRITE */ @@ -303,12 +294,14 @@ do_capture(char *capfile_name) struct pcap_stat stats; if (capfile_name != NULL) { - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* ringbuffer is enabled */ - cfile.save_file_fd = ringbuf_init(capfile_name, cfile.ringbuffer_num_files); + cfile.save_file_fd = ringbuf_init(capfile_name, + capture_opts.ringbuffer_num_files); } else { /* Try to open/create the specified file for use as a capture buffer. */ - cfile.save_file_fd = open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 0600); + cfile.save_file_fd = open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, + 0600); } is_tempfile = FALSE; } else { @@ -323,7 +316,7 @@ do_capture(char *capfile_name) "The temporary file to which the capture would be saved (\"%s\")" "could not be opened: %s.", capfile_name, strerror(errno)); } else { - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ringbuf_error_cleanup(); } simple_dialog(ESD_TYPE_CRIT, NULL, @@ -335,7 +328,7 @@ do_capture(char *capfile_name) g_assert(cfile.save_file == NULL); cfile.save_file = capfile_name; - if (sync_mode) { /* do the capture in a child process */ + if (capture_opts.sync_mode) { /* do the capture in a child process */ char ssnap[24]; char scount[24]; /* need a constant for len of numbers */ char sautostop_filesize[24]; /* need a constant for len of numbers */ @@ -370,31 +363,31 @@ do_capture(char *capfile_name) sprintf(save_file_fd,"%d",cfile.save_file_fd); /* in lieu of itoa */ argv = add_arg(argv, &argc, save_file_fd); - if (has_autostop_count) { + if (capture_opts.has_autostop_count) { argv = add_arg(argv, &argc, "-c"); - sprintf(scount,"%d",autostop_count); + sprintf(scount,"%d",capture_opts.autostop_count); argv = add_arg(argv, &argc, scount); } - if (has_snaplen) { + if (capture_opts.has_snaplen) { argv = add_arg(argv, &argc, "-s"); - sprintf(ssnap,"%d",snaplen); + sprintf(ssnap,"%d",capture_opts.snaplen); argv = add_arg(argv, &argc, ssnap); } - if (has_autostop_filesize) { + if (capture_opts.has_autostop_filesize) { argv = add_arg(argv, &argc, "-a"); - sprintf(sautostop_filesize,"filesize:%d",autostop_filesize); + sprintf(sautostop_filesize,"filesize:%d",capture_opts.autostop_filesize); argv = add_arg(argv, &argc, sautostop_filesize); } - if (has_autostop_duration) { + if (capture_opts.has_autostop_duration) { argv = add_arg(argv, &argc, "-a"); - sprintf(sautostop_duration,"duration:%d",autostop_duration); + sprintf(sautostop_duration,"duration:%d",capture_opts.autostop_duration); argv = add_arg(argv, &argc, sautostop_duration); } - if (!promisc_mode) + if (!capture_opts.promisc_mode) argv = add_arg(argv, &argc, "-p"); #ifdef _WIN32 @@ -684,7 +677,7 @@ do_capture(char *capfile_name) } /* We're not doing a capture any more, so we don't have a save file. */ - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ringbuf_free(); } else { g_free(cfile.save_file); @@ -1339,8 +1332,8 @@ capture(gboolean *stats_known, struct pcap_stat *stats) ld.go = TRUE; ld.counts.total = 0; - if (has_autostop_count) - ld.max = autostop_count; + if (capture_opts.has_autostop_count) + ld.max = capture_opts.autostop_count; else ld.max = 0; /* no limit */ ld.err = 0; /* no error seen yet */ @@ -1369,8 +1362,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats) the error buffer, and check if it's still a null string. */ open_err_str[0] = '\0'; pch = pcap_open_live(cfile.iface, - has_snaplen ? snaplen : WTAP_MAX_PACKET_SIZE, - promisc_mode, CAP_READ_TIMEOUT, open_err_str); + capture_opts.has_snaplen ? capture_opts.snaplen : + WTAP_MAX_PACKET_SIZE, + capture_opts.promisc_mode, CAP_READ_TIMEOUT, + open_err_str); if (pch == NULL) { #ifdef _WIN32 @@ -1483,7 +1478,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats) " that Ethereal doesn't support (data link type %d).", pcap_encap); goto error; } - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ld.pdh = ringbuf_init_wtap_dump_fdopen(WTAP_FILE_PCAP, ld.linktype, file_snaplen, &err); } else { @@ -1617,10 +1612,12 @@ capture(gboolean *stats_known, struct pcap_stat *stats) /* initialize capture stop conditions */ init_capture_stop_conditions(); /* create stop conditions */ - if (has_autostop_filesize) - cnd_stop_capturesize = cnd_new(CND_CLASS_CAPTURESIZE,(long)autostop_filesize * 1000); - if (has_autostop_duration) - cnd_stop_timeout = cnd_new(CND_CLASS_TIMEOUT,(gint32)autostop_duration); + if (capture_opts.has_autostop_filesize) + cnd_stop_capturesize = + cnd_new(CND_CLASS_CAPTURESIZE,(long)capture_opts.autostop_filesize * 1000); + if (capture_opts.has_autostop_duration) + cnd_stop_timeout = + cnd_new(CND_CLASS_TIMEOUT,(gint32)capture_opts.autostop_duration); while (ld.go) { while (gtk_events_pending()) gtk_main_iteration(); @@ -1706,7 +1703,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats) } else if (cnd_stop_capturesize != NULL && cnd_eval(cnd_stop_capturesize, (guint32)wtap_get_bytes_dumped(ld.pdh))){ /* Capture file reached its maximum size. */ - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* Switch to the next ringbuffer file */ if (ringbuf_switch_file(&cfile, &ld.pdh, &ld.err)) { /* File switch succeeded: reset the condition */ @@ -1788,13 +1785,13 @@ capture(gboolean *stats_known, struct pcap_stat *stats) /* A write failed, so we've already told the user there's a problem; if the close fails, there's no point in telling them about that as well. */ - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ringbuf_wtap_dump_close(&cfile, &err); } else { wtap_dump_close(ld.pdh, &err); } } else { - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { dump_ok = ringbuf_wtap_dump_close(&cfile, &err); } else { dump_ok = wtap_dump_close(ld.pdh, &err); @@ -1857,7 +1854,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats) return TRUE; error: - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* cleanup ringbuffer */ ringbuf_error_cleanup(); } else { diff --git a/capture.h b/capture.h index d3eb6e853c..5269b4e74a 100644 --- a/capture.h +++ b/capture.h @@ -1,7 +1,7 @@ /* capture.h * Definitions for packet capture windows * - * $Id: capture.h,v 1.30 2002/02/24 03:33:04 guy Exp $ + * $Id: capture.h,v 1.31 2002/02/24 09:25:34 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -31,16 +31,27 @@ /* Name we give to the child process when doing a "-S" capture. */ #define CHILD_NAME "ethereal-capture" -extern gboolean has_snaplen; /* TRUE if maximum capture packet length is specified */ -extern int snaplen; /* Maximum captured packet length */ -extern int promisc_mode; /* capture in promiscuous mode */ -extern int sync_mode; /* fork a child to do the capture, and sync between them */ -extern gboolean has_autostop_count; -extern int autostop_count; -extern gboolean has_autostop_filesize; /* TRUE if maximum capture file size is specified */ -extern gint32 autostop_filesize; /* Maximum capture file size */ -extern gboolean has_autostop_duration; /* TRUE if maximum capture duration is specified */ -extern gint32 autostop_duration; /* Maximum capture duration */ +typedef struct { + gboolean has_snaplen; /* TRUE if maximum capture packet + length is specified */ + int snaplen; /* Maximum captured packet length */ + int promisc_mode; /* Capture in promiscuous mode */ + int sync_mode; /* Fork a child to do the capture, + and sync between them */ + gboolean has_autostop_count; /* TRUE if maximum packet count is + specified */ + int autostop_count; /* Maximum packet count */ + gboolean has_autostop_duration; /* TRUE if maximum capture duration + is specified */ + gint32 autostop_duration; /* Maximum capture duration */ + gboolean has_autostop_filesize; /* TRUE if maximum capture file size + is specified */ + gint32 autostop_filesize; /* Maximum capture file size */ + gboolean ringbuffer_on; /* TRUE if ring buffer in use */ + guint32 ringbuffer_num_files; /* Number of ring buffer files */ +} capture_options; + +extern capture_options capture_opts; extern int sync_pipe[2]; /* used to sync father */ extern int quit_after_cap; /* Makes a "capture only mode". Implies -k */ diff --git a/file.h b/file.h index 381a992f9e..3212096b02 100644 --- a/file.h +++ b/file.h @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.91 2002/02/24 03:33:04 guy Exp $ + * $Id: file.h,v 1.92 2002/02/24 09:25:34 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -87,10 +87,6 @@ typedef struct _capture_file { frame_data *current_frame; /* Frame data for current frame */ epan_dissect_t *edt; /* Protocol dissection fo rcurrently selected packet */ FILE *print_fh; /* File we're printing to */ -#ifdef HAVE_LIBPCAP - gboolean ringbuffer_on; /* Ringbuffer option */ - guint32 ringbuffer_num_files; /* Number of ringbuffer files */ -#endif } capture_file; /* Return values from "read_cap_file()", "continue_tail_cap_file()", diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index c5aa1eb0b1..b1ea3dbcf3 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -1,7 +1,7 @@ /* capture_dlg.c * Routines for packet capture windows * - * $Id: capture_dlg.c,v 1.61 2002/02/24 06:01:03 guy Exp $ + * $Id: capture_dlg.c,v 1.62 2002/02/24 09:25:36 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -248,13 +248,14 @@ capture_prep_cb(GtkWidget *w, gpointer d) snap_cb = dlg_check_button_new_with_label_with_mnemonic( "_Limit each packet to", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(snap_cb), has_snaplen); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(snap_cb), + capture_opts.has_snaplen); gtk_signal_connect(GTK_OBJECT(snap_cb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_box_pack_start(GTK_BOX(snap_hb), snap_cb, FALSE, FALSE, 0); gtk_widget_show(snap_cb); - snap_adj = (GtkAdjustment *) gtk_adjustment_new((float) snaplen, + snap_adj = (GtkAdjustment *) gtk_adjustment_new((float) capture_opts.snaplen, MIN_PACKET_SIZE, WTAP_MAX_PACKET_SIZE, 1.0, 10.0, 0.0); snap_sb = gtk_spin_button_new (snap_adj, 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE); @@ -270,7 +271,8 @@ capture_prep_cb(GtkWidget *w, gpointer d) /* Promiscuous mode row */ promisc_cb = dlg_check_button_new_with_label_with_mnemonic( "Capture packets in _promiscuous mode", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb), promisc_mode); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(promisc_cb), + capture_opts.promisc_mode); gtk_container_add(GTK_CONTAINER(capture_vb), promisc_cb); gtk_widget_show(promisc_cb); @@ -326,9 +328,10 @@ capture_prep_cb(GtkWidget *w, gpointer d) /* 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 a capture. */ - if (sync_mode) - cfile.ringbuffer_on = FALSE; - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_on_tb),cfile.ringbuffer_on); + if (capture_opts.sync_mode) + capture_opts.ringbuffer_on = FALSE; + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ringbuffer_on_tb), + capture_opts.ringbuffer_on); gtk_signal_connect(GTK_OBJECT(ringbuffer_on_tb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_box_pack_start(GTK_BOX(ringbuffer_hb), ringbuffer_on_tb, FALSE, FALSE, 0); @@ -339,7 +342,7 @@ capture_prep_cb(GtkWidget *w, gpointer d) gtk_box_pack_start(GTK_BOX(ringbuffer_hb), ringbuffer_nbf_lb, FALSE, FALSE, 6); gtk_widget_show(ringbuffer_nbf_lb); - ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((float) cfile.ringbuffer_num_files, + ringbuffer_nbf_adj = (GtkAdjustment *) gtk_adjustment_new((float) capture_opts.ringbuffer_num_files, RINGBUFFER_MIN_NUM_FILES, RINGBUFFER_MAX_NUM_FILES, 1.0, 10.0, 0.0); ringbuffer_nbf_sb = gtk_spin_button_new (ringbuffer_nbf_adj, 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (ringbuffer_nbf_sb), TRUE); @@ -359,7 +362,8 @@ capture_prep_cb(GtkWidget *w, gpointer d) /* "Update display in real time" row */ sync_cb = dlg_check_button_new_with_label_with_mnemonic( "_Update list of packets in real time", accel_group); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb), sync_mode); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sync_cb), + capture_opts.sync_mode); gtk_signal_connect(GTK_OBJECT(sync_cb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_container_add(GTK_CONTAINER(display_vb), sync_cb); @@ -387,13 +391,14 @@ capture_prep_cb(GtkWidget *w, gpointer d) gtk_widget_show(count_hb); count_cb = gtk_check_button_new_with_label("Stop capture after"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(count_cb), has_autostop_count); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(count_cb), + capture_opts.has_autostop_count); gtk_signal_connect(GTK_OBJECT(count_cb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_box_pack_start(GTK_BOX(count_hb), count_cb, FALSE, FALSE, 0); gtk_widget_show(count_cb); - count_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_count, + count_adj = (GtkAdjustment *) gtk_adjustment_new(capture_opts.autostop_count, 1, INT_MAX, 1.0, 10.0, 0.0); count_sb = gtk_spin_button_new (count_adj, 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (count_sb), TRUE); @@ -413,13 +418,13 @@ capture_prep_cb(GtkWidget *w, gpointer d) filesize_cb = gtk_check_button_new_with_label(""); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(filesize_cb), - has_autostop_filesize); + capture_opts.has_autostop_filesize); gtk_signal_connect(GTK_OBJECT(filesize_cb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_box_pack_start(GTK_BOX(filesize_hb), filesize_cb, FALSE, FALSE, 0); gtk_widget_show(filesize_cb); - filesize_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_filesize, + filesize_adj = (GtkAdjustment *) gtk_adjustment_new(capture_opts.autostop_filesize, 1, INT_MAX, 1.0, 10.0, 0.0); filesize_sb = gtk_spin_button_new (filesize_adj, 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (filesize_sb), TRUE); @@ -439,13 +444,13 @@ capture_prep_cb(GtkWidget *w, gpointer d) duration_cb = gtk_check_button_new_with_label("Stop capture after"); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(duration_cb), - has_autostop_duration); + capture_opts.has_autostop_duration); gtk_signal_connect(GTK_OBJECT(duration_cb), "toggled", GTK_SIGNAL_FUNC(capture_prep_adjust_sensitivity), GTK_OBJECT(cap_open_w)); gtk_box_pack_start(GTK_BOX(duration_hb), duration_cb, FALSE, FALSE, 0); gtk_widget_show(duration_cb); - duration_adj = (GtkAdjustment *) gtk_adjustment_new(autostop_duration, + duration_adj = (GtkAdjustment *) gtk_adjustment_new(capture_opts.autostop_duration, 1, INT_MAX, 1.0, 10.0, 0.0); duration_sb = gtk_spin_button_new (duration_adj, 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (duration_sb), TRUE); @@ -703,16 +708,19 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) { cfile.iface = g_strdup(if_name); g_free(if_text); - has_snaplen = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)); - if (has_snaplen) { - snaplen = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb)); - if (snaplen < 1) - snaplen = WTAP_MAX_PACKET_SIZE; - else if (snaplen < MIN_PACKET_SIZE) - snaplen = MIN_PACKET_SIZE; + capture_opts.has_snaplen = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)); + if (capture_opts.has_snaplen) { + capture_opts.snaplen = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb)); + if (capture_opts.snaplen < 1) + capture_opts.snaplen = WTAP_MAX_PACKET_SIZE; + else if (capture_opts.snaplen < MIN_PACKET_SIZE) + capture_opts.snaplen = MIN_PACKET_SIZE; } - promisc_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb)); + capture_opts.promisc_mode = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(promisc_cb)); /* XXX - don't try to get clever and set "cfile.filter" to NULL if the filter string is empty, as an indication that we don't have a filter @@ -737,19 +745,26 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) { save_file = NULL; } - has_autostop_count = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(count_cb)); - if (has_autostop_count) - autostop_count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(count_sb)); + capture_opts.has_autostop_count = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(count_cb)); + if (capture_opts.has_autostop_count) + capture_opts.autostop_count = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(count_sb)); - has_autostop_filesize = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(filesize_cb)); - if (has_autostop_filesize) - autostop_filesize = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(filesize_sb)); + capture_opts.has_autostop_filesize = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(filesize_cb)); + if (capture_opts.has_autostop_filesize) + capture_opts.autostop_filesize = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(filesize_sb)); - has_autostop_duration = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(duration_cb)); - if (has_autostop_duration) - autostop_duration = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(duration_sb)); + capture_opts.has_autostop_duration = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(duration_cb)); + if (capture_opts.has_autostop_duration) + capture_opts.autostop_duration = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(duration_sb)); - sync_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb)); + capture_opts.sync_mode = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sync_cb)); auto_scroll_live = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auto_scroll_cb)); @@ -762,14 +777,15 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb))) g_resolv_flags |= RESOLV_TRANSPORT; - cfile.ringbuffer_on = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_on_tb)) && !(sync_mode); - if (cfile.ringbuffer_on == TRUE) { + capture_opts.ringbuffer_on = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ringbuffer_on_tb)) && + !(capture_opts.sync_mode); + if (capture_opts.ringbuffer_on) { if (save_file == NULL) { simple_dialog(ESD_TYPE_CRIT, NULL, "You must specify a save file if you want to use the ring buffer."); return; - } else if (!has_autostop_filesize || autostop_filesize == 0) { + } else if (!capture_opts.has_autostop_filesize) { simple_dialog(ESD_TYPE_CRIT, NULL, "You must specify a file size at which to rotate the capture files\n" "if you want to use the ring buffer."); @@ -777,11 +793,12 @@ capture_prep_ok_cb(GtkWidget *ok_bt, gpointer parent_w) { } } - cfile.ringbuffer_num_files = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb)); - if (cfile.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; - else if (cfile.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; + capture_opts.ringbuffer_num_files = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ringbuffer_nbf_sb)); + if (capture_opts.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; + else if (capture_opts.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; gtk_widget_destroy(GTK_WIDGET(parent_w)); diff --git a/gtk/main.c b/gtk/main.c index fde8e66c42..7af2696188 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.236 2002/02/24 06:01:03 guy Exp $ + * $Id: main.c,v 1.237 2002/02/24 09:25:36 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -1163,11 +1163,11 @@ set_autostop_criterion(const char *autostoparg) return FALSE; } if (strcmp(autostoparg,"duration") == 0) { - has_autostop_duration = TRUE; - autostop_duration = get_positive_int(p,"autostop duration"); + capture_opts.has_autostop_duration = TRUE; + capture_opts.autostop_duration = get_positive_int(p,"autostop duration"); } else if (strcmp(autostoparg,"filesize") == 0) { - has_autostop_filesize = TRUE; - autostop_filesize = get_positive_int(p,"autostop filesize"); + capture_opts.has_autostop_filesize = TRUE; + capture_opts.autostop_filesize = get_positive_int(p,"autostop filesize"); } else { return FALSE; } @@ -1297,14 +1297,16 @@ main(int argc, char *argv[]) prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path); #ifdef HAVE_LIBPCAP - has_snaplen = FALSE; - snaplen = MIN_PACKET_SIZE; - has_autostop_count = FALSE; - autostop_count = 1; - has_autostop_duration = FALSE; - autostop_duration = 1; - has_autostop_filesize = FALSE; - autostop_filesize = 1; + capture_opts.has_snaplen = FALSE; + capture_opts.snaplen = MIN_PACKET_SIZE; + capture_opts.has_autostop_count = FALSE; + capture_opts.autostop_count = 1; + capture_opts.has_autostop_duration = FALSE; + capture_opts.autostop_duration = 1; + capture_opts.has_autostop_filesize = FALSE; + capture_opts.autostop_filesize = 1; + capture_opts.ringbuffer_on = FALSE; + capture_opts.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; /* If this is a capture child process, it should pay no attention to the "prefs.capture_prom_mode" setting in the preferences file; @@ -1314,13 +1316,13 @@ main(int argc, char *argv[]) Otherwise, set promiscuous mode from the preferences setting. */ if (capture_child) - promisc_mode = TRUE; + capture_opts.promisc_mode = TRUE; else - promisc_mode = prefs->capture_prom_mode; + capture_opts.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; + capture_opts.sync_mode = prefs->capture_real_time; /* And do the same for "Automatic scrolling in live capture" mode. */ auto_scroll_live = prefs->capture_auto_scroll; @@ -1354,10 +1356,6 @@ main(int argc, char *argv[]) cfile.has_snap = FALSE; cfile.snap = WTAP_MAX_PACKET_SIZE; cfile.count = 0; -#ifdef HAVE_LIBPCAP - cfile.ringbuffer_on = FALSE; - cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; -#endif col_init(&cfile.cinfo, prefs->num_cols); /* Assemble the compile-time options */ @@ -1438,8 +1436,9 @@ main(int argc, char *argv[]) break; case 'b': /* Ringbuffer option */ #ifdef HAVE_LIBPCAP - cfile.ringbuffer_on = TRUE; - cfile.ringbuffer_num_files = get_positive_int(optarg, "number of ring buffer files"); + capture_opts.ringbuffer_on = TRUE; + capture_opts.ringbuffer_num_files = + get_positive_int(optarg, "number of ring buffer files"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1450,8 +1449,8 @@ main(int argc, char *argv[]) break; case 'c': /* Capture xxx packets */ #ifdef HAVE_LIBPCAP - has_autostop_count = TRUE; - autostop_count = get_positive_int(optarg, "packet count"); + capture_opts.has_autostop_count = TRUE; + capture_opts.autostop_count = get_positive_int(optarg, "packet count"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1531,7 +1530,7 @@ main(int argc, char *argv[]) break; case 'p': /* Don't capture in promiscuous mode */ #ifdef HAVE_LIBPCAP - promisc_mode = FALSE; + capture_opts.promisc_mode = FALSE; #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1560,8 +1559,8 @@ main(int argc, char *argv[]) break; case 's': /* Set the snapshot (capture) length */ #ifdef HAVE_LIBPCAP - has_snaplen = TRUE; - snaplen = get_positive_int(optarg, "snapshot length"); + capture_opts.has_snaplen = TRUE; + capture_opts.snaplen = get_positive_int(optarg, "snapshot length"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1569,7 +1568,7 @@ main(int argc, char *argv[]) break; case 'S': /* "Sync" mode: used for following file ala tail -f */ #ifdef HAVE_LIBPCAP - sync_mode = TRUE; + capture_opts.sync_mode = TRUE; #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1676,24 +1675,24 @@ main(int argc, char *argv[]) } #ifdef HAVE_LIBPCAP - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* Ring buffer works only under certain conditions: a) ring buffer does not work with temporary files; - b) sync_mode and cfile.ringbuffer_on are mutually exclusive - + b) sync_mode and capture_opts.ringbuffer_on are mutually exclusive - sync_mode takes precedence; c) it makes no sense to enable the ring buffer if the maximum file size is set to "infinite". */ if (cfile.save_file == NULL) { fprintf(stderr, "ethereal: Ring buffer requested, but capture isn't being saved to a permanent file.\n"); - cfile.ringbuffer_on = FALSE; + capture_opts.ringbuffer_on = FALSE; } - if (sync_mode) { + if (capture_opts.sync_mode) { fprintf(stderr, "ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.\n"); - cfile.ringbuffer_on = FALSE; + capture_opts.ringbuffer_on = FALSE; } - if (!has_autostop_filesize || autostop_filesize == 0) { + if (!capture_opts.has_autostop_filesize) { fprintf(stderr, "ethereal: Ring buffer requested, but no maximum capture file size was specified.\n"); - cfile.ringbuffer_on = FALSE; + capture_opts.ringbuffer_on = FALSE; } } #endif @@ -1769,18 +1768,18 @@ main(int argc, char *argv[]) } #ifdef HAVE_LIBPCAP - if (has_snaplen) { - if (snaplen < 1) - snaplen = WTAP_MAX_PACKET_SIZE; - else if (snaplen < MIN_PACKET_SIZE) - snaplen = MIN_PACKET_SIZE; + if (capture_opts.has_snaplen) { + if (capture_opts.snaplen < 1) + capture_opts.snaplen = WTAP_MAX_PACKET_SIZE; + else if (capture_opts.snaplen < MIN_PACKET_SIZE) + capture_opts.snaplen = MIN_PACKET_SIZE; } /* Check the value range of the ringbuffer_num_files parameter */ - if (cfile.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; - else if (cfile.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; + if (capture_opts.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; + else if (capture_opts.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; #endif rc_file = get_persconffile_path(RC_FILE, FALSE); diff --git a/tethereal.c b/tethereal.c index 3c0b187272..7f9d08c5fe 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1,6 +1,6 @@ /* tethereal.c * - * $Id: tethereal.c,v 1.126 2002/02/24 06:45:13 guy Exp $ + * $Id: tethereal.c,v 1.127 2002/02/24 09:25:34 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -153,8 +153,36 @@ capture_file cfile; FILE *data_out_file = NULL; ts_type timestamp_type = RELATIVE; #ifdef HAVE_LIBPCAP -static int snaplen = WTAP_MAX_PACKET_SIZE; -static int promisc_mode = TRUE; +typedef struct { + int snaplen; /* Maximum captured packet length */ + int promisc_mode; /* Capture in promiscuous mode */ + int autostop_count; /* Maximum packet count */ + gboolean has_autostop_duration; /* TRUE if maximum capture duration + is specified */ + gint32 autostop_duration; /* Maximum capture duration */ + gboolean has_autostop_filesize; /* TRUE if maximum capture file size + is specified */ + gint32 autostop_filesize; /* Maximum capture file size */ + gboolean ringbuffer_on; /* TRUE if ring buffer in use */ + guint32 ringbuffer_num_files; /* Number of ring buffer files */ +} capture_options; + +static capture_options capture_opts = { + WTAP_MAX_PACKET_SIZE, /* snapshot length - default is + infinite, in effect */ + TRUE, /* promiscuous mode is the default */ + 0, /* max packet count - default is 0, + meaning infinite */ + FALSE, /* maximum capture duration not + specified by default */ + 0, /* maximum capture duration */ + FALSE, /* maximum capture file size not + specified by default */ + 0, /* maximum capture file size */ + FALSE, /* ring buffer off by default */ + RINGBUFFER_MIN_NUM_FILES /* default number of ring buffer + files */ +}; #endif static void @@ -217,11 +245,6 @@ get_positive_int(const char *string, const char *name) } #ifdef HAVE_LIBPCAP -static gboolean has_autostop_filesize; /* TRUE if maximum capture file size is specified */ -static gint32 autostop_filesize = 0; /* Maximum capture file size */ -static gboolean has_autostop_duration; /* TRUE if maximum capture duration is specified */ -static gint32 autostop_duration = 0; /* Maximum capture duration */ - /* * Given a string of the form ":", as might appear * as an argument to a "-a" option, parse it and set the criterion in @@ -257,11 +280,11 @@ set_autostop_criterion(const char *autostoparg) return FALSE; } if (strcmp(autostoparg,"duration") == 0) { - has_autostop_duration = TRUE; - autostop_duration = get_positive_int(p,"autostop duration"); + capture_opts.has_autostop_duration = TRUE; + capture_opts.autostop_duration = get_positive_int(p,"autostop duration"); } else if (strcmp(autostoparg,"filesize") == 0) { - has_autostop_filesize = TRUE; - autostop_filesize = get_positive_int(p,"autostop filesize"); + capture_opts.has_autostop_filesize = TRUE; + capture_opts.autostop_filesize = get_positive_int(p,"autostop filesize"); } else { return FALSE; } @@ -292,7 +315,6 @@ main(int argc, char *argv[]) int err; #ifdef HAVE_LIBPCAP gboolean capture_filter_specified = FALSE; - guint packet_count = 0; GList *if_list, *if_entry; gchar err_str[PCAP_ERRBUF_SIZE]; #else @@ -364,10 +386,6 @@ main(int argc, char *argv[]) cfile.has_snap = FALSE; cfile.snap = WTAP_MAX_PACKET_SIZE; cfile.count = 0; -#ifdef HAVE_LIBPCAP - cfile.ringbuffer_on = FALSE; - cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; -#endif col_init(&cfile.cinfo, prefs->num_cols); /* Assemble the compile-time options */ @@ -439,8 +457,9 @@ main(int argc, char *argv[]) break; case 'b': /* Ringbuffer option */ #ifdef HAVE_LIBPCAP - cfile.ringbuffer_on = TRUE; - cfile.ringbuffer_num_files = get_positive_int(optarg, "number of ring buffer files"); + capture_opts.ringbuffer_on = TRUE; + capture_opts.ringbuffer_num_files = + get_positive_int(optarg, "number of ring buffer files"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -448,7 +467,8 @@ main(int argc, char *argv[]) break; case 'c': /* Capture xxx packets */ #ifdef HAVE_LIBPCAP - packet_count = get_positive_int(optarg, "packet count"); + capture_opts.autostop_count = + get_positive_int(optarg, "packet count"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -555,7 +575,7 @@ main(int argc, char *argv[]) break; case 'p': /* Don't capture in promiscuous mode */ #ifdef HAVE_LIBPCAP - promisc_mode = 0; + capture_opts.promisc_mode = FALSE; #else capture_option_specified = TRUE; arg_error = TRUE; @@ -569,7 +589,7 @@ main(int argc, char *argv[]) break; case 's': /* Set the snapshot (capture) length */ #ifdef HAVE_LIBPCAP - snaplen = get_positive_int(optarg, "snapshot length"); + capture_opts.snaplen = get_positive_int(optarg, "snapshot length"); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -637,12 +657,12 @@ main(int argc, char *argv[]) #ifdef HAVE_LIBPCAP /* If they didn't specify a "-w" flag, but specified a maximum capture file size, tell them that this doesn't work, and exit. */ - if (has_autostop_filesize && autostop_filesize != 0 && cfile.save_file == NULL) { + if (capture_opts.has_autostop_filesize && cfile.save_file == NULL) { fprintf(stderr, "tethereal: Maximum capture file size specified, but capture isn't being saved to a file.\n"); exit(2); } - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* Ring buffer works only under certain conditions: a) ring buffer does not work if you're not saving the capture to a file; @@ -657,7 +677,7 @@ main(int argc, char *argv[]) fprintf(stderr, "tethereal: Ring buffer requested, but capture isn't being saved in libpcap format.\n"); exit(2); } - if (!has_autostop_filesize || autostop_filesize == 0) { + if (!capture_opts.has_autostop_filesize) { fprintf(stderr, "tethereal: Ring buffer requested, but no maximum capture file size was specified.\n"); exit(2); } @@ -699,16 +719,16 @@ main(int argc, char *argv[]) } #ifdef HAVE_LIBPCAP - if (snaplen < 1) - snaplen = WTAP_MAX_PACKET_SIZE; - else if (snaplen < MIN_PACKET_SIZE) - snaplen = MIN_PACKET_SIZE; + if (capture_opts.snaplen < 1) + capture_opts.snaplen = WTAP_MAX_PACKET_SIZE; + else if (capture_opts.snaplen < MIN_PACKET_SIZE) + capture_opts.snaplen = MIN_PACKET_SIZE; /* Check the value range of the ringbuffer_num_files parameter */ - if (cfile.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; - else if (cfile.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) - cfile.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; + if (capture_opts.ringbuffer_num_files < RINGBUFFER_MIN_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MIN_NUM_FILES; + else if (capture_opts.ringbuffer_num_files > RINGBUFFER_MAX_NUM_FILES) + capture_opts.ringbuffer_num_files = RINGBUFFER_MAX_NUM_FILES; #endif if (rfilter != NULL) { @@ -770,9 +790,9 @@ main(int argc, char *argv[]) free_interface_list(if_list); } } - capture(packet_count, out_file_type); + capture(capture_opts.autostop_count, out_file_type); - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ringbuf_free(); } #else @@ -821,8 +841,8 @@ capture(volatile int packet_count, int out_file_type) 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. */ open_err_str[0] = '\0'; - ld.pch = pcap_open_live(cfile.iface, snaplen, promisc_mode, 1000, - open_err_str); + ld.pch = pcap_open_live(cfile.iface, capture_opts.snaplen, + capture_opts.promisc_mode, 1000, open_err_str); if (ld.pch == NULL) { /* Well, we couldn't start the capture. */ @@ -900,9 +920,9 @@ capture(volatile int packet_count, int out_file_type) " that Tethereal doesn't support."); goto error; } - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { cfile.save_file_fd = ringbuf_init(cfile.save_file, - cfile.ringbuffer_num_files); + capture_opts.ringbuffer_num_files); if (cfile.save_file_fd != -1) { ld.pdh = ringbuf_init_wtap_dump_fdopen(out_file_type, ld.linktype, pcap_snapshot(ld.pch), &err); @@ -944,12 +964,12 @@ capture(volatile int packet_count, int out_file_type) /* initialize capture stop conditions */ init_capture_stop_conditions(); /* create stop conditions */ - if (has_autostop_filesize) + if (capture_opts.has_autostop_filesize) cnd_stop_capturesize = cnd_new((char*)CND_CLASS_CAPTURESIZE, - (long)autostop_filesize * 1000); - if (has_autostop_duration) + (long)capture_opts.autostop_filesize * 1000); + if (capture_opts.has_autostop_duration) cnd_stop_timeout = cnd_new((char*)CND_CLASS_TIMEOUT, - (gint32)autostop_duration); + (gint32)capture_opts.autostop_duration); if (packet_count == 0) packet_count = -1; /* infinite capturng */ @@ -971,7 +991,7 @@ capture(volatile int packet_count, int out_file_type) (guint32)wtap_get_bytes_dumped(ld.pdh))) { /* We're saving the capture to a file, and the capture file reached its maximum size. */ - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { /* Switch to the next ringbuffer file */ if (ringbuf_switch_file(&cfile, &ld.pdh, &err) == TRUE) { /* File switch failed: reset the condition */ @@ -1022,7 +1042,7 @@ capture(volatile int packet_count, int out_file_type) if (cfile.save_file != NULL) { /* We're saving to a file or files; close all files. */ - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { dump_ok = ringbuf_wtap_dump_close(&cfile, &err); } else { dump_ok = wtap_dump_close(ld.pdh, &err); @@ -1034,7 +1054,7 @@ capture(volatile int packet_count, int out_file_type) return TRUE; error: - if (cfile.ringbuffer_on) { + if (capture_opts.ringbuffer_on) { ringbuf_error_cleanup(); } g_free(cfile.save_file); -- cgit v1.2.3