aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-09-30 06:50:01 +0000
committerGuy Harris <guy@alum.mit.edu>1999-09-30 06:50:01 +0000
commitbab015f5e50f6966a6f944b08d669e11736d5d2c (patch)
tree598656f67b782d216a43b74971951a4bf69012f0 /gtk
parent062cb007f187984acdf6e9ba3f9ee4b647deadc2 (diff)
Add a new global flag "capture_child", which is TRUE if we're a child
process for a sync mode or fork mode capture. Have that flag control whether we do things that *only* the parent or *only* the child should do, rather than basing it solely on the setting of "sync_mode" or "fork_mode" (or, in the case of stuff done in the child process either in sync mode or fork mode, rather than basing it on the setting of those flags at all). Split "do_capture()" into a "run_capture()" routine that starts a capture (possibly by forking off and execing a child process, if we're supposed to do sync mode or fork mode captures), and that assumes the file to which the capture is to write has already been opened and that "cf.save_file_fd" is the file descriptor for that file, and a "do_capture()" routine that creates a temporary file, getting an FD for it, and calls "run_capture()". Use "run_capture()", rather than "capture()", for "-k" captures, so that it'll do the capture in a child process if "-S" or "-F" was specified ("do_capture()" won't do because "-k" captures should write to the file specified by the "-w" flag, not some random temporary file). For child process captures, however, just use "capture()" - the child process shouldn't itself fork off a child if we're in sync or fork mode, and should just write to the file whose file descriptor was specified by the "-W" flag on the command line. All this allows you to do "ethereal -S -w <file> -i <interface> -k" to start a sync mode capture from the command line. svn path=/trunk/; revision=740
Diffstat (limited to 'gtk')
-rw-r--r--gtk/main.c73
1 files changed, 44 insertions, 29 deletions
diff --git a/gtk/main.c b/gtk/main.c
index 70fc7e5d1f..15c86ebff4 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.10 1999/09/30 06:11:50 guy Exp $
+ * $Id: main.c,v 1.11 1999/09/30 06:50:01 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -103,7 +103,6 @@ GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar,
*info_bar;
GdkFont *m_r_font, *m_b_font;
guint main_ctx, file_ctx;
-gint start_capture = 0;
gchar comp_info_str[256];
gchar *ethereal_path = NULL;
gchar *medium_font = MONO_MEDIUM_FONT;
@@ -119,6 +118,7 @@ int sync_mode; /* fork a child to do the capture, and sync between them */
int sync_pipe[2]; /* used to sync father */
int fork_mode; /* fork a child to do the capture */
int quit_after_cap; /* Makes a "capture only mode". Implies -k */
+gboolean capture_child; /* if this is the child for "-F"/"-S" */
#endif
/* Specifies byte offsets for object selected in tree */
@@ -462,7 +462,7 @@ print_usage(void) {
int
main(int argc, char *argv[])
{
- char *command_name, *s;
+ char *command_name, *s;
int i;
#ifndef WIN32
int opt;
@@ -471,6 +471,9 @@ main(int argc, char *argv[])
char *pf_path;
int pf_open_errno = 0;
int err;
+#ifdef HAVE_LIBPCAP
+ gboolean start_capture = FALSE;
+#endif
GtkWidget *window, *main_vbox, *menubar, *u_pane, *l_pane,
*bv_table, *bv_hscroll, *bv_vscroll, *stat_hbox,
*tv_scrollw, *filter_bt, *filter_te;
@@ -501,7 +504,11 @@ main(int argc, char *argv[])
proto_registrar_dump();
exit(0);
}
-
+
+ /* Set "capture_child" to indicate whether this is going to be a child
+ process for a "-S" or "-F" capture? */
+ capture_child = (strcmp(command_name, CHILD_NAME) == 0);
+
/* Let GTK get its args */
gtk_init (&argc, &argv);
@@ -589,7 +596,7 @@ main(int argc, char *argv[])
break;
#ifdef HAVE_LIBPCAP
case 'k': /* Start capture immediately */
- start_capture = 1;
+ start_capture = TRUE;
break;
#endif
case 'P': /* Packet list pane height */
@@ -598,7 +605,7 @@ main(int argc, char *argv[])
#ifdef HAVE_LIBPCAP
case 'Q': /* Quit after capture (just capture to file) */
quit_after_cap = 1;
- start_capture = 1; /*** -Q implies -k !! ***/
+ start_capture = TRUE; /*** -Q implies -k !! ***/
break;
#endif
case 'r': /* Read capture file xxx */
@@ -659,7 +666,7 @@ main(int argc, char *argv[])
exit(1);
}
#ifdef HAVE_LIBPCAP
- if (sync_mode || fork_mode) {
+ if (capture_child && (sync_mode || fork_mode)) {
if (cf.save_file_fd == -1) {
fprintf(stderr, "ethereal: \"-k\" flag was specified with \"-%c\" flag but without \"-W\" flag\n",
(sync_mode ? 'S' : 'F'));
@@ -859,7 +866,7 @@ main(int argc, char *argv[])
/* Is this a "child" ethereal, which is only supposed to pop up a
capture box to let us stop the capture, and run a capture
to a file that our parent will read? */
- if (strcmp(command_name, CHILD_NAME) != 0) {
+ if (!capture_child) {
/* No. Pop up the main window, and read in a capture file if
we were told to. */
@@ -907,28 +914,36 @@ main(int argc, char *argv[])
}
#ifdef HAVE_LIBPCAP
- if (start_capture) {
- /* "-k" was specified; start a capture. */
-
- /* Try to open/create the file specified on the command line with
- the "-w" flag. (We already checked in "main()" that "-w" was
- specified. */
- cf.save_file_fd = open(cf.save_file, O_RDWR|O_TRUNC|O_CREAT, 0600);
- if (cf.save_file_fd == -1) {
- /* XXX - display the error in a message box, or on the command line? */
- simple_dialog(ESD_TYPE_WARN, NULL,
- "The file to which the capture would be saved (\"%s\")"
- "could not be opened: %s.", cf.save_file, strerror(errno));
- } else {
- /* XXX - "capture()" used to do this, but we now do it in
- "do_capture()", before calling "capture()"; will we ever
- have a capture file open here?
- Yes, if "-r" was specified - but that's arguably silly, so
- perhaps we should treate that as an error. */
- close_cap_file(&cf, info_bar, file_ctx);
- capture();
+ if (capture_child) {
+ /* This is the child process for a sync mode or fork mode capture,
+ so just do the low-level work of a capture - don't create
+ a temporary file (so don't call "do_capture()"), and don't
+ fork off *another* child process (so don't call "run_capture()"). */
+
+ capture();
+ } else {
+ if (start_capture) {
+ /* "-k" was specified; start a capture. */
+
+ /* Try to open/create the file specified on the command line with
+ the "-w" flag. (We already checked in "main()" that "-w" was
+ specified. */
+ cf.save_file_fd = open(cf.save_file, O_RDWR|O_TRUNC|O_CREAT, 0600);
+ if (cf.save_file_fd == -1) {
+ /* XXX - display the error in a message box, or on the command line? */
+ simple_dialog(ESD_TYPE_WARN, NULL,
+ "The file to which the capture would be saved (\"%s\")"
+ "could not be opened: %s.", cf.save_file, strerror(errno));
+ } else {
+ /* XXX - "capture()" used to do this, but we now do it in
+ "do_capture()", before calling "capture()"; will we ever
+ have a capture file open here?
+ Yes, if "-r" was specified - but that's arguably silly, so
+ perhaps we should treate that as an error. */
+ close_cap_file(&cf, info_bar, file_ctx);
+ run_capture();
+ }
}
- start_capture = 0;
}
#endif