diff --git a/acinclude.m4 b/acinclude.m4 index 5eb2359a07..dedbe25ff4 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -513,6 +513,9 @@ and did you also install that package?]])) AC_MSG_RESULT(no) fi AC_CHECK_FUNCS(pcap_open_dead pcap_freecode) +# Don't activate this check yet +# https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=475 +# AC_CHECK_FUNCS(pcap_create pcap_set_buffer_size) # # pcap_breakloop may be present in the library but not declared # in the pcap.h header file. If it's not declared in the header diff --git a/capture_opts.c b/capture_opts.c index 657c91f41b..48d1f37335 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -97,7 +97,7 @@ capture_opts_init(capture_options *capture_opts, void *cf) capture_opts->sampling_param = 0; #endif #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) capture_opts->buffer_size = 1; /* 1 MB */ #endif capture_opts->has_snaplen = FALSE; @@ -173,7 +173,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio g_log(log_domain, log_level, "No capture RPCAP : %u", capture_opts->nocap_rpcap); g_log(log_domain, log_level, "No capture local : %u", capture_opts->nocap_local); #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) g_log(log_domain, log_level, "BufferSize : %u (MB)", capture_opts->buffer_size); #endif g_log(log_domain, log_level, "SnapLen (%u): %u", capture_opts->has_snaplen, capture_opts->snaplen); @@ -464,7 +464,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ return 1; } break; -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) case 'B': /* Buffer size */ capture_opts->buffer_size = get_positive_int(optarg_str_p, "buffer size"); break; diff --git a/capture_opts.h b/capture_opts.h index 7b7fb67d86..507ced2926 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -105,7 +105,7 @@ typedef struct capture_options_tag { int sampling_param; /**< PCAP packet sampling parameter */ #endif #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) int buffer_size; /**< the capture buffer size (MB) */ #endif gboolean has_snaplen; /**< TRUE if maximum capture packet length diff --git a/capture_sync.c b/capture_sync.c index b26293d32d..55ff2bd121 100644 --- a/capture_sync.c +++ b/capture_sync.c @@ -257,8 +257,10 @@ sync_pipe_start(capture_options *capture_opts) { #ifdef HAVE_PCAP_SETSAMPLING char ssampling[ARGV_NUMBER_LEN]; #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) char buffer_size[ARGV_NUMBER_LEN]; +#endif +#ifdef _WIN32 HANDLE sync_pipe_read; /* pipe used to send messages from child to parent */ HANDLE sync_pipe_write; /* pipe used to send messages from child to parent */ HANDLE signal_pipe; /* named pipe used to send messages from parent to child (currently only stop) */ @@ -396,7 +398,7 @@ sync_pipe_start(capture_options *capture_opts) { #endif #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) argv = sync_pipe_add_arg(argv, &argc, "-B"); #ifdef HAVE_PCAP_REMOTE if (capture_opts->src_type == CAPTURE_IFREMOTE) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index fcfcd9963a..953f9f3bac 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -175,6 +175,9 @@ /* Define to 1 if you have the `pcap_breakloop' function. */ #cmakedefine HAVE_PCAP_BREAKLOOP 1 +/* Define to 1 if you have the `pcap_create' function. */ +#cmakedefine HAVE_PCAP_CREATE 1 + /* Define to 1 if you have the `pcap_datalink_name_to_val' function. */ #cmakedefine HAVE_PCAP_DATALINK_NAME_TO_VAL 1 @@ -206,6 +209,9 @@ /* Define to 1 if you have the `pcap_open_dead' function. */ #cmakedefine HAVE_PCAP_OPEN_DEAD 1 +/* Define to 1 if you have the `pcap_set_buffer_size' function. */ +#define HAVE_PCAP_SET_BUFFER_SIZE 1 + /* Define to 1 if you have the `pcap_set_datalink' function. */ #cmakedefine HAVE_PCAP_SET_DATALINK 1 diff --git a/config.nmake b/config.nmake index 5bba362a6d..9077bb24e1 100644 --- a/config.nmake +++ b/config.nmake @@ -7,7 +7,7 @@ # Only "win32" and "win64" are valid (for now). # This can be defined in the system environment. !IFNDEF WIRESHARK_TARGET_PLATFORM -WIRESHARK_TARGET_PLATFORM=win32 +WIRESHARK_TARGET_PLATFORM=win64 !ENDIF ##### Versions ##### diff --git a/dumpcap.c b/dumpcap.c index aff96ed484..ff8bccf9c4 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -322,7 +322,7 @@ print_usage(gboolean print_ver) { fprintf(output, " -f packet filter in libpcap filter syntax\n"); fprintf(output, " -s packet snapshot length (def: 65535)\n"); fprintf(output, " -p don't capture in promiscuous mode\n"); -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) fprintf(output, " -B size of kernel buffer (def: 1MB)\n"); #endif fprintf(output, " -y link layer type (def: first appropriate)\n"); @@ -1460,19 +1460,39 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, the error buffer, and check if it's still a null string. */ open_err_str[0] = '\0'; #ifdef HAVE_PCAP_OPEN - auth.type = capture_opts->auth_type == CAPTURE_AUTH_PWD ? - RPCAP_RMTAUTH_PWD : RPCAP_RMTAUTH_NULL; - auth.username = capture_opts->auth_username; - auth.password = capture_opts->auth_password; + if (strncmp (capture_opts->iface, "rpcap://", 8) == 0) { + auth.type = capture_opts->auth_type == CAPTURE_AUTH_PWD ? + RPCAP_RMTAUTH_PWD : RPCAP_RMTAUTH_NULL; + auth.username = capture_opts->auth_username; + auth.password = capture_opts->auth_password; - ld->pcap_h = pcap_open(capture_opts->iface, - capture_opts->has_snaplen ? capture_opts->snaplen : - WTAP_MAX_PACKET_SIZE, - /* flags */ - (capture_opts->promisc_mode ? PCAP_OPENFLAG_PROMISCUOUS : 0) | - (capture_opts->datatx_udp ? PCAP_OPENFLAG_DATATX_UDP : 0) | - (capture_opts->nocap_rpcap ? PCAP_OPENFLAG_NOCAPTURE_RPCAP : 0), - CAP_READ_TIMEOUT, &auth, open_err_str); + ld->pcap_h = pcap_open(capture_opts->iface, + capture_opts->has_snaplen ? capture_opts->snaplen : + WTAP_MAX_PACKET_SIZE, + /* flags */ + (capture_opts->promisc_mode ? PCAP_OPENFLAG_PROMISCUOUS : 0) | + (capture_opts->datatx_udp ? PCAP_OPENFLAG_DATATX_UDP : 0) | + (capture_opts->nocap_rpcap ? PCAP_OPENFLAG_NOCAPTURE_RPCAP : 0), + CAP_READ_TIMEOUT, &auth, open_err_str); + } else +#elif defined(HAVE_PCAP_CREATE) + { + ld->pcap_h = pcap_create(capture_opts->iface, open_err_str); + if (ld->pcap_h != NULL) { + pcap_set_snaplen(ld->pcap_h, capture_opts->has_snaplen ? capture_opts->snaplen : WTAP_MAX_PACKET_SIZE); + pcap_set_promisc(ld->pcap_h, capture_opts->promisc_mode); + pcap_set_timeout(ld->pcap_h, CAP_READ_TIMEOUT); + + if (capture_opts->buffer_size > 1) { + pcap_set_buffer_size(ld->pcap_h, capture_opts->buffer_size * 1024 * 1024); + } + if (pcap_activate(ld->pcap_h) != 0) { + /* Failed to activate, set to NULL */ + pcap_close(ld->pcap_h); + ld->pcap_h = NULL; + } + } + } #else ld->pcap_h = pcap_open_live(capture_opts->iface, capture_opts->has_snaplen ? capture_opts->snaplen : @@ -1499,7 +1519,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, if (capture_opts->buffer_size > 1 && pcap_setbuff(ld->pcap_h, capture_opts->buffer_size * 1024 * 1024) != 0) { sync_secondary_msg_str = g_strdup_printf( - "The capture buffer size of %luMB seems to be too high for your machine,\n" + "The capture buffer size of %dMB seems to be too high for your machine,\n" "the default of 1MB will be used.\n" "\n" "Nonetheless, the capture is started.\n", @@ -1511,7 +1531,8 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, #endif #if defined(HAVE_PCAP_REMOTE) && defined(HAVE_PCAP_SETSAMPLING) - if (capture_opts->sampling_method != CAPTURE_SAMP_NONE) + if ((capture_opts->sampling_method != CAPTURE_SAMP_NONE) && + (strncmp (capture_opts->iface, "rpcap://", 8) == 0)) { struct pcap_samp *samp; @@ -2682,14 +2703,14 @@ main(int argc, char *argv[]) #define OPTSTRING_INIT "a:b:c:Df:hi:LMnpSs:vw:y:Z:" #endif -#ifdef _WIN32 -#define OPTSTRING_WIN32 "B:" +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) +#define OPTSTRING_EXTRA "B:" #else -#define OPTSTRING_WIN32 "" -#endif /* _WIN32 */ +#define OPTSTRING_EXTRA "" +#endif /* _WIN32 or HAVE_PCAP_SET_BUFFER_SIZE */ - char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_WIN32) - 1] = - OPTSTRING_INIT OPTSTRING_WIN32; + char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_EXTRA) - 1] = + OPTSTRING_INIT OPTSTRING_EXTRA; #ifdef DEBUG_CHILD_DUMPCAP if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) { @@ -2956,9 +2977,9 @@ main(int argc, char *argv[]) #ifdef HAVE_PCAP_SETSAMPLING case 'm': /* Sampling */ #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) case 'B': /* Buffer size */ -#endif /* _WIN32 */ +#endif /* _WIN32 or HAVE_PCAP_SET_BUFFER_SIZE */ status = capture_opts_add_opt(&global_capture_opts, opt, optarg, &start_capture); if(status != 0) { exit_main(status); diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index e029fb8efd..d9b4e3bc22 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -85,7 +85,7 @@ #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 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) #define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb" #endif #define E_CAP_SNAP_SB_KEY "cap_snap_sb" @@ -1471,7 +1471,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) int row; int err; gchar *err_str; -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) GtkAdjustment *buffer_size_adj; GtkWidget *buffer_size_lb, *buffer_size_sb, *buffer_size_hb; #endif @@ -1658,7 +1658,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) gtk_container_set_border_width(GTK_CONTAINER(left_vb), 0); gtk_box_pack_start(GTK_BOX(main_hb), left_vb, TRUE, TRUE, 0); -#if defined (HAVE_AIRPCAP) || defined (HAVE_PCAP_REMOTE) || defined (_WIN32) +#if defined (HAVE_AIRPCAP) || defined (HAVE_PCAP_REMOTE) || defined (HAVE_PCAP_SET_BUFFER_SIZE) /* Avoid adding the right vbox if not needed, because it steals 3 pixels */ right_vb = gtk_vbox_new(FALSE, 3); gtk_container_set_border_width(GTK_CONTAINER(right_vb), 0); @@ -1820,7 +1820,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) gtk_widget_show(remote_bt); #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) buffer_size_hb = gtk_hbox_new(FALSE, 3); buffer_size_lb = gtk_label_new("Buffer size:"); gtk_box_pack_start (GTK_BOX(buffer_size_hb), buffer_size_lb, FALSE, FALSE, 0); @@ -2179,7 +2179,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_CB_KEY, snap_cb); g_object_set_data(G_OBJECT(cap_open_w), E_CAP_SNAP_SB_KEY, snap_sb); g_object_set_data(G_OBJECT(cap_open_w), E_CAP_LT_OM_KEY, linktype_om); -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) g_object_set_data(G_OBJECT(cap_open_w), E_CAP_BUFFER_SIZE_SB_KEY, buffer_size_sb); #endif g_object_set_data(G_OBJECT(cap_open_w), E_CAP_PROMISC_KEY, promisc_cb); @@ -2547,7 +2547,7 @@ capture_dlg_prep(gpointer parent_w) { #ifdef HAVE_PCAP_REMOTE GtkWidget *iftype_cbx; #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) GtkWidget *buffer_size_sb; #endif gchar *entry_text; @@ -2566,7 +2566,7 @@ capture_dlg_prep(gpointer parent_w) { snap_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_CB_KEY); snap_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_SNAP_SB_KEY); linktype_om = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_LT_OM_KEY); -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) buffer_size_sb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_BUFFER_SIZE_SB_KEY); #endif promisc_cb = (GtkWidget *) g_object_get_data(G_OBJECT(parent_w), E_CAP_PROMISC_KEY); @@ -2627,7 +2627,7 @@ capture_dlg_prep(gpointer parent_w) { global_capture_opts.src_type = CAPTURE_IFREMOTE; #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) global_capture_opts.buffer_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_sb)); #endif diff --git a/gtk/main.c b/gtk/main.c index 514dbd354e..c72163750f 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1161,7 +1161,7 @@ print_usage(gboolean print_ver) { fprintf(output, " -Q quit Wireshark after capturing\n"); fprintf(output, " -S update packet display when new packets are captured\n"); fprintf(output, " -l turn on automatic scrolling while -S is in use\n"); -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) fprintf(output, " -B size of kernel buffer (def: 1MB)\n"); #endif fprintf(output, " -y link layer type (def: first appropriate)\n"); @@ -2021,14 +2021,14 @@ main(int argc, char *argv[]) #define OPTSTRING_INIT "a:b:c:C:Df:g:Hhi:jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:" -#if defined HAVE_LIBPCAP && defined _WIN32 -#define OPTSTRING_WIN32 "B:" +#if defined HAVE_LIBPCAP && defined HAVE_PCAP_SET_BUFFER_SIZE +#define OPTSTRING_EXTRA "B:" #else -#define OPTSTRING_WIN32 "" +#define OPTSTRING_EXTRA "" #endif - char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_WIN32) - 1] = - OPTSTRING_INIT OPTSTRING_WIN32; + char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_EXTRA) - 1] = + OPTSTRING_INIT OPTSTRING_EXTRA; /* * Get credential information for later use, and drop privileges @@ -2393,9 +2393,9 @@ main(int argc, char *argv[]) case 'S': /* "Sync" mode: used for following file ala tail -f */ case 'w': /* Write to capture file xxx */ case 'y': /* Set the pcap data link type */ -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) case 'B': /* Buffer size */ -#endif /* _WIN32 */ +#endif /* _WIN32 or HAVE_PCAP_SET_BUFFER_SIZE */ #ifdef HAVE_LIBPCAP status = capture_opts_add_opt(&global_capture_opts, opt, optarg, &start_capture); diff --git a/tshark.c b/tshark.c index 2350cca994..6015f9c55f 100644 --- a/tshark.c +++ b/tshark.c @@ -232,7 +232,7 @@ print_usage(gboolean print_ver) fprintf(output, " -f packet filter in libpcap filter syntax\n"); fprintf(output, " -s packet snapshot length (def: 65535)\n"); fprintf(output, " -p don't capture in promiscuous mode\n"); -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) fprintf(output, " -B size of kernel buffer (def: 1MB)\n"); #endif fprintf(output, " -y link layer type (def: first appropriate)\n"); @@ -769,16 +769,16 @@ main(int argc, char *argv[]) #define OPTSTRING_INIT "a:b:c:C:d:De:E:f:F:G:hi:K:lLnN:o:pPqr:R:s:St:T:u:vVw:xX:y:z:" #ifdef HAVE_LIBPCAP -#ifdef _WIN32 -#define OPTSTRING_WIN32 "B:" +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) +#define OPTSTRING_EXTRA "B:" #else -#define OPTSTRING_WIN32 "" -#endif /* _WIN32 */ +#define OPTSTRING_EXTRA "" +#endif /* _WIN32 or HAVE_PCAP_SET_BUFFER_SIZE */ #else -#define OPTSTRING_WIN32 "" +#define OPTSTRING_EXTRA "" #endif /* HAVE_LIBPCAP */ - static const char optstring[] = OPTSTRING_INIT OPTSTRING_WIN32; + static const char optstring[] = OPTSTRING_INIT OPTSTRING_EXTRA; /* * Get credential information for later use. @@ -1003,9 +1003,9 @@ main(int argc, char *argv[]) case 's': /* Set the snapshot (capture) length */ case 'w': /* Write to capture file x */ case 'y': /* Set the pcap data link type */ -#ifdef _WIN32 +#if defined(_WIN32) || defined(HAVE_PCAP_SET_BUFFER_SIZE) case 'B': /* Buffer size */ -#endif /* _WIN32 */ +#endif /* _WIN32 or HAVE_PCAP_SET_BUFFER_SIZE */ #ifdef HAVE_LIBPCAP status = capture_opts_add_opt(&global_capture_opts, opt, optarg, &start_capture); if(status != 0) {