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
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));
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);
}
}
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;
- }
-}
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"