remove #include "globals.h" and access to global cfile, use access functions and...
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Feb 2005 08:42:39 +0000 (08:42 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Feb 2005 08:42:39 +0000 (08:42 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13284 f5534014-38df-0310-8fa8-9805f1628bb7

capture_loop.c
file.c
file.h

index 3baf06af64650a1f75b0e8dd8fd9eca1eac30e83..7d4d8cd204f3c09ecd40ab1e2e59123f5968ec81 100644 (file)
@@ -72,7 +72,6 @@
 #include "pcap-util.h"
 
 #include "simple_dialog.h"
-#include "globals.h"
 #include "conditions.h"
 #include "capture_stop_conditions.h"
 #include "ringbuffer.h"
@@ -559,14 +558,14 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
      if they succeed; to tell if that's happened, we have to clear
      the error buffer, and check if it's still a null string.  */
   open_err_str[0] = '\0';
-  ld->pcap_h = pcap_open_live(cfile.iface,
+  ld->pcap_h = pcap_open_live(cf_get_iface(capture_opts->cf),
                       capture_opts->has_snaplen ? capture_opts->snaplen :
                                                  WTAP_MAX_PACKET_SIZE,
                       capture_opts->promisc_mode, CAP_READ_TIMEOUT,
                       open_err_str);
 
   if (ld->pcap_h != NULL) {
-    /* we've opened "cfile.iface" as a network device */
+    /* we've opened "iface" as a network device */
 #ifdef _WIN32
     /* try to set the capture buffer size */
     if (pcap_setbuff(ld->pcap_h, capture_opts->buffer_size * 1024 * 1024) != 0) {
@@ -583,7 +582,7 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
 
     /* setting the data link type only works on real interfaces */
     if (capture_opts->linktype != -1) {
-      set_linktype_err_str = set_pcap_linktype(ld->pcap_h, cfile.iface,
+      set_linktype_err_str = set_pcap_linktype(ld->pcap_h, cf_get_iface(capture_opts->cf),
        capture_opts->linktype);
       if (set_linktype_err_str != NULL) {
        g_snprintf(errmsg, errmsg_len, "Unable to set data link type (%s).",
@@ -592,7 +591,7 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
       }
     }
   } else {
-    /* We couldn't open "cfile.iface" as a network device. */
+    /* We couldn't open "iface" as a network device. */
 #ifdef _WIN32
     /* On Windows, we don't support capturing on pipes, so we give up.
        If this is a child process that does the capturing in sync
@@ -618,8 +617,8 @@ static int capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
        open_err_str);
     return FALSE;
 #else
-    /* try to open cfile.iface as a pipe */
-    ld->cap_pipe_fd = cap_pipe_open_live(cfile.iface, &ld->cap_pipe_hdr, ld, errmsg, errmsg_len);
+    /* try to open iface as a pipe */
+    ld->cap_pipe_fd = cap_pipe_open_live(cf_get_iface(capture_opts->cf), &ld->cap_pipe_hdr, ld, errmsg, errmsg_len);
 
     if (ld->cap_pipe_fd == -1) {
 
@@ -709,15 +708,15 @@ static void capture_loop_close_input(loop_data *ld) {
 
 
 /* init the capture filter */
-static int capture_loop_init_filter(loop_data *ld, char *errmsg, int errmsg_len) {
+static int capture_loop_init_filter(loop_data *ld, const gchar * iface, gchar * cfilter, char *errmsg, int errmsg_len) {
   bpf_u_int32 netnum, netmask;
   gchar       lookup_net_err_str[PCAP_ERRBUF_SIZE];
   struct bpf_program fcode;
 
   /* capture filters only work on real interfaces */
-  if (cfile.cfilter && !ld->from_cap_pipe) {
+  if (cfilter && !ld->from_cap_pipe) {
     /* A capture filter was specified; set it up. */
-    if (pcap_lookupnet(cfile.iface, &netnum, &netmask, lookup_net_err_str) < 0) {
+    if (pcap_lookupnet(iface, &netnum, &netmask, lookup_net_err_str) < 0) {
       /*
        * Well, we can't get the netmask for this interface; it's used
        * only for filters that check for broadcast IP addresses, so
@@ -729,10 +728,10 @@ static int capture_loop_init_filter(loop_data *ld, char *errmsg, int errmsg_len)
        */
       netmask = 0;
     }
-    if (pcap_compile(ld->pcap_h, &fcode, cfile.cfilter, 1, netmask) < 0) {
+    if (pcap_compile(ld->pcap_h, &fcode, cfilter, 1, netmask) < 0) {
       dfilter_t   *rfcode = NULL;
       /* filter string invalid, did the user tried a display filter? */
-      if (dfilter_compile(cfile.cfilter, &rfcode) && rfcode != NULL) {
+      if (dfilter_compile(cfilter, &rfcode) && rfcode != NULL) {
         g_snprintf(errmsg, errmsg_len,
           "%sInvalid capture filter: \"%s\"!%s\n"
           "\n"
@@ -743,7 +742,7 @@ static int capture_loop_init_filter(loop_data *ld, char *errmsg, int errmsg_len)
           "so you can't use most display filter expressions as capture filters.\n"
           "\n"
           "See the help for a description of the capture filter syntax.",
-          simple_dialog_primary_start(), cfile.cfilter, simple_dialog_primary_end(),
+          simple_dialog_primary_start(), cfilter, simple_dialog_primary_end(),
           pcap_geterr(ld->pcap_h));
        dfilter_free(rfcode);
       } else {
@@ -752,7 +751,7 @@ static int capture_loop_init_filter(loop_data *ld, char *errmsg, int errmsg_len)
           "\n"
           "That string isn't a valid capture filter (%s).\n"
           "See the help for a description of the capture filter syntax.",
-          simple_dialog_primary_start(), cfile.cfilter, simple_dialog_primary_end(),
+          simple_dialog_primary_start(), cfilter, simple_dialog_primary_end(),
           pcap_geterr(ld->pcap_h));
       }
       return FALSE;
@@ -783,7 +782,7 @@ static int capture_loop_open_wiretap_output(capture_options *capture_opts, loop_
   } else
 #endif
   {
-    pcap_encap = get_pcap_linktype(ld->pcap_h, cfile.iface);
+    pcap_encap = get_pcap_linktype(ld->pcap_h, cf_get_iface(capture_opts->cf));
     file_snaplen = pcap_snapshot(ld->pcap_h);
   }
 
@@ -1024,7 +1023,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
   }
 
   /* init the input filter from the network interface (capture pipe will do nothing) */
-  if (!capture_loop_init_filter(&ld, errmsg, sizeof(errmsg))) {
+  if (!capture_loop_init_filter(&ld, cf_get_iface(capture_opts->cf), cf_get_cfilter(capture_opts->cf), errmsg, sizeof(errmsg))) {
     goto error;
   }
 
@@ -1076,7 +1075,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
   if(show_info) {
       capture_ui.callback_data  = &ld;
       capture_ui.counts         = &ld.counts;
-      capture_info_create(&capture_ui, cfile.iface);
+      capture_info_create(&capture_ui, cf_get_iface(capture_opts->cf));
   }
 
   /* init the time values */
diff --git a/file.c b/file.c
index a5a395fd6db17111a950526094a2b5daed4a7b44..7de1d489e69e6576c1749cd9de1b81d2a9848066 100644 (file)
--- a/file.c
+++ b/file.c
@@ -746,6 +746,10 @@ void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
     cf->rfcode = rfcode;
 }
 
+gchar *cf_get_cfilter(capture_file *cf)
+{
+    return cf->cfilter;
+}
 
 typedef struct {
   color_filter_t *colorf;
diff --git a/file.h b/file.h
index 1584f994ad31682a06a1f37c5660e01a69e2d483..763c6b8d54632a10b3c8da03c18330091dc6fe5e 100644 (file)
--- a/file.h
+++ b/file.h
@@ -58,6 +58,7 @@ void cf_set_drops_known(capture_file *cf, gboolean drops_known);
 void cf_set_drops(capture_file *cf, guint32 drops);
 gchar *cf_get_iface(capture_file *cf);
 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
+gchar *cf_get_cfilter(capture_file *cf);
 
 gboolean
 cf_merge_files(const char *out_filename, int out_fd, int in_file_count,