Have the ring buffer routines take a pointer to a "bytes written" count
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 29 Apr 2006 17:54:46 +0000 (17:54 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 29 Apr 2006 17:54:46 +0000 (17:54 +0000)
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.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@18032 f5534014-38df-0310-8fa8-9805f1628bb7

capture_loop.c
ringbuffer.c
ringbuffer.h
tethereal.c

index f4a3f90..16d32bb 100644 (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)
index 7d1e00a..f4cf4b0 100644 (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;
   }
 
index 8989f5c..63af28b 100644 (file)
 
 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);
index b2fb7a0..ece0213 100644 (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 {