#include "caputils/ws80211_utils.h"
+#ifdef HAVE_EXTCAP
+#include "extcap.h"
+#endif
+
/*
* Get information about libpcap format from "wiretap/libpcap.h".
* XXX - can we just use pcap_open_offline() to read the pipe?
*open_err_str);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
"pcap_open_live() returned %p.", (void *)pcap_h);
+
+/* Windows doesn't have pcap_create() yet */
+#ifdef _WIN32
+ /* try to set the capture buffer size -- but not for remote devices */
+ if (pcap_h && interface_opts->buffer_size > 1 &&
+ pcap_setbuff(pcap_h, interface_opts->buffer_size * 1024 * 1024) != 0) {
+ gchar *sync_secondary_msg_str;
+
+ sync_secondary_msg_str = g_strdup_printf(
+ "Unable to set a capture buffer size of %d MiB.\n"
+ "Capturing using the default size of %d MiB instead.",
+ interface_opts->buffer_size, DEFAULT_CAPTURE_BUFFER_SIZE);
+ report_capture_error("Couldn't set the capture buffer size.",
+ sync_secondary_msg_str);
+ g_free(sync_secondary_msg_str);
+ }
+#endif
#endif
}
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "open_capture_device %s : %s", pcap_h ? "SUCCESS" : "FAILURE", interface_opts->name);
return data_link_info;
}
-#ifdef HAVE_BONDING
-gboolean
+#if defined(HAVE_BONDING) && defined(HAVE_PCAP_CREATE)
+static gboolean
is_linux_bonding_device(const char *ifname)
{
int fd;
close(fd);
return FALSE;
}
-#else
+#elif defined(HAVE_PCAP_CREATE)
static gboolean
is_linux_bonding_device(const char *ifname _U_)
{
* Get the capabilities of a network device.
*/
static if_capabilities_t *
-get_if_capabilities(const char *devicename, gboolean monitor_mode
-#ifndef HAVE_PCAP_CREATE
- _U_
-#endif
-, char **err_str)
+get_if_capabilities(interface_options *interface_opts, char **err_str)
{
if_capabilities_t *caps;
char errbuf[PCAP_ERRBUF_SIZE];
*/
errbuf[0] = '\0';
#ifdef HAVE_PCAP_OPEN
- pch = pcap_open(devicename, MIN_PACKET_SIZE, 0, 0, NULL, errbuf);
+#ifdef HAVE_PCAP_REMOTE
+ if (strncmp (interface_opts->name, "rpcap://", 8) == 0) {
+ struct pcap_rmtauth auth;
+
+ auth.type = interface_opts->auth_type == CAPTURE_AUTH_PWD ?
+ RPCAP_RMTAUTH_PWD : RPCAP_RMTAUTH_NULL;
+ auth.username = interface_opts->auth_username;
+ auth.password = interface_opts->auth_password;
+
+ pch = pcap_open(interface_opts->name, MIN_PACKET_SIZE, 0, 0, &auth, errbuf);
+ } else
+#endif
+ pch = pcap_open(interface_opts->name, MIN_PACKET_SIZE, 0, 0, NULL, errbuf);
caps->can_set_rfmon = FALSE;
if (pch == NULL) {
if (err_str != NULL)
return NULL;
}
#elif defined(HAVE_PCAP_CREATE)
- pch = pcap_create(devicename, errbuf);
+ pch = pcap_create(interface_opts->name, errbuf);
if (pch == NULL) {
if (err_str != NULL)
*err_str = g_strdup(errbuf);
g_free(caps);
return NULL;
}
- if (is_linux_bonding_device(devicename)) {
+ if (is_linux_bonding_device(interface_opts->name)) {
/*
* Linux bonding device; not Wi-Fi, so no monitor mode, and
* calling pcap_can_set_rfmon() might get a "no such device"
caps->can_set_rfmon = FALSE;
else if (status == 1) {
caps->can_set_rfmon = TRUE;
- if (monitor_mode)
+ if (interface_opts->monitor_mode)
pcap_set_rfmon(pch, 1);
} else {
if (err_str != NULL) {
return NULL;
}
#else
- pch = pcap_open_live(devicename, MIN_PACKET_SIZE, 0, 0, errbuf);
+ pch = pcap_open_live(interface_opts->name, MIN_PACKET_SIZE, 0, 0, errbuf);
caps->can_set_rfmon = FALSE;
if (pch == NULL) {
if (err_str != NULL)
return NULL;
}
#endif
- deflt = get_pcap_linktype(pch, devicename);
+ deflt = get_pcap_linktype(pch, interface_opts->name);
#ifdef HAVE_PCAP_LIST_DATALINKS
nlt = pcap_list_datalinks(pch, &linktypes);
if (nlt == 0 || linktypes == NULL) {
char *pncopy, *pos;
wchar_t *err_str;
interface_options interface_opts;
+#ifdef HAVE_EXTCAP
+ char* extcap_pipe_name;
+ gboolean extcap_pipe;
+#endif
#endif
ssize_t b;
int fd = -1, sel_ret;
#ifdef _WIN32
pcap_opts->cap_pipe_h = INVALID_HANDLE_VALUE;
#endif
+
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "cap_pipe_open_live: %s", pipename);
/*
}
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
+#ifdef HAVE_EXTCAP
+ extcap_pipe_name = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, NULL);
+ extcap_pipe = strstr(interface_opts.name, extcap_pipe_name) ? TRUE : FALSE;
+ g_free(extcap_pipe_name);
+#endif
/* Wait for the pipe to appear */
while (1) {
- if(strncmp(interface_opts.name,"\\\\.\\pipe\\",9)== 0)
+#ifdef HAVE_EXTCAP
+ if(extcap_pipe)
pcap_opts->cap_pipe_h = GetStdHandle(STD_INPUT_HANDLE);
else
+#endif
pcap_opts->cap_pipe_h = CreateFile(utf_8to16(pipename), GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, NULL);
guint i;
#ifdef _WIN32
int err;
- gchar *sync_secondary_msg_str;
WORD wVersionRequested;
WSADATA wsaData;
#endif
/* XXX - opening Winsock on tshark? */
- /* Initialize Windows Socket if we are in a WIN32 OS
+ /* Initialize Windows Socket if we are in a Win32 OS
This needs to be done before querying the interface for network/netmask */
#ifdef _WIN32
/* XXX - do we really require 1.1 or earlier?
pcap_opts->ts_nsec = have_high_resolution_timestamp(pcap_opts->pcap_h);
#endif
-#ifdef _WIN32
- /* try to set the capture buffer size */
- if (interface_opts.buffer_size > 1 &&
- pcap_setbuff(pcap_opts->pcap_h, interface_opts.buffer_size * 1024 * 1024) != 0) {
- sync_secondary_msg_str = g_strdup_printf(
- "The capture buffer size of %d MiB seems to be too high for your machine,\n"
- "the default of %d MiB will be used.\n"
- "\n"
- "Nonetheless, the capture is started.\n",
- interface_opts.buffer_size, DEFAULT_CAPTURE_BUFFER_SIZE);
- report_capture_error("Couldn't set the capture buffer size.",
- sync_secondary_msg_str);
- g_free(sync_secondary_msg_str);
- }
-#endif
-
#if defined(HAVE_PCAP_SETSAMPLING)
if (interface_opts.sampling_method != CAPTURE_SAMP_NONE) {
struct pcap_samp *samp;
if (capture_opts->multi_files_on) {
if (cnd_autostop_files != NULL &&
- cnd_eval(cnd_autostop_files, ++global_ld.autostop_files)) {
+ cnd_eval(cnd_autostop_files, (guint64)++global_ld.autostop_files)) {
/* no files left: stop here */
global_ld.go = FALSE;
return FALSE;
static gboolean
capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats)
{
-#ifdef WIN32
+#ifdef _WIN32
DWORD upd_time, cur_time; /* GetTickCount() returns a "DWORD" (which is 'unsigned long') */
#else
struct timeval upd_time, cur_time;
if (capture_opts->has_autostop_files)
cnd_autostop_files =
- cnd_new(CND_CLASS_CAPTURESIZE, capture_opts->autostop_files);
+ cnd_new(CND_CLASS_CAPTURESIZE, (guint64)capture_opts->autostop_files);
}
/* init the time values */
-#ifdef WIN32
+#ifdef _WIN32
upd_time = GetTickCount();
#else
gettimeofday(&upd_time, NULL);
*/
#define DUMPCAP_UPD_TIME 500
-#ifdef WIN32
+#ifdef _WIN32
cur_time = GetTickCount(); /* Note: wraps to 0 if sys runs for 49.7 days */
if ((cur_time - upd_time) > DUMPCAP_UPD_TIME) { /* wrap just causes an extra update */
#else
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, ii);
- caps = get_if_capabilities(interface_opts.name,
- interface_opts.monitor_mode, &err_str);
+ caps = get_if_capabilities(&interface_opts, &err_str);
if (caps == NULL) {
cmdarg_err("The capabilities of the capture device \"%s\" could not be obtained (%s).\n"
"Please check to make sure you have sufficient permissions, and that\n"