aboutsummaryrefslogtreecommitdiffstats
path: root/capture.c
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 /capture.c
parent062cb007f187984acdf6e9ba3f9ee4b647deadc2 (diff)
downloadwireshark-bab015f5e50f6966a6f944b08d669e11736d5d2c.tar.gz
wireshark-bab015f5e50f6966a6f944b08d669e11736d5d2c.tar.bz2
wireshark-bab015f5e50f6966a6f944b08d669e11736d5d2c.zip
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 'capture.c')
-rw-r--r--capture.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/capture.c b/capture.c
index 2d22b54474..93c6785588 100644
--- a/capture.c
+++ b/capture.c
@@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
- * $Id: capture.c,v 1.73 1999/09/30 06:11:43 guy Exp $
+ * $Id: capture.c,v 1.74 1999/09/30 06:49:53 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -97,14 +97,11 @@ typedef struct _loop_data {
wtap_dumper *pdh;
} loop_data;
+/* Create a temporary file and start a capture to it. */
void
do_capture(void)
{
char tmpname[128+1];
- u_char c;
- int i;
- guint byte_count;
- char *msg;
/* Choose a random name for the capture buffer */
cf.save_file_fd = create_tempfile(tmpname, sizeof tmpname, "ether");
@@ -123,7 +120,21 @@ do_capture(void)
}
cf.save_file = g_strdup(tmpname);
cf.user_saved = 0;
-
+
+ run_capture();
+}
+
+/* Start a capture to a file we've opened; "cf.save_file" is the
+ pathname of the file, and "cf.save_file_fd" is the file descriptor
+ we got when we opened it. */
+void
+run_capture(void)
+{
+ u_char c;
+ int i;
+ guint byte_count;
+ char *msg;
+
if (sync_mode || fork_mode) { /* use fork() for capture */
int fork_child;
char ssnap[24];
@@ -234,6 +245,7 @@ do_capture(void)
capture();
}
+/* Do the low-level work of a capture. */
void
capture(void)
{
@@ -265,11 +277,12 @@ capture(void)
pch = pcap_open_live(cf.iface, cf.snap, 1, 250, err_str);
if (pch == NULL) {
- /* Well, we couldn't start the capture. */
- if (!sync_mode && !fork_mode) {
- /* In fork mode, we shouldn't do any UI stuff until we pop up the
- capture-progress window, and, since we couldn't start the
- capture, we haven't popped it up. */
+ /* Well, we couldn't start the capture.
+ If this is a child process that does the capturing in sync
+ mode or fork mode, it shouldn't do any UI stuff until we pop up the
+ capture-progress window, and, since we couldn't start the
+ capture, we haven't popped it up. */
+ if (!capture_child) {
while (gtk_events_pending()) gtk_main_iteration();
}
snprintf(errmsg, sizeof errmsg,
@@ -337,14 +350,15 @@ capture(void)
goto error;
}
- if (sync_mode) {
+ if (capture_child && sync_mode) {
/* Well, we should be able to start capturing.
- Sync out the capture file, so the header makes it to the file
- system, and send a "capture started successfully and capture
- file created" message to our parent so that they'll open the
- capture file and update its windows to indicate that we have
- a live capture in progress. */
+ This is the child process for a sync mode capture, so sync out
+ the capture file, so the header makes it to the file system,
+ and send a "capture started successfully and capture file created"
+ message to our parent so that they'll open the capture file and
+ update its windows to indicate that we have a live capture in
+ progress. */
fflush(wtap_dump_file(ld.pdh));
write(1, "0;", 2);
}
@@ -447,7 +461,10 @@ capture(void)
/* do sync here, too */
fflush(wtap_dump_file(ld.pdh));
- if (sync_mode && ld.sync_packets) {
+ if (capture_child && sync_mode && ld.sync_packets) {
+ /* This is the child process for a sync mode capture, so send
+ our parent a message saying we've written out "ld.sync_packets"
+ packets to the capture file. */
char tmp[20];
sprintf(tmp, "%d*", ld.sync_packets);
write(1, tmp, strlen(tmp));
@@ -515,8 +532,9 @@ error:
/* We couldn't even start the capture, so get rid of the capture
file. */
unlink(cf.save_file); /* silently ignore error */
- if (sync_mode) {
- /* Send the error message to our parent, so they can display a
+ if (capture_child && sync_mode) {
+ /* This is the child process for a sync mode capture.
+ Send the error message to our parent, so they can display a
dialog box containing it. */
int msglen = strlen(errmsg);
char lenbuf[10+1+1];