From 6c9a1dc0939565e1ca0140e3260abaa1184fafdf Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Sat, 13 Mar 2004 22:49:30 +0000 Subject: experimental: make usage of pcap_setbuff to increase the kernel buffer size svn path=/trunk/; revision=10377 --- capture-wpcap.c | 11 ++++++++++- capture.c | 16 +++++++++++++++- capture.h | 5 ++++- gtk/capture_dlg.c | 39 ++++++++++++++++++++++++++++++++++++++- gtk/main.c | 5 ++++- 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/capture-wpcap.c b/capture-wpcap.c index 618dd58747..53225ae889 100644 --- a/capture-wpcap.c +++ b/capture-wpcap.c @@ -3,7 +3,7 @@ * time, so that we only need one Ethereal binary and one Tethereal binary * for Windows, regardless of whether WinPcap is installed or not. * - * $Id: capture-wpcap.c,v 1.8 2004/01/05 19:31:42 ulfl Exp $ + * $Id: capture-wpcap.c,v 1.9 2004/03/13 22:49:29 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -70,6 +70,7 @@ static int (*p_pcap_findalldevs) (pcap_if_t **, char *); static void (*p_pcap_freealldevs) (pcap_if_t *); #endif static const char *(*p_pcap_lib_version) (void); +static int (*p_pcap_setbuff) (pcap_t *, int dim); typedef struct { const char *name; @@ -102,6 +103,7 @@ load_wpcap(void) SYM(pcap_freealldevs, TRUE), #endif SYM(pcap_lib_version, TRUE), + SYM(pcap_setbuff, TRUE), { NULL, NULL, FALSE } }; @@ -248,6 +250,13 @@ pcap_freealldevs(pcap_if_t *a) } #endif +/* setbuff is win32 specific! */ +int pcap_setbuff(pcap_t *a, int b) +{ + g_assert(has_wpcap); + return p_pcap_setbuff(a, b); +} + /* * This will use "pcap_findalldevs()" if we have it, otherwise it'll * fall back on "pcap_lookupdev()". diff --git a/capture.c b/capture.c index 7644af8eed..be3a16c17a 100644 --- a/capture.c +++ b/capture.c @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.245 2004/03/04 21:27:55 ulfl Exp $ + * $Id: capture.c,v 1.246 2004/03/13 22:49:30 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -1516,6 +1516,20 @@ capture(gboolean *stats_known, struct pcap_stat *stats) open_err_str); if (pch != NULL) { +#ifdef _WIN32 + /* try to set the capture buffer size */ + if (pcap_setbuff(pch, capture_opts.buffer_size * 1024 * 1024) != 0) { + simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, + "%sCouldn't set the capture buffer size!%s\n" + "\n" + "The capture buffer size of %luMB seems to be too high for your machine,\n" + "the default of 1MB will be used.\n" + "\n" + "Nonetheless, the capture is started.\n", + simple_dialog_primary_start(), simple_dialog_primary_end(), capture_opts.buffer_size); + } +#endif + /* setting the data link type only works on real interfaces */ if (capture_opts.linktype != -1) { set_linktype_err_str = set_pcap_linktype(pch, cfile.iface, diff --git a/capture.h b/capture.h index 09d79cb788..916a6a74c0 100644 --- a/capture.h +++ b/capture.h @@ -1,7 +1,7 @@ /* capture.h * Definitions for packet capture windows * - * $Id: capture.h,v 1.43 2004/03/04 19:31:20 ulfl Exp $ + * $Id: capture.h,v 1.44 2004/03/13 22:49:30 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -31,6 +31,9 @@ #define CHILD_NAME "ethereal-capture" typedef struct { +#ifdef _WIN32 + int buffer_size; /* the capture buffer size (MB) */ +#endif gboolean has_snaplen; /* TRUE if maximum capture packet length is specified */ int snaplen; /* Maximum captured packet length */ diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 1c39ab5dc9..2da27a83d7 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -1,7 +1,7 @@ /* capture_dlg.c * Routines for packet capture windows * - * $Id: capture_dlg.c,v 1.120 2004/03/06 11:10:14 ulfl Exp $ + * $Id: capture_dlg.c,v 1.121 2004/03/13 22:49:30 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -60,6 +60,9 @@ #define E_CAP_SNAP_CB_KEY "cap_snap_cb" #define E_CAP_LT_OM_KEY "cap_lt_om" #define E_CAP_LT_OM_LABEL_KEY "cap_lt_om_label" +#ifdef _WIN32 +#define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb" +#endif #define E_CAP_SNAP_SB_KEY "cap_snap_sb" #define E_CAP_PROMISC_KEY "cap_promisc" #define E_CAP_FILT_KEY "cap_filter_te" @@ -466,6 +469,10 @@ capture_prep(void) int err; int row; char err_str[PCAP_ERRBUF_SIZE]; +#ifdef _WIN32 + GtkAdjustment *buffer_size_adj; + GtkWidget *buffer_size_lb, *buffer_size_sb; +#endif if (cap_open_w != NULL) { /* There's already a "Capture Options" dialog box; reactivate it. */ @@ -569,6 +576,22 @@ capture_prep(void) SIGNAL_CONNECT(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "changed", capture_prep_interface_changed_cb, linktype_om); +#ifdef _WIN32 + buffer_size_lb = gtk_label_new("Buffer size:"); + gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0); + + buffer_size_adj = (GtkAdjustment *) gtk_adjustment_new((gfloat) capture_opts.buffer_size, + 1, 65535, 1.0, 10.0, 0.0); + buffer_size_sb = gtk_spin_button_new (buffer_size_adj, 0, 0); + gtk_spin_button_set_value(GTK_SPIN_BUTTON (buffer_size_sb), (gfloat) capture_opts.buffer_size); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (buffer_size_sb), TRUE); + WIDGET_SET_SIZE(buffer_size_sb, 80, -1); + gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_sb, FALSE, FALSE, 0); + + buffer_size_lb = gtk_label_new("megabyte(s)"); + gtk_box_pack_start (GTK_BOX(linktype_hb), buffer_size_lb, FALSE, FALSE, 0); +#endif + /* Promiscuous mode row */ promisc_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC( "Capture packets in _promiscuous mode", accel_group); @@ -876,6 +899,9 @@ capture_prep(void) OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_CB_KEY, snap_cb); OBJECT_SET_DATA(cap_open_w, E_CAP_SNAP_SB_KEY, snap_sb); OBJECT_SET_DATA(cap_open_w, E_CAP_LT_OM_KEY, linktype_om); +#ifdef _WIN32 + OBJECT_SET_DATA(cap_open_w, E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb); +#endif OBJECT_SET_DATA(cap_open_w, E_CAP_PROMISC_KEY, promisc_cb); OBJECT_SET_DATA(cap_open_w, E_CAP_FILT_KEY, filter_te); OBJECT_SET_DATA(cap_open_w, E_CAP_FILE_TE_KEY, file_te); @@ -1109,6 +1135,9 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) { *file_duration_cb, *file_duration_sb, *file_duration_om, *stop_files_cb, *stop_files_sb, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb; +#ifdef _WIN32 + GtkWidget *buffer_size_sb; +#endif gchar *entry_text; gchar *if_text; gchar *if_name; @@ -1123,6 +1152,9 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) { snap_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_CB_KEY); snap_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_SNAP_SB_KEY); linktype_om = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_LT_OM_KEY); +#ifdef _WIN32 + buffer_size_sb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_BUFFER_SIZE_SB_KEY); +#endif promisc_cb = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_PROMISC_KEY); filter_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILT_KEY); file_te = (GtkWidget *) OBJECT_GET_DATA(parent_w, E_CAP_FILE_TE_KEY); @@ -1169,6 +1201,11 @@ capture_prep_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) { capture_opts.linktype = GPOINTER_TO_INT(OBJECT_GET_DATA(linktype_om, E_CAP_OM_LT_VALUE_KEY)); +#ifdef _WIN32 + capture_opts.buffer_size = + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb)); +#endif + capture_opts.has_snaplen = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(snap_cb)); if (capture_opts.has_snaplen) { diff --git a/gtk/main.c b/gtk/main.c index 7b7a1fd2e3..6c7337c720 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.414 2004/03/13 15:15:25 ulfl Exp $ + * $Id: main.c,v 1.415 2004/03/13 22:49:30 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -2010,6 +2010,9 @@ main(int argc, char *argv[]) capture_opts.has_snaplen = FALSE; capture_opts.snaplen = MIN_PACKET_SIZE; capture_opts.linktype = -1; +#ifdef _WIN32 + capture_opts.buffer_size = 1; +#endif capture_opts.has_autostop_packets = FALSE; capture_opts.autostop_packets = 1; -- cgit v1.2.3