From Francesco Fondelli:
[obnox/wireshark/wip.git] / dumpcap.c
index c1176574dbd550a0b714f268b500e1a1e5721c6c..f6268c7c668b43de9f1371eace979ea2fa226232 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -2518,7 +2518,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
                 }
                 successful = libpcap_write_interface_description_block(ld->pdh,
                                                                        interface_opts.name,
-                                                                       interface_opts.cfilter,
+                                                                       interface_opts.cfilter?interface_opts.cfilter:"",
                                                                        pcap_opts->linktype,
                                                                        pcap_opts->snaplen,
                                                                        &ld->bytes_written,
@@ -2947,7 +2947,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
                     pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
                     successful = libpcap_write_interface_description_block(global_ld.pdh,
                                                                            interface_opts.name,
-                                                                           interface_opts.cfilter,
+                                                                           interface_opts.cfilter?interface_opts.cfilter:"",
                                                                            pcap_opts->linktype,
                                                                            pcap_opts->snaplen,
                                                                            &(global_ld.bytes_written),
@@ -3068,9 +3068,14 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
         pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
         interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
         /* init the input filter from the network interface (capture pipe will do nothing) */
+        /*
+         * When remote capturing WinPCap crashes when the capture filter
+         * is NULL. This might be a bug in WPCap. Therefore we provide an emtpy
+         * string.
+         */
         switch (capture_loop_init_filter(pcap_opts->pcap_h, pcap_opts->from_cap_pipe,
                                          interface_opts.name,
-                                         interface_opts.cfilter)) {
+                                         interface_opts.cfilter?interface_opts.cfilter:"")) {
 
         case INITFILTER_NO_ERROR:
             break;
@@ -4065,28 +4070,29 @@ main(int argc, char *argv[])
             machine_readable = TRUE;
             break;
         default:
-        case '?':        /* Bad flag - print usage message */
             cmdarg_err("Invalid Option: %s", argv[optind-1]);
+        case '?':        /* Bad flag - print usage message */
             arg_error = TRUE;
             break;
         }
     }
-    argc -= optind;
-    argv += optind;
-    if (argc >= 1) {
-        /* user specified file name as regular command-line argument */
-        /* XXX - use it as the capture file name (or something else)? */
-        argc--;
-        argv++;
-    }
-
-    if (argc != 0) {
-        /*
-         * Extra command line arguments were specified; complain.
-         * XXX - interpret as capture filter, as tcpdump and tshark do?
-         */
-        cmdarg_err("Invalid argument: %s", argv[0]);
-        arg_error = TRUE;
+    if (!arg_error) {
+        argc -= optind;
+        argv += optind;
+        if (argc >= 1) {
+            /* user specified file name as regular command-line argument */
+            /* XXX - use it as the capture file name (or something else)? */
+            argc--;
+            argv++;
+        }
+        if (argc != 0) {
+            /*
+             * Extra command line arguments were specified; complain.
+             * XXX - interpret as capture filter, as tcpdump and tshark do?
+             */
+            cmdarg_err("Invalid argument: %s", argv[0]);
+            arg_error = TRUE;
+        }
     }
 
     if (arg_error) {