Have the ring buffer routines take a pointer to a "bytes written" count

as an argument, rather than keeping the count to themselves, so the
count kept by the capturing program can be updated correctly - including
getting reset when files are switched.  Fixes bug 895.

svn path=/trunk/; revision=18032
This commit is contained in:
Guy Harris 2006-04-29 17:54:46 +00:00
parent f3d1963924
commit 25e8c37489
4 changed files with 21 additions and 13 deletions

View File

@ -744,7 +744,8 @@ gboolean capture_loop_init_output(capture_options *capture_opts, int save_file_f
/* Set up to write to the capture file. */
if (capture_opts->multi_files_on) {
ld->pdh = ringbuf_init_libpcap_fdopen(ld->linktype, file_snaplen, &err);
ld->pdh = ringbuf_init_libpcap_fdopen(ld->linktype, file_snaplen,
&ld->bytes_written, &err);
} else {
ld->pdh = libpcap_fdopen(save_file_fd, ld->linktype, file_snaplen,
&ld->bytes_written, &err);
@ -1233,7 +1234,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* Switch to the next ringbuffer file */
if (ringbuf_switch_file(&ld.pdh, &capture_opts->save_file,
&save_file_fd, &ld.err)) {
&save_file_fd, &ld.bytes_written, &ld.err)) {
/* File switch succeeded: reset the conditions */
cnd_reset(cnd_autostop_size);
if (cnd_file_duration) {
@ -1303,7 +1304,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
}
/* Switch to the next ringbuffer file */
if (ringbuf_switch_file(&ld.pdh, &capture_opts->save_file, &save_file_fd, &ld.err)) {
if (ringbuf_switch_file(&ld.pdh, &capture_opts->save_file,
&save_file_fd, &ld.bytes_written, &ld.err)) {
/* file switch succeeded: reset the conditions */
cnd_reset(cnd_file_duration);
if(cnd_autostop_size)

View File

@ -88,7 +88,6 @@ typedef struct _ringbuf_data {
int fd; /* Current ringbuffer file descriptor */
FILE *pdh;
long bytes_written; /* Bytes written to the current file */
} ringbuf_data;
static ringbuf_data rb_data;
@ -231,14 +230,15 @@ const gchar *ringbuf_current_filename(void)
* Calls libpcap_fdopen() for the current ringbuffer file
*/
FILE *
ringbuf_init_libpcap_fdopen(int linktype, int snaplen, int *err)
ringbuf_init_libpcap_fdopen(int linktype, int snaplen,
long *bytes_written, int *err)
{
rb_data.linktype = linktype;
rb_data.snaplen = snaplen;
rb_data.pdh = libpcap_fdopen(rb_data.fd, linktype, snaplen,
&rb_data.bytes_written, err);
rb_data.pdh = libpcap_fdopen(rb_data.fd, linktype, snaplen, bytes_written,
err);
return rb_data.pdh;
}
@ -246,7 +246,8 @@ ringbuf_init_libpcap_fdopen(int linktype, int snaplen, int *err)
* Switches to the next ringbuffer file
*/
gboolean
ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd,
long *bytes_written, int *err)
{
int next_file_num;
rb_file *next_rfile = NULL;
@ -274,7 +275,7 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
}
if (ringbuf_init_libpcap_fdopen(rb_data.linktype, rb_data.snaplen,
err) == NULL) {
bytes_written, err) == NULL) {
return FALSE;
}

View File

@ -40,8 +40,10 @@
int ringbuf_init(const char *capture_name, guint num_files);
const gchar *ringbuf_current_filename(void);
FILE *ringbuf_init_libpcap_fdopen(int linktype, int snaplen, int *err);
gboolean ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err);
FILE *ringbuf_init_libpcap_fdopen(int linktype, int snaplen,
long *bytes_written, int *err);
gboolean ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd,
long *bytes_written, int *err);
gboolean ringbuf_libpcap_dump_close(gchar **save_file, int *err);
void ringbuf_free(void);
void ringbuf_error_cleanup(void);

View File

@ -1716,7 +1716,9 @@ capture(void)
its maximum size. */
if (capture_opts.multi_files_on) {
/* Switch to the next ringbuffer file */
if (ringbuf_switch_file(&ld.pdh, &capture_opts.save_file, &save_file_fd, &loop_err)) {
if (ringbuf_switch_file(&ld.pdh, &capture_opts.save_file,
&save_file_fd, &ld.bytes_written,
&loop_err)) {
/* File switch succeeded: reset the condition */
cnd_reset(cnd_autostop_size);
if (cnd_file_duration) {
@ -1889,7 +1891,8 @@ capture_pcap_cb(u_char *user, const struct pcap_pkthdr *phdr,
*/
if (cnd_file_duration != NULL && cnd_eval(cnd_file_duration)) {
/* time elapsed for this ring file, switch to the next */
if (ringbuf_switch_file(&ld->pdh, &ld->save_file, &save_file_fd, &loop_err)) {
if (ringbuf_switch_file(&ld->pdh, &ld->save_file, &save_file_fd,
&ld->bytes_written, &loop_err)) {
/* File switch succeeded: reset the condition */
cnd_reset(cnd_file_duration);
} else {