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
This commit is contained in:
parent
fc9a0f0744
commit
9ff19a4c94
|
@ -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\")"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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. */
|
||||
|
|
1
cfile.c
1
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;
|
||||
|
|
1
cfile.h
1
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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
10
tethereal.c
10
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 {
|
||||
|
|
Loading…
Reference in New Issue