Save the capture filter in the recent list iff the capture succeeds.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 7 Oct 2004 03:50:16 +0000 (03:50 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 7 Oct 2004 03:50:16 +0000 (03:50 +0000)
Checking the syntax involves opening a device, which

1) might not succeed

and

2) might tie up a BPF device or otherwise consume resources

so we leave it up to the capture operation to do the checking.

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

gtk/capture_dlg.c
gtk/cfilter_combo_utils.c
gtk/cfilter_combo_utils.h

index d44fd191aeaf1d5f01c6bf404a807e6bbc91d216..d507f55515d9434299fdc1ab1f3dd11ec922de67 100644 (file)
@@ -1296,10 +1296,6 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
   cfile.iface = g_strdup(if_name);
   g_free(entry_text);
 
-  /* Add this capture filter to the recent capture filter list if it passes a syntax check */
-  if(check_capture_filter_syntax(cfile.iface, (gchar *) gtk_entry_get_text(GTK_ENTRY(filter_te))))
-    cfilter_combo_add_recent((gchar *) gtk_entry_get_text(GTK_ENTRY(filter_te)));
-
   capture_opts.linktype =
       GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY));
 
@@ -1464,7 +1460,11 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) {
 
   window_destroy(GTK_WIDGET(parent_w));
 
-  do_capture(save_file);
+  if (do_capture(save_file)) {
+    /* The capture succeeded, which means the capture filter syntax is
+       valid; add this capture filter to the recent capture filter list. */
+    cfilter_combo_add_recent(cfile.cfilter);
+  }
   if (save_file != NULL)
     g_free(save_file);
 }
index 3d0c6a3b9e19e5fa7873e2a2b394199f43bf7b4f..2f06a449a8e5544601b76622329039d874fcf411 100644 (file)
@@ -87,22 +87,3 @@ gboolean
    }
    return TRUE;
 }
-
-gboolean check_capture_filter_syntax(gchar *interface_name, gchar *filter_str){
-  struct bpf_program fcode;
-  gchar       open_err_str[PCAP_ERRBUF_SIZE];
-  pcap_t     *pch;
-  int        status=0;
-
-  open_err_str[0] = '\0';
-  pch = pcap_open_live(interface_name, WTAP_MAX_PACKET_SIZE, 0, 250, open_err_str);
-  status = pcap_compile(pch, &fcode, filter_str, 1, 0);
-  pcap_close(pch);
-
-  if (status < 0){
-    return FALSE;
-  }
-  else{
-    return TRUE;
-  }
-}
index 08f4b417462a5c298ddf7ea8bf8f92ed93986f60..09ff0368af2e561277d71bb86c916224891830ed 100644 (file)
 extern void cfilter_combo_recent_write_all(FILE *rf);
 extern gboolean cfilter_combo_add_recent(gchar *s);
 
-/** Check the syntax of a capture filter string. This is done by calling pcap_open_live().
- *
- * @param interface_name The interface name to be opened by pcap_open_live().
- * @param filter_str The filter string to be verified.
- */
-extern gboolean check_capture_filter_syntax(gchar *interface_name, gchar *filter_str);
-
 #define E_CFILTER_CM_KEY          "capture_filter_combo"
 #define E_CFILTER_FL_KEY          "capture_filter_list"
 #define RECENT_KEY_CAPTURE_FILTER "recent.capture_filter"