diff options
-rw-r--r-- | capture.c | 22 | ||||
-rw-r--r-- | capture.h | 10 | ||||
-rw-r--r-- | gtk/main.c | 30 |
3 files changed, 38 insertions, 24 deletions
@@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.209 2003/09/15 22:48:41 guy Exp $ + * $Id: capture.c,v 1.210 2003/09/15 23:15:31 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -287,8 +287,9 @@ quote_encapsulate(const char *string) #endif /* Open a specified file, or create a temporary file, and start a capture - to the file in question. */ -void + to the file in question. Returns TRUE if the capture starts + successfully, FALSE otherwise. */ +gboolean do_capture(const char *save_file) { char tmpname[128+1]; @@ -338,7 +339,7 @@ do_capture(const char *save_file) file_open_error_message(errno, TRUE, WTAP_FILE_PCAP), capfile_name); } g_free(capfile_name); - return; + return FALSE; } cf_close(&cfile); g_assert(cfile.save_file == NULL); @@ -419,7 +420,7 @@ do_capture(const char *save_file) cfile.save_file = NULL; simple_dialog(ESD_TYPE_CRIT, NULL, "Couldn't create sync pipe: %s", strerror(error)); - return; + return FALSE; } /* Convert font name to a quote-encapsulated string and pass to child */ @@ -457,7 +458,7 @@ do_capture(const char *save_file) cfile.save_file = NULL; simple_dialog(ESD_TYPE_CRIT, NULL, "Couldn't create sync pipe: %s", strerror(error)); - return; + return FALSE; } argv = add_arg(argv, &argc, "-m"); @@ -521,7 +522,7 @@ do_capture(const char *save_file) cfile.save_file = NULL; simple_dialog(ESD_TYPE_CRIT, NULL, "Couldn't create child process: %s", strerror(error)); - return; + return FALSE; } /* Read a byte count from "sync_pipe[READ]", terminated with a @@ -541,7 +542,7 @@ do_capture(const char *save_file) g_free(cfile.save_file); cfile.save_file = NULL; wait_for_child(TRUE); - return; + return FALSE; } if (c == SP_CAPSTART || c == SP_ERROR_MSG) break; @@ -555,7 +556,7 @@ do_capture(const char *save_file) cfile.save_file = NULL; simple_dialog(ESD_TYPE_WARN, NULL, "Capture child process sent us a bad message"); - return; + return FALSE; } byte_count = byte_count*10 + c - '0'; } @@ -688,7 +689,7 @@ do_capture(const char *save_file) we registered get called. */ if (gtk_main_level() > 0) gtk_main_quit(); - return; + return FALSE; } } } @@ -701,6 +702,7 @@ do_capture(const char *save_file) } cfile.save_file = NULL; } + return TRUE; } #ifdef _WIN32 @@ -1,13 +1,12 @@ /* capture.h * Definitions for packet capture windows * - * $Id: capture.h,v 1.35 2003/05/15 13:33:53 deniel Exp $ + * $Id: capture.h,v 1.36 2003/09/15 23:15:31 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs * - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -59,8 +58,9 @@ extern int quit_after_cap; /* Makes a "capture only mode". Implies -k */ extern gboolean capture_child; /* if this is the child for "-S" */ /* Open a specified file, or create a temporary file, and start a capture - to the file in question. */ -void do_capture(const char *save_file); + to the file in question. Returns TRUE if the capture starts + successfully, FALSE otherwise. */ +gboolean do_capture(const char *save_file); /* Do the low-level work of a capture. */ int capture(gboolean *stats_known, struct pcap_stat *stats); diff --git a/gtk/main.c b/gtk/main.c index f50b0912c4..f6159859ac 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.313 2003/09/15 22:48:42 guy Exp $ + * $Id: main.c,v 1.314 2003/09/15 23:15:32 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -2078,7 +2078,7 @@ main(int argc, char *argv[]) a capture file to read? */ if (cf_name) { /* Yes - that's bogus. */ - fprintf(stderr, "ethereal: both live capture (-k) and capture file specified\n"); + fprintf(stderr, "ethereal: You cannot specify both a live capture and a capture file to read.\n"); exit(2); } @@ -2253,12 +2253,6 @@ main(int argc, char *argv[]) register_all_tap_menus(); set_menus_for_capture_file(FALSE); - /* open tap windows after creating the main window to avoid GTK warnings */ - if (tap_opt && tli) { - (*tli->func)(tap_opt); - g_free(tap_opt); - } - colors_init(); colfilter_init(); @@ -2281,6 +2275,16 @@ main(int argc, char *argv[]) capture file, and thus destroyed any previous read filter attached to "cf". */ cfile.rfcode = rfcode; + + /* Open tap windows; we do so after creating the main window, + to avoid GTK warnings, and after successfully opening the + capture file, so we know we have something to tap. */ + if (tap_opt && tli) { + (*tli->func)(tap_opt); + g_free(tap_opt); + } + + /* Read the capture file. */ switch (cf_read(&cfile, &err)) { case READ_SUCCESS: @@ -2403,7 +2407,15 @@ main(int argc, char *argv[]) } else { if (start_capture) { /* "-k" was specified; start a capture. */ - do_capture(save_file); + if (do_capture(save_file)) { + /* The capture started. Open tap windows; we do so after creating + the main window, to avoid GTK warnings, and after starting the + capture, so we know we have something to tap. */ + if (tap_opt && tli) { + (*tli->func)(tap_opt); + g_free(tap_opt); + } + } if (save_file != NULL) { /* Save the directory name for future file dialogs. */ s = get_dirname(save_file); /* Overwrites save_file */ |