From 9ff19a4c94351adfedb53dab9b6445786827345f Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Thu, 3 Feb 2005 22:48:20 +0000 Subject: move capture_file_fd field from capture_file to capture_opts type, as this is the place where it should be svn path=/trunk/; revision=13268 --- capture.c | 8 ++++---- capture.h | 1 + capture_loop.c | 8 ++++---- capture_sync.c | 4 ++-- cfile.c | 1 - cfile.h | 1 - gtk/main.c | 5 +++-- tethereal.c | 10 ++++++---- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/capture.c b/capture.c index 109f902dd7..066a4a6055 100644 --- a/capture.c +++ b/capture.c @@ -96,23 +96,23 @@ capture_open_output(capture_options *capture_opts, const char *save_file, gboole capfile_name = g_strdup(save_file); if (capture_opts->multi_files_on) { /* ringbuffer is enabled */ - cfile.save_file_fd = ringbuf_init(capfile_name, + capture_opts->save_file_fd = ringbuf_init(capfile_name, (capture_opts->has_ring_num_files) ? capture_opts->ring_num_files : 0); } 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, + capture_opts->save_file_fd = open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 0600); } *is_tempfile = FALSE; } else { /* Choose a random name for the temporary capture buffer */ - cfile.save_file_fd = create_tempfile(tmpname, sizeof tmpname, "ether"); + capture_opts->save_file_fd = create_tempfile(tmpname, sizeof tmpname, "ether"); capfile_name = g_strdup(tmpname); *is_tempfile = TRUE; } /* did we fail to open the output file? */ - if (cfile.save_file_fd == -1) { + if (capture_opts->save_file_fd == -1) { if (is_tempfile) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The temporary file to which the capture would be saved (\"%s\")" diff --git a/capture.h b/capture.h index 0b2bec89ed..0d1c9d8339 100644 --- a/capture.h +++ b/capture.h @@ -47,6 +47,7 @@ typedef struct capture_options_tag { int linktype; /**< Data link type to use, or -1 for "use default" */ gboolean capture_child; /**< True if this is the child for "-S" */ + int save_file_fd; /**< File descriptor for saved file */ /* GUI related */ gboolean sync_mode; /**< Fork a child to do the capture, diff --git a/capture_loop.c b/capture_loop.c index 76a9685266..912152bbe7 100644 --- a/capture_loop.c +++ b/capture_loop.c @@ -799,7 +799,7 @@ static int capture_loop_open_wiretap_output(capture_options *capture_opts, loop_ ld->wtap_pdh = ringbuf_init_wtap_dump_fdopen(WTAP_FILE_PCAP, ld->wtap_linktype, file_snaplen, &err); } else { - ld->wtap_pdh = wtap_dump_fdopen(cfile.save_file_fd, WTAP_FILE_PCAP, + ld->wtap_pdh = wtap_dump_fdopen(capture_opts->save_file_fd, WTAP_FILE_PCAP, ld->wtap_linktype, file_snaplen, &err); } @@ -1106,7 +1106,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct } /* Switch to the next ringbuffer file */ - if (ringbuf_switch_file(&ld.wtap_pdh, &cfile.save_file, &cfile.save_file_fd, &ld.err)) { + if (ringbuf_switch_file(&ld.wtap_pdh, &cfile.save_file, &capture_opts->save_file_fd, &ld.err)) { /* File switch succeeded: reset the conditions */ cnd_reset(cnd_autostop_size); if (cnd_file_duration) { @@ -1175,7 +1175,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct } /* Switch to the next ringbuffer file */ - if (ringbuf_switch_file(&ld.wtap_pdh, &cfile.save_file, &cfile.save_file_fd, &ld.err)) { + if (ringbuf_switch_file(&ld.wtap_pdh, &cfile.save_file, &capture_opts->save_file_fd, &ld.err)) { /* file switch succeeded: reset the conditions */ cnd_reset(cnd_file_duration); if(cnd_autostop_size) @@ -1283,7 +1283,7 @@ error: } else { /* We can't use the save file, and we have no wtap_dump stream to close in order to close it, so close the FD directly. */ - close(cfile.save_file_fd); + close(capture_opts->save_file_fd); /* We couldn't even start the capture, so get rid of the capture file. */ diff --git a/capture_sync.c b/capture_sync.c index c07555df3c..6a88e9fcf9 100644 --- a/capture_sync.c +++ b/capture_sync.c @@ -251,7 +251,7 @@ sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile) { argv = sync_pipe_add_arg(argv, &argc, cfile.save_file); argv = sync_pipe_add_arg(argv, &argc, "-W"); - sprintf(save_file_fd,"%d",cfile.save_file_fd); /* in lieu of itoa */ + sprintf(save_file_fd,"%d",capture_opts->save_file_fd); /* in lieu of itoa */ argv = sync_pipe_add_arg(argv, &argc, save_file_fd); if (capture_opts->has_autostop_packets) { @@ -396,7 +396,7 @@ sync_pipe_do_capture(capture_options *capture_opts, gboolean is_tempfile) { /* Close the save file FD, as we won't be using it - we'll be opening it and reading the save file through Wiretap. */ - close(cfile.save_file_fd); + close(capture_opts->save_file_fd); if (fork_child == -1) { /* We couldn't even create the child process. */ diff --git a/cfile.c b/cfile.c index 475906408d..5b958f3252 100644 --- a/cfile.c +++ b/cfile.c @@ -57,7 +57,6 @@ init_cap_file(capture_file *cf) #endif cf->iface = NULL; cf->save_file = NULL; - cf->save_file_fd = -1; cf->has_snap = FALSE; cf->snap = WTAP_MAX_PACKET_SIZE; cf->count = 0; diff --git a/cfile.h b/cfile.h index bcb5938e96..13c8548940 100644 --- a/cfile.h +++ b/cfile.h @@ -62,7 +62,6 @@ typedef struct _capture_file { int snap; /* Maximum captured packet length */ gchar *iface; /* Interface */ gchar *save_file; /* File that user saved capture to */ - int save_file_fd; /* File descriptor for saved file */ wtap *wth; /* Wiretap session */ dfilter_t *rfcode; /* Compiled read filter program */ gchar *dfilter; /* Display filter string */ diff --git a/gtk/main.c b/gtk/main.c index db2f75bbdb..3084766b0a 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1854,6 +1854,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 capture_opts->buffer_size = 1; #endif + capture_opts->save_file_fd = -1; capture_opts->quit_after_cap = FALSE; capture_opts->has_autostop_packets = FALSE; @@ -2204,7 +2205,7 @@ main(int argc, char *argv[]) * the error flags for the user in the non-libpcap case. */ case 'W': /* Write to capture file FD xxx */ - cfile.save_file_fd = atoi(optarg); + capture_opts->save_file_fd = atoi(optarg); break; #endif case 'z': @@ -2373,7 +2374,7 @@ main(int argc, char *argv[]) } if (capture_opts->capture_child) { - if (cfile.save_file_fd == -1) { + if (capture_opts->save_file_fd == -1) { /* XXX - send this to the standard output as something our parent should put in an error message box? */ fprintf(stderr, "%s: \"-W\" flag not specified\n", CHILD_NAME); diff --git a/tethereal.c b/tethereal.c index 367ec2c73c..d83ecee390 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1716,6 +1716,7 @@ capture(int out_file_type) gboolean write_err; gboolean dump_ok; dfilter_t *rfcode = NULL; + int save_file_fd; /* Initialize all data structures used for dissection. */ init_dissection(); @@ -1876,9 +1877,9 @@ capture(int out_file_type) goto error; } if (capture_opts.ringbuffer_on) { - cfile.save_file_fd = ringbuf_init(cfile.save_file, + save_file_fd = ringbuf_init(cfile.save_file, capture_opts.ringbuffer_num_files); - if (cfile.save_file_fd != -1) { + if (save_file_fd != -1) { ld.pdh = ringbuf_init_wtap_dump_fdopen(out_file_type, ld.linktype, file_snaplen, &err); } else { @@ -2034,7 +2035,7 @@ capture(int out_file_type) its maximum size. */ if (capture_opts.ringbuffer_on) { /* Switch to the next ringbuffer file */ - if (ringbuf_switch_file(&ld.pdh, &cfile.save_file, &cfile.save_file_fd, &loop_err)) { + if (ringbuf_switch_file(&ld.pdh, &cfile.save_file, &save_file_fd, &loop_err)) { /* File switch succeeded: reset the condition */ cnd_reset(cnd_stop_capturesize); if (cnd_ring_timeout) { @@ -2168,6 +2169,7 @@ capture_pcap_cb(guchar *user, const struct pcap_pkthdr *phdr, loop_data *ldat = (loop_data *) user; int loop_err; int err; + int save_file_fd; /* Convert from libpcap to Wiretap format. If that fails, ignore the packet (wtap_process_pcap_packet has @@ -2193,7 +2195,7 @@ capture_pcap_cb(guchar *user, const struct pcap_pkthdr *phdr, */ if (cnd_ring_timeout != NULL && cnd_eval(cnd_ring_timeout)) { /* time elapsed for this ring file, switch to the next */ - if (ringbuf_switch_file(&ldat->pdh, &cfile.save_file, &cfile.save_file_fd, &loop_err)) { + if (ringbuf_switch_file(&ldat->pdh, &cfile.save_file, &save_file_fd, &loop_err)) { /* File switch succeeded: reset the condition */ cnd_reset(cnd_ring_timeout); } else { -- cgit v1.2.1