diff options
-rw-r--r-- | gtk/cfilter_combo_utils.c | 215 | ||||
-rw-r--r-- | gtk/cfilter_combo_utils.h | 73 |
2 files changed, 145 insertions, 143 deletions
diff --git a/gtk/cfilter_combo_utils.c b/gtk/cfilter_combo_utils.c index fe10194ad2..3d0c6a3b9e 100644 --- a/gtk/cfilter_combo_utils.c +++ b/gtk/cfilter_combo_utils.c @@ -1,107 +1,108 @@ -/* cfilter_combo_utils.c
- * Capture filter combo box routines
- *
- * $Id: cfilter_combo_utils.c 12115 2004-09-27 22:55:15Z guy $
- *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <gtk/gtk.h>
-#include "compat_macros.h"
-#include "main.h"
-#include "gtkglobals.h"
-#include "cfilter_combo_utils.h"
-#include "recent.h"
-#ifdef HAVE_LIBPCAP
-#include <pcap.h>
-#endif
-
-/* XXX: use a preference for this setting! */
-static guint cfilter_combo_max_recent = 20;
-
-gboolean
-cfilter_combo_add(gchar *s) {
- GList *li;
- GList *fl = OBJECT_GET_DATA(top_level, E_CFILTER_FL_KEY);
-
- li = g_list_first(fl);
- while (li) {
- /* If the filter is already in the list, remove the old one and
- * append the new one at the latest position (at g_list_append() below) */
- if (li->data && strcmp(s, li->data) == 0) {
- fl = g_list_remove(fl, li->data);
- break;
- }
- li = li->next;
- }
- fl = g_list_append(fl, s);
- OBJECT_SET_DATA(top_level, E_CFILTER_FL_KEY, fl);
- return TRUE;
-}
-
-
-/* write all non empty capture filters (until maximum count)
- * of the combo box GList to the user's recent file */
-void
- cfilter_combo_recent_write_all(FILE *rf) {
- GList *filter_list = OBJECT_GET_DATA(top_level, E_CFILTER_FL_KEY);
- GList *li;
- guint max_count = 0;
-
- /* write all non empty display filter strings to the recent file (until max count) */
- li = g_list_first(filter_list);
- while ( li && (max_count++ <= cfilter_combo_max_recent) ) {
- if (strlen(li->data)) {
- fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data);
- }
- li = li->next;
- }
-}
-
-/* add a capture filter coming from the user's recent file to the cfilter combo box */
-gboolean
- cfilter_combo_add_recent(gchar *s) {
- gchar *dup;
-
- dup = g_strdup(s);
- if (!cfilter_combo_add(dup)) {
- g_free(dup);
- return FALSE;
- }
- 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;
- }
-}
+/* cfilter_combo_utils.c + * Capture filter combo box routines + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <gtk/gtk.h> +#include "compat_macros.h" +#include "main.h" +#include "gtkglobals.h" +#include "cfilter_combo_utils.h" +#include "recent.h" +#ifdef HAVE_LIBPCAP +#include <pcap.h> +#endif + +/* XXX: use a preference for this setting! */ +static guint cfilter_combo_max_recent = 20; + +gboolean +cfilter_combo_add(gchar *s) { + GList *li; + GList *fl = OBJECT_GET_DATA(top_level, E_CFILTER_FL_KEY); + + li = g_list_first(fl); + while (li) { + /* If the filter is already in the list, remove the old one and + * append the new one at the latest position (at g_list_append() below) */ + if (li->data && strcmp(s, li->data) == 0) { + fl = g_list_remove(fl, li->data); + break; + } + li = li->next; + } + fl = g_list_append(fl, s); + OBJECT_SET_DATA(top_level, E_CFILTER_FL_KEY, fl); + return TRUE; +} + + +/* write all non empty capture filters (until maximum count) + * of the combo box GList to the user's recent file */ +void + cfilter_combo_recent_write_all(FILE *rf) { + GList *filter_list = OBJECT_GET_DATA(top_level, E_CFILTER_FL_KEY); + GList *li; + guint max_count = 0; + + /* write all non empty display filter strings to the recent file (until max count) */ + li = g_list_first(filter_list); + while ( li && (max_count++ <= cfilter_combo_max_recent) ) { + if (strlen(li->data)) { + fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data); + } + li = li->next; + } +} + +/* add a capture filter coming from the user's recent file to the cfilter combo box */ +gboolean + cfilter_combo_add_recent(gchar *s) { + gchar *dup; + + dup = g_strdup(s); + if (!cfilter_combo_add(dup)) { + g_free(dup); + return FALSE; + } + 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; + } +} diff --git a/gtk/cfilter_combo_utils.h b/gtk/cfilter_combo_utils.h index 1a4560cb96..08f4b41746 100644 --- a/gtk/cfilter_combo_utils.h +++ b/gtk/cfilter_combo_utils.h @@ -1,36 +1,37 @@ -/* cfilter_combo_utils.h
- * Capture filter combo box routines
- *
- * $Id: cfilter_combo_utils.h 12115 2004-09-27 22:55:15Z guy $
- *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-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"
\ No newline at end of file +/* cfilter_combo_utils.h + * Capture filter combo box routines + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +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" |