Save the capture filter in the recent list iff the capture succeeds.

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.

svn path=/trunk/; revision=12225
This commit is contained in:
Guy Harris 2004-10-07 03:50:16 +00:00
parent 5a244d166b
commit ab9b8d36b5
3 changed files with 5 additions and 31 deletions

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

View 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;
}
}

View File

@ -25,13 +25,6 @@
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"