Show the Experimental-Result-Code if we don't know have a subdissector for that
[metze/wireshark/wip.git] / dumpcap.c
index 892e46c2a02e9927147b7a522d142d6320e785a4..06b76c41ca00f80932a0e6a4e4f4be002f167e67 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
 
 #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?
@@ -783,6 +787,23 @@ open_capture_device(capture_options *capture_opts
                                 *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);
@@ -1150,8 +1171,8 @@ create_data_link_info(int dlt)
     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;
@@ -1181,7 +1202,7 @@ is_linux_bonding_device(const char *ifname)
     close(fd);
     return FALSE;
 }
-#else
+#elif defined(HAVE_PCAP_CREATE)
 static gboolean
 is_linux_bonding_device(const char *ifname _U_)
 {
@@ -1193,11 +1214,7 @@ 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];
@@ -1233,7 +1250,19 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
      */
     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)
@@ -1242,14 +1271,14 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         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"
@@ -1277,7 +1306,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         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) {
@@ -1304,7 +1333,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         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)
@@ -1313,7 +1342,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         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) {
@@ -2045,6 +2074,10 @@ cap_pipe_open_live(char *pipename,
     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;
@@ -2054,6 +2087,7 @@ cap_pipe_open_live(char *pipename,
 #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);
 
     /*
@@ -2181,13 +2215,20 @@ cap_pipe_open_live(char *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);
 
@@ -2619,14 +2660,13 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
     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?
@@ -2739,22 +2779,6 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
             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;
@@ -3442,7 +3466,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
 
     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;
@@ -3550,7 +3574,7 @@ pcap_read_handler(void* arg)
 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;
@@ -3682,11 +3706,11 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
 
         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);
@@ -3788,7 +3812,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
          */
 #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
@@ -4946,8 +4970,7 @@ DIAG_ON(cast-qual)
 
             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"