diff options
-rw-r--r-- | Makefile.nmake | 1 | ||||
-rw-r--r-- | capture-wpcap.c | 35 | ||||
-rw-r--r-- | config.h.win32 | 1 | ||||
-rw-r--r-- | config.nmake | 2 | ||||
-rw-r--r-- | gtk/capture_dlg.c | 47 |
5 files changed, 51 insertions, 35 deletions
diff --git a/Makefile.nmake b/Makefile.nmake index 5318820077..34858697ca 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -369,6 +369,7 @@ config.h : config.h.win32 config.nmake -e "s/@HAVE_REMOTE@/$(PCAP_HAVE_REMOTE_CONFIG)/" \ -e "s/@HAVE_PCAP_REMOTE@/$(PCAP_REMOTE_CONFIG)/" \ -e "s/@HAVE_PCAP_OPEN@/$(PCAP_OPEN_CONFIG)/" \ + -e "s/@HAVE_PCAP_OPEN_DEAD@/$(PCAP_OPEN_DEAD_CONFIG)/" \ -e "s/@HAVE_PCAP_LIST_DATALINKS@/$(PCAP_LIST_DATALINKS_CONFIG)/" \ -e "s/@HAVE_PCAP_FREE_DATALINKS@/$(PCAP_FREE_DATALINKS_CONFIG)/" \ -e "s/@HAVE_PCAP_SET_DATALINK@/$(PCAP_SET_DATALINK_CONFIG)/" \ diff --git a/capture-wpcap.c b/capture-wpcap.c index f1d0cf06d6..d081fa657b 100644 --- a/capture-wpcap.c +++ b/capture-wpcap.c @@ -69,6 +69,9 @@ static int (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *, char *); static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *); static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *); +#ifdef HAVE_PCAP_OPEN_DEAD +static pcap_t* (*p_pcap_open_dead) (int, int); +#endif static void (*p_pcap_freecode) (struct bpf_program *); #ifdef HAVE_PCAP_FINDALLDEVS static int (*p_pcap_findalldevs) (pcap_if_t **, char *); @@ -113,6 +116,10 @@ static int (*p_pcap_set_datalink)(pcap_t *, int); static int (*p_pcap_free_datalinks)(int *); #endif +#ifdef HAVE_BPF_IMAGE +static char *(*p_bpf_image) (const struct bpf_insn *, int); +#endif + typedef struct { const char *name; gpointer *ptr; @@ -144,6 +151,9 @@ load_wpcap(void) SYM(pcap_createsrcstr, FALSE), #endif SYM(pcap_open_live, FALSE), +#ifdef HAVE_PCAP_OPEN_DEAD + SYM(pcap_open_dead, FALSE), +#endif #ifdef HAVE_PCAP_SETSAMPLING SYM(pcap_setsampling, TRUE), #endif @@ -182,6 +192,9 @@ load_wpcap(void) #ifdef HAVE_PCAP_FREE_DATALINKS SYM(pcap_free_datalinks, TRUE), #endif +#ifdef HAVE_BPF_IMAGE + SYM(bpf_image, FALSE), +#endif { NULL, NULL, FALSE } }; @@ -316,6 +329,28 @@ pcap_open_live(const char *a, int b, int c, int d, char *e) return p_pcap_open_live(a, b, c, d, e); } +#ifdef HAVE_PCAP_OPEN_DEAD +pcap_t* +pcap_open_dead(int a, int b) +{ + if (!has_wpcap) { + return NULL; + } + return p_pcap_open_dead(a, b); +} +#endif + +#ifdef HAVE_BPF_IMAGE +static char * +bpf_image(const struct bpf_insn *a, int b) +{ + if (!has_wpcap) { + return NULL; + } + return p_bpf_image(a, b); +} +#endif + #ifdef HAVE_PCAP_REMOTE pcap_t* pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f) diff --git a/config.h.win32 b/config.h.win32 index 211d3eeebc..98e76c411c 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -63,6 +63,7 @@ @HAVE_REMOTE@ @HAVE_PCAP_REMOTE@ @HAVE_PCAP_OPEN@ +@HAVE_PCAP_OPEN_DEAD@ @HAVE_PCAP_SETSAMPLING@ @HAVE_AIRPCAP@ diff --git a/config.nmake b/config.nmake index c24979bcf6..89b7312aea 100644 --- a/config.nmake +++ b/config.nmake @@ -1033,6 +1033,7 @@ PCAP_BREAKLOOP_CONFIG= PCAP_LIST_DATALINKS_CONFIG=^#define HAVE_PCAP_LIST_DATALINKS 1 PCAP_FREE_DATALINKS_CONFIG=^#define HAVE_PCAP_FREE_DATALINKS 1 PCAP_SET_DATALINK_CONFIG=^#define HAVE_PCAP_SET_DATALINK 1 +PCAP_OPEN_DEAD_CONFIG=^#define HAVE_PCAP_OPEN_DEAD 1 !ELSE # no WpdPack installed WINPCAP_CONFIG= @@ -1044,6 +1045,7 @@ PCAP_BREAKLOOP_CONFIG= PCAP_LIST_DATALINKS_CONFIG= PCAP_FREE_DATALINKS_CONFIG= PCAP_SET_DATALINK_CONFIG= +PCAP_OPEN_DEAD_CONFIG= !ENDIF !IF DEFINED(PCAP_DIR) && DEFINED(PCAP_REMOTE) diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 677e7f0ee4..18c3499d13 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -154,6 +154,9 @@ #define E_CAP_SAMP_TIMER_SB_KEY "cap_samp_timer_sb" #endif +#define DUMMY_SNAPLENGTH 65535 +#define DUMMY_NETMASK 0xFF000000 + /* * Keep a static pointer to the current "Capture Options" window, if * any, so that if somebody tries to do "Capture:Start" while there's @@ -261,9 +264,9 @@ capture_filter_check_syntax_cb(GtkWidget *w _U_, gpointer user_data _U_) return; } - if (pcap_compile_nopcap(128 /* use a dummy snaplength for syntax-checking */, + if (pcap_compile_nopcap(DUMMY_SNAPLENGTH /* use a dummy snaplength for syntax-checking */, global_capture_opts.linktype, &fcode, filter_text, 1 /* Do optimize */, - (guint)255*256*256*256 /* use a dummy netmask for syntax-checking */) < 0) { + DUMMY_NETMASK /* use a dummy netmask for syntax-checking */) < 0) { colorize_filter_te_as_invalid(filter_te); } else { colorize_filter_te_as_valid(filter_te); @@ -1503,43 +1506,17 @@ capture_remote_combo_add_recent(gchar *s) #endif -#ifdef HAVE_PCAP_CREATE +#if defined(HAVE_PCAP_OPEN_DEAD) && defined(HAVE_BPF_IMAGE) static void capture_filter_compile_cb(GtkWidget *w _U_, gpointer user_data _U_) { - GtkWidget *if_cb; - gchar *entry_text; - gchar *if_text; - const gchar *if_name; - pcap_t *pd; struct bpf_program fcode; - char errbuf[PCAP_ERRBUF_SIZE]; GtkWidget *filter_cm, *filter_te; const gchar *filter_text; - if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY); - entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry))); - if_text = g_strstrip(entry_text); - if_name = get_if_name(if_text); - if (*if_name == '\0') { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "You didn't specify an interface on which to capture packets."); - g_free(entry_text); - return; - } - - if (!(pd = pcap_create(if_name, errbuf))) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", errbuf); - g_free(entry_text); - return; - } - /* Activate the PD to set the proper DLT for this interface */ - pcap_activate(pd); - /* change the DLT if the user selected a non-default DLT for the interface */ - if (global_capture_opts.linktype != -1) - pcap_set_datalink(pd, global_capture_opts.linktype); + pd = pcap_open_dead(global_capture_opts.linktype, DUMMY_SNAPLENGTH); filter_cm = g_object_get_data(G_OBJECT(top_level), E_CFILTER_CM_KEY); filter_te = GTK_COMBO(filter_cm)->entry; @@ -1560,7 +1537,9 @@ capture_filter_compile_cb(GtkWidget *w _U_, gpointer user_data _U_) gchar *bpf_code_markup; for (i = 0; i < n; ++insn, ++i) { +/* g_string_append(bpf_code_dump, bpf_image(insn, i)); +*/ g_string_append(bpf_code_dump, "\n"); } @@ -1573,12 +1552,10 @@ capture_filter_compile_cb(GtkWidget *w _U_, gpointer user_data _U_) g_free(bpf_code_markup); } - g_free(entry_text); pcap_close(pd); } #endif - /* show capture prepare (options) dialog */ void capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) @@ -1597,7 +1574,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) #endif *pcap_ng_cb, *filter_hb, *filter_bt, *filter_te, *filter_cm, -#ifdef HAVE_PCAP_CREATE +#if defined(HAVE_PCAP_OPEN_DEAD) && defined(HAVE_BPF_IMAGE) *compile_bt, #endif *file_fr, *file_vb, @@ -1980,7 +1957,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) /* let an eventually capture filters dialog know the text entry to fill in */ g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te); -#ifdef HAVE_PCAP_CREATE +#if defined(HAVE_PCAP_OPEN_DEAD) && defined(HAVE_BPF_IMAGE) compile_bt = gtk_button_new_with_label("Compile BPF"); g_signal_connect(compile_bt, "clicked", G_CALLBACK(capture_filter_compile_cb), NULL); gtk_tooltips_set_tip(tooltips, compile_bt, @@ -3054,7 +3031,7 @@ capture_prep_destroy_cb(GtkWidget *win, gpointer user_data _U_) /* user changed the interface entry */ static void -capture_prep_interface_changed_cb(GtkWidget *entry _U_, gpointer argp _U_) +capture_prep_interface_changed_cb(GtkWidget *entry, gpointer argp) { set_if_capabilities(FALSE); capture_filter_check_syntax_cb(entry, argp); |