List the disappearance of the ADDRESS macros as an API change.
[metze/wireshark/wip.git] / ringbuffer.c
index ce816008666e78a9cfc808a3a146811791ada44b..4873c34c4824054fdb096e545592822f013c4e18 100644 (file)
@@ -1,8 +1,6 @@
 /* ringbuffer.c
  * Routines for packet capture windows
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
@@ -42,9 +40,7 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include <config.h>
 
 #ifdef HAVE_LIBPCAP
 
 
 #include <glib.h>
 
-#include "pcapio.h"
 #include "ringbuffer.h"
 #include <wsutil/file_util.h>
 
 
 /* Ringbuffer file structure */
 typedef struct _rb_file {
-  gchar                *name;
+  gchar         *name;
 } rb_file;
 
 /* Ringbuffer data structure */
@@ -84,7 +79,7 @@ typedef struct _ringbuf_data {
   gchar        *fsuffix;             /* Filename suffix */
   gboolean      unlimited;           /* TRUE if unlimited number of files */
 
-  int           fd;                 /* Current ringbuffer file descriptor */
+  int           fd;                  /* Current ringbuffer file descriptor */
   FILE         *pdh;
   gboolean      group_read_access;   /* TRUE if files need to be opened with group read access */
 } ringbuf_data;
@@ -117,14 +112,15 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
   g_snprintf(filenum, sizeof(filenum), "%05u", (rb_data.curr_file_num + 1) % RINGBUFFER_MAX_NUM_FILES);
   strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(&current_time));
   rfile->name = g_strconcat(rb_data.fprefix, "_", filenum, "_", timestr,
-                           rb_data.fsuffix, NULL);
+                            rb_data.fsuffix, NULL);
 
   if (rfile->name == NULL) {
-    *err = ENOMEM;
+    if (err != NULL)
+      *err = ENOMEM;
     return -1;
   }
 
-  rb_data.fd = ws_open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 
+  rb_data.fd = ws_open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT,
                             rb_data.group_read_access ? 0640 : 0600);
 
   if (rb_data.fd == -1 && err != NULL) {
@@ -228,12 +224,17 @@ const gchar *ringbuf_current_filename(void)
 }
 
 /*
- * Calls libpcap_fdopen() for the current ringbuffer file
+ * Calls ws_fdopen() for the current ringbuffer file
  */
 FILE *
 ringbuf_init_libpcap_fdopen(int *err)
 {
-  rb_data.pdh = libpcap_fdopen(rb_data.fd, err);
+  rb_data.pdh = ws_fdopen(rb_data.fd, "wb");
+  if (rb_data.pdh == NULL) {
+    if (err != NULL) {
+      *err = errno;
+    }
+  }
   return rb_data.pdh;
 }
 
@@ -248,9 +249,12 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
 
   /* close current file */
 
-  if (!libpcap_dump_close(rb_data.pdh, err)) {
-    ws_close(rb_data.fd);      /* XXX - the above should have closed this already */
-    rb_data.pdh = NULL;        /* it's still closed, we just got an error while closing */
+  if (fclose(rb_data.pdh) == EOF) {
+    if (err != NULL) {
+      *err = errno;
+    }
+    ws_close(rb_data.fd);  /* XXX - the above should have closed this already */
+    rb_data.pdh = NULL;    /* it's still closed, we just got an error while closing */
     rb_data.fd = -1;
     return FALSE;
   }
@@ -281,7 +285,7 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err)
 }
 
 /*
- * Calls libpcap_dump_close() for the current ringbuffer file
+ * Calls fclose() for the current ringbuffer file
  */
 gboolean
 ringbuf_libpcap_dump_close(gchar **save_file, int *err)
@@ -290,11 +294,13 @@ ringbuf_libpcap_dump_close(gchar **save_file, int *err)
 
   /* close current file, if it's open */
   if (rb_data.pdh != NULL) {
-    if (!libpcap_dump_close(rb_data.pdh, err)) {
+    if (fclose(rb_data.pdh) == EOF) {
+      if (err != NULL) {
+        *err = errno;
+      }
       ws_close(rb_data.fd);
       ret_val = FALSE;
     }
-
     rb_data.pdh = NULL;
     rb_data.fd  = -1;
   }
@@ -315,8 +321,8 @@ ringbuf_free(void)
   if (rb_data.files != NULL) {
     for (i=0; i < rb_data.num_files; i++) {
       if (rb_data.files[i].name != NULL) {
-       g_free(rb_data.files[i].name);
-       rb_data.files[i].name = NULL;
+        g_free(rb_data.files[i].name);
+        rb_data.files[i].name = NULL;
       }
     }
     g_free(rb_data.files);
@@ -342,15 +348,13 @@ ringbuf_error_cleanup(void)
 
   /* try to close via wtap */
   if (rb_data.pdh != NULL) {
-    if (libpcap_dump_close(rb_data.pdh, NULL)) {
+    if (fclose(rb_data.pdh) == 0) {
       rb_data.fd = -1;
     }
     rb_data.pdh = NULL;
   }
 
   /* close directly if still open */
-  /* XXX - it shouldn't still be open; "libpcap_dump_close()" should leave the
-     file closed even if it fails */
   if (rb_data.fd != -1) {
     ws_close(rb_data.fd);
     rb_data.fd = -1;
@@ -368,3 +372,16 @@ ringbuf_error_cleanup(void)
 }
 
 #endif /* HAVE_LIBPCAP */
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=2 tabstop=8 expandtab:
+ * :indentSize=2:tabSize=8:noTabs=true:
+ */