move capture_file_fd field from capture_file to capture_opts type, as this is the...
authorUlf Lamping <ulf.lamping@web.de>
Thu, 3 Feb 2005 22:48:20 +0000 (22:48 -0000)
committerUlf Lamping <ulf.lamping@web.de>
Thu, 3 Feb 2005 22:48:20 +0000 (22:48 -0000)
svn path=/trunk/; revision=13268

capture.c
capture.h
capture_loop.c
capture_sync.c
cfile.c
cfile.h
gtk/main.c
tethereal.c

index 109f902dd7d3e67b53893580cb1e6c6dc4f4b610..066a4a6055eeb59d47874de1ef9077bfe5409f95 100644 (file)
--- 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\")"
index 0b2bec89ed090fdf0debd0a1811afd799d2003f6..0d1c9d83399ba77140dee33f9c99df46ac3f3aaf 100644 (file)
--- 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,
index 76a968526601707c0ddbe8bc35fb655546b3df93..912152bbe759e1b50d37afe548929642d912c9f9 100644 (file)
@@ -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. */
index c07555df3c82529e1780033ff6fdd2474aaec131..6a88e9fcf9612da3df165e9ecefcf9167b805f40 100644 (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. */
diff --git a/cfile.c b/cfile.c
index 475906408db73ea04fa8fbb23ebbf42186741b8e..5b958f3252dac864ca43a124cffdf2edd40bd07f 100644 (file)
--- 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 bcb5938e96c2516e3ab614c602e9145acc626720..13c85489406443019f23382b855650b082e8a6b7 100644 (file)
--- 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 */
index db2f75bbdb01613b0610de15746ef7b16e247f26..3084766b0a1c92952e2a7753a42f372dff560890 100644 (file)
@@ -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);
index 367ec2c73ccc6cef41589811bc43ebc0cb1fe945..d83ecee3909aaeb7b4805ba6de3d1454c3d642ab 100644 (file)
@@ -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 {