If we're given the "-k" flag, don't start the capture until after we've:

popped up the top-level window (so that it looks like a capture
	started from "Capture/Start");

	initialized the colors (so that we don't dump core when reading
	in the capture file);

	popped up any message box for failure to read the preferences
	file.

This means we start the capture in "main()", rather than in the realize
callback for the main window, so get rid of that callback.

If we're a child process that's just capturing to a file for our parent
to read, however, we shouldn't pop up the top-level window, because
that's our parent's job; when running that child, set its "argv[0]" to a
special name, so that

	1) it shows up in a "ps" with a special name;

	2) we don't have to invent Yet Another Flag to say "you're the
	   child".

(We may want to use the name to turn on *all* behaviors that the capture
child, and only the capture child, should exhibit.)

If "-w" and "-k" were both specified, attempt to open the file specified
by "-w" and, if that succeeds, set "cf.save_file_fd" to refer to it, so
that "-w" plus "-k" works again, rather than popping up a "The file to
which the capture would be saved ... could not be opened: Bad file
descriptor." message box.

svn path=/trunk/; revision=739
This commit is contained in:
Guy Harris 1999-09-30 06:11:51 +00:00
parent 7caca1db1d
commit 062cb007f1
4 changed files with 69 additions and 50 deletions

View File

@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
* $Id: capture.c,v 1.72 1999/09/25 02:02:11 guy Exp $
* $Id: capture.c,v 1.73 1999/09/30 06:11:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -153,7 +153,7 @@ do_capture(void)
close(1);
dup(sync_pipe[1]);
close(sync_pipe[0]);
execlp(ethereal_path, "ethereal", "-k", "-Q", "-i", cf.iface,
execlp(ethereal_path, CHILD_NAME, "-k", "-Q", "-i", cf.iface,
"-w", cf.save_file, "-W", save_file_fd,
"-c", scount, "-s", ssnap, "-S",
"-m", medium_font, "-b", bold_font,
@ -162,7 +162,7 @@ do_capture(void)
(const char *)NULL);
}
else {
execlp(ethereal_path, "ethereal", "-k", "-Q", "-i", cf.iface,
execlp(ethereal_path, CHILD_NAME, "-k", "-Q", "-i", cf.iface,
"-w", cf.save_file, "-W", save_file_fd,
"-c", scount, "-s", ssnap,
"-m", medium_font, "-b", bold_font,

View File

@ -1,7 +1,7 @@
/* capture.h
* Definitions for packet capture windows
*
* $Id: capture.h,v 1.15 1999/09/23 06:27:19 guy Exp $
* $Id: capture.h,v 1.16 1999/09/30 06:11:44 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -48,6 +48,9 @@
#define DLT_PPP_BSDOS 14
#endif
/* Name we give to the child process when doing a "-S" or "-F" capture. */
#define CHILD_NAME "ethereal-capture"
void do_capture(void);
void capture(void);

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.9 1999/09/23 07:57:23 guy Exp $
* $Id: main.c,v 1.10 1999/09/30 06:11:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -432,21 +432,6 @@ void blank_packetinfo() {
pi.destport = 0;
}
/* Things to do when the main window is realized */
void
main_realize_cb(GtkWidget *w, gpointer data) {
#ifdef HAVE_LIBPCAP
if (start_capture) {
/* 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? */
close_cap_file(&cf, info_bar, file_ctx);
capture();
start_capture = 0;
}
#endif
}
/* call initialization routines at program startup time */
static void
ethereal_proto_init(void) {
@ -720,8 +705,6 @@ main(int argc, char *argv[])
GTK_SIGNAL_FUNC(file_quit_cmd_cb), "WM destroy");
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(file_quit_cmd_cb), "WM destroy");
gtk_signal_connect(GTK_OBJECT (window), "realize",
GTK_SIGNAL_FUNC(main_realize_cb), NULL);
gtk_window_set_title(GTK_WINDOW(window), "The Ethereal Network Analyzer");
gtk_widget_set_usize(GTK_WIDGET(window), DEF_WIDTH, -1);
gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
@ -873,35 +856,43 @@ main(int argc, char *argv[])
ethereal_proto_init(); /* Init anything that needs initializing */
gtk_widget_show(window);
/* 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) {
/* No. Pop up the main window, and read in a capture file if
we were told to. */
colors_init(&cf);
gtk_widget_show(window);
/* If we were given the name of a capture file, read it in now;
we defer it until now, so that, if we can't open it, and pop
up an alert box, the alert box is more likely to come up on
top of the main window - but before the preference-file-error
alert box, so, if we get one of those, it's more likely to come
up on top of us. */
if (cf_name) {
if (rfilter != NULL) {
rfcode = dfilter_new();
if (dfilter_compile(rfcode, rfilter) != 0) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
dfilter_destroy(rfcode);
rfilter_parse_failed = TRUE;
}
}
if (!rfilter_parse_failed) {
if ((err = open_cap_file(cf_name, &cf)) == 0) {
cf.rfcode = rfcode;
err = read_cap_file(&cf);
s = strrchr(cf_name, '/');
if (s) {
last_open_dir = cf_name;
*s = '\0';
colors_init(&cf);
/* If we were given the name of a capture file, read it in now;
we defer it until now, so that, if we can't open it, and pop
up an alert box, the alert box is more likely to come up on
top of the main window - but before the preference-file-error
alert box, so, if we get one of those, it's more likely to come
up on top of us. */
if (cf_name) {
if (rfilter != NULL) {
rfcode = dfilter_new();
if (dfilter_compile(rfcode, rfilter) != 0) {
simple_dialog(ESD_TYPE_WARN, NULL, dfilter_error_msg);
dfilter_destroy(rfcode);
rfilter_parse_failed = TRUE;
}
}
if (!rfilter_parse_failed) {
if ((err = open_cap_file(cf_name, &cf)) == 0) {
cf.rfcode = rfcode;
err = read_cap_file(&cf);
s = strrchr(cf_name, '/');
if (s) {
last_open_dir = cf_name;
*s = '\0';
}
set_menu_sensitivity("/File/Save As...", TRUE);
}
set_menu_sensitivity("/File/Save As...", TRUE);
}
}
}
@ -915,6 +906,32 @@ main(int argc, char *argv[])
strerror(pf_open_errno));
}
#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();
}
start_capture = 0;
}
#endif
gtk_main();
ethereal_proto_cleanup();

View File

@ -1,7 +1,7 @@
/* ethereal.h
* Global defines, etc.
*
* $Id: main.h,v 1.4 1999/09/11 12:36:14 deniel Exp $
* $Id: main.h,v 1.5 1999/09/30 06:11:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -64,7 +64,6 @@ void file_quit_cmd_cb(GtkWidget *, gpointer);
void file_reload_cmd_cb(GtkWidget *, gpointer);
void file_print_cmd_cb(GtkWidget *, gpointer);
void file_print_packet_cmd_cb(GtkWidget *, gpointer);
void main_realize_cb(GtkWidget *, gpointer);
void expand_all_cb(GtkWidget *, gpointer);
void collapse_all_cb(GtkWidget *, gpointer);