Fetch an indication of whether the interface supports capturing in
[obnox/wireshark/wip.git] / capture_sync.c
index aa6c8c987c9e362417114d5af737ef61550fc813..f412c4e51af9ab727a49023a1033184ca2305577 100644 (file)
@@ -44,7 +44,7 @@
 #include <signal.h>
 
 #ifdef _WIN32
-#include "epan/unicode-utils.h"
+#include <wsutil/unicode-utils.h>
 #endif
 
 #ifdef HAVE_SYS_WAIT_H
 #include "globals.h"
 #include "file.h"
 #include <epan/filesystem.h>
+#include <epan/report_err.h>
 
 #include "capture.h"
 #include "capture_sync.h"
-#include "simple_dialog.h"
 
 #include "sync_pipe.h"
 
@@ -98,7 +98,7 @@
 #include "capture-wpcap.h"
 #endif
 #include "ui_util.h"
-#include "file_util.h"
+#include <wsutil/file_util.h>
 #include "log.h"
 
 #ifdef _WIN32
@@ -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_CREATE)
     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) */
@@ -288,10 +290,10 @@ sync_pipe_start(capture_options *capture_opts) {
     argv = init_pipe_args(&argc);
     if (!argv) {
         /* We don't know where to find dumpcap. */
-        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "We don't know where to find dumpcap.");
+        report_failure("We don't know where to find dumpcap.");
         return FALSE;
     }
-    
+
     g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "argv[0]: %s", argv[0]);
 
     argv = sync_pipe_add_arg(argv, &argc, "-i");
@@ -305,12 +307,7 @@ sync_pipe_start(capture_options *capture_opts) {
 
     if (capture_opts->linktype != -1) {
       argv = sync_pipe_add_arg(argv, &argc, "-y");
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
       g_snprintf(sdlt, ARGV_NUMBER_LEN, "%s",linktype_val_to_name(capture_opts->linktype));
-#else
-      /* we can't get the type name, just treat it as a number */
-      g_snprintf(sdlt, ARGV_NUMBER_LEN, "%d",capture_opts->linktype);
-#endif
       argv = sync_pipe_add_arg(argv, &argc, sdlt);
     }
 
@@ -360,6 +357,12 @@ sync_pipe_start(capture_options *capture_opts) {
 
     if (!capture_opts->promisc_mode)
       argv = sync_pipe_add_arg(argv, &argc, "-p");
+#ifdef HAVE_PCAP_CREATE
+    if (capture_opts->monitor_mode)
+      argv = sync_pipe_add_arg(argv, &argc, "-I");
+#endif
+    if (capture_opts->use_pcapng)
+      argv = sync_pipe_add_arg(argv, &argc, "-n");
 #ifdef HAVE_PCAP_REMOTE
     if (capture_opts->datatx_udp)
       argv = sync_pipe_add_arg(argv, &argc, "-u");
@@ -399,8 +402,14 @@ sync_pipe_start(capture_options *capture_opts) {
 #endif
 #endif
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
     argv = sync_pipe_add_arg(argv, &argc, "-B");
+#ifdef HAVE_PCAP_REMOTE
+    if (capture_opts->src_type == CAPTURE_IFREMOTE)
+      /* No buffer size when using remote interfaces */
+      g_snprintf(buffer_size, ARGV_NUMBER_LEN, "%d", 1);
+    else
+#endif
     g_snprintf(buffer_size, ARGV_NUMBER_LEN, "%d",capture_opts->buffer_size);
     argv = sync_pipe_add_arg(argv, &argc, buffer_size);
 #endif
@@ -425,8 +434,7 @@ sync_pipe_start(capture_options *capture_opts) {
     /* (increase this value if you have trouble while fast capture file switches) */
     if (! CreatePipe(&sync_pipe_read, &sync_pipe_write, &sa, 5120)) {
       /* Couldn't create the pipe between parent and child. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't create sync pipe: %s",
-                        strerror(errno));
+      report_failure("Couldn't create sync pipe: %s", strerror(errno));
       g_free( (gpointer) argv[0]);
       g_free( (gpointer) argv);
       return FALSE;
@@ -440,8 +448,7 @@ sync_pipe_start(capture_options *capture_opts) {
 
     if (signal_pipe == INVALID_HANDLE_VALUE) {
       /* Couldn't create the signal pipe between parent and child. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't create signal pipe: %s",
-                        strerror(errno));
+      report_failure("Couldn't create signal pipe: %s", strerror(errno));
       g_free( (gpointer) argv[0]);
       g_free( (gpointer) argv);
       return FALSE;
@@ -475,9 +482,8 @@ sync_pipe_start(capture_options *capture_opts) {
     /* call dumpcap */
     if(!CreateProcess(NULL, utf_8to16(args->str), NULL, NULL, TRUE,
                       CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                    "Couldn't run %s in child process: error %u",
-                    args->str, GetLastError());
+      report_failure("Couldn't run %s in child process: error %u",
+                     args->str, GetLastError());
       CloseHandle(sync_pipe_read);
       CloseHandle(sync_pipe_write);
       g_free( (gpointer) argv[0]);
@@ -497,8 +503,7 @@ sync_pipe_start(capture_options *capture_opts) {
 #else /* _WIN32 */
     if (pipe(sync_pipe) < 0) {
       /* Couldn't create the pipe between parent and child. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't create sync pipe: %s",
-                       strerror(errno));
+      report_failure("Couldn't create sync pipe: %s", strerror(errno));
       g_free( (gpointer) argv[0]);
       g_free(argv);
       return FALSE;
@@ -510,7 +515,7 @@ sync_pipe_start(capture_options *capture_opts) {
        * it just capture with the specified capture parameters
        */
       dup2(sync_pipe[PIPE_WRITE], 2);
-      eth_close(sync_pipe[PIPE_READ]);
+      ws_close(sync_pipe[PIPE_READ]);
       execv(argv[0], (gpointer)argv);
       g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
                argv[0], strerror(errno));
@@ -542,16 +547,15 @@ sync_pipe_start(capture_options *capture_opts) {
 #ifdef _WIN32
     CloseHandle(sync_pipe_write);
 #else
-    eth_close(sync_pipe[PIPE_WRITE]);
+    ws_close(sync_pipe[PIPE_WRITE]);
 #endif
 
     if (capture_opts->fork_child == -1) {
       /* We couldn't even create the child process. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                       "Couldn't create child process: %s", strerror(errno));
-      eth_close(sync_pipe_read_fd);
+      report_failure("Couldn't create child process: %s", strerror(errno));
+      ws_close(sync_pipe_read_fd);
 #ifdef _WIN32
-      eth_close(capture_opts->signal_pipe_write_fd);
+      ws_close(capture_opts->signal_pipe_write_fd);
 #endif
       return FALSE;
     }
@@ -572,12 +576,11 @@ sync_pipe_start(capture_options *capture_opts) {
 }
 
 /*
- * Open dumpcap with the supplied arguments.  On success, msg points to
- * a buffer containing the dumpcap output and returns 0.  read_fd and
- * fork_child point to the pipe's file descriptor and child PID/handle,
- * respectively.  On failure, msg points to the error message returned by
- * dumpcap, and returns dumpcap's exit value.  In either case, msg must be
- * freed with g_free().
+ * Open a pipe to dumpcap with the supplied arguments.  On success, *msg
+ * is unchanged and 0 is returned; read_fd and fork_child point to the
+ * pipe's file descriptor and child PID/handle, respectively.  On failure,
+ * *msg points to an error message for the failure, and -1 is returned.
+ * In the latter case, *msg must be freed with g_free().
  */
 /* XXX - This duplicates a lot of code in sync_pipe_start() */
 #define PIPE_BUF_SIZE 5120
@@ -617,13 +620,13 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
     sa.lpSecurityDescriptor = NULL;
 
     /* Create a pipe for the child process */
-    /* (inrease this value if you have trouble while fast capture file switches) */
+    /* (increase this value if you have trouble while fast capture file switches) */
     if (! CreatePipe(&sync_pipe_read, &sync_pipe_write, &sa, 5120)) {
         /* Couldn't create the pipe between parent and child. */
         *msg = g_strdup_printf("Couldn't create sync pipe: %s", strerror(errno));
         g_free( (gpointer) argv[0]);
         g_free( (gpointer) argv);
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 
     /* init STARTUPINFO */
@@ -660,7 +663,7 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
         CloseHandle(sync_pipe_write);
         g_free( (gpointer) argv[0]);
         g_free( (gpointer) argv);
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
     *fork_child = (int) pi.hProcess;
     g_string_free(args, TRUE);
@@ -675,7 +678,7 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
         *msg = g_strdup_printf("Couldn't create sync pipe: %s", strerror(errno));
         g_free( (gpointer) argv[0]);
         g_free(argv);
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 
     if ((*fork_child = fork()) == 0) {
@@ -684,7 +687,7 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
          * it just capture with the specified capture parameters
          */
         dup2(sync_pipe[PIPE_WRITE], 1);
-        eth_close(sync_pipe[PIPE_READ]);
+        ws_close(sync_pipe[PIPE_READ]);
         execv(argv[0], (gpointer)argv);
         g_snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
                   argv[0], strerror(errno));
@@ -716,14 +719,14 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
 #ifdef _WIN32
     CloseHandle(sync_pipe_write);
 #else
-    eth_close(sync_pipe[PIPE_WRITE]);
+    ws_close(sync_pipe[PIPE_WRITE]);
 #endif
 
     if (*fork_child == -1) {
         /* We couldn't even create the child process. */
         *msg = g_strdup_printf("Couldn't create child process: %s", strerror(errno));
-        eth_close(*read_fd);
-        return CANT_RUN_DUMPCAP;
+        ws_close(*read_fd);
+        return -1;
     }
 
     /* we might wait for a moment till child is ready, so update screen now */
@@ -731,6 +734,12 @@ sync_pipe_open_command(const char** argv, int *read_fd, int *fork_child, gchar *
     return 0;
 }
 
+/*
+ * Wait for dumpcap to finish.  On success, *msg is unchanged, and 0 is
+ * returned.  On failure, *msg points to an error message for the
+ * failure, and -1 is returned.  In the latter case, *msg must be
+ * freed with g_free().
+ */
 static int
 #ifdef _WIN32
 sync_pipe_close_command(int *read_fd, int *fork_child, gchar **msg) {
@@ -739,7 +748,7 @@ sync_pipe_close_command(int *read_fd, gchar **msg) {
 #endif
     int fork_child_status;
 
-    eth_close(*read_fd);
+    ws_close(*read_fd);
 
     g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_close_command: wait till child closed");
 
@@ -749,7 +758,7 @@ sync_pipe_close_command(int *read_fd, gchar **msg) {
     if (_cwait(&fork_child_status, *fork_child, _WAIT_CHILD) == -1) {
         *msg = g_strdup_printf("Child capture process stopped unexpectedly "
             "(errno:%u)", errno);
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 #else
     if (wait(&fork_child_status) != -1) {
@@ -772,22 +781,25 @@ sync_pipe_close_command(int *read_fd, gchar **msg) {
                 *msg = g_strdup_printf("Child capture process died: wait status %#o",
                     fork_child_status);
             }
-            return CANT_RUN_DUMPCAP;
+            return -1;
         }
     } else {
       *msg = g_strdup_printf("Child capture process stopped unexpectedly "
         "(errno:%u)", errno);
-      return CANT_RUN_DUMPCAP;
+      return -1;
     }
 #endif
     return 0;
 }
 
 /*
- * Run dumpcap with the supplied arguments.  On success, msg points to
- * a buffer containing the dumpcap output and returns 0.  On failure, msg
- * points to the error message returned by dumpcap, and returns dumpcap's
- * exit value.  In either case, msg must be freed with g_free().
+ * Run dumpcap with the supplied arguments.  On success, *msg points to
+ * a buffer containing the dumpcap output, and 0 is returned.  On failure,
+ * *msg points to an error message, and -1 is returned.  In either case,
+ * *msg must be freed with g_free().
+ *
+ * XXX - this doesn't check the exit status of dumpcap if it can be
+ * started and its return status could be fetched.
  */
 /* XXX - This duplicates a lot of code in sync_pipe_start() */
 #define PIPE_BUF_SIZE 5120
@@ -803,10 +815,9 @@ sync_pipe_run_command(const char** argv, gchar **msg) {
     if (ret)
        return ret;
 
-    /* We were able to set up to read dumpcap's output.  Do so and
-       return its exit value. */
+    /* We were able to set up to read dumpcap's output.  Do so. */
     msg_buf = g_string_new("");
-    while ((count = eth_read(sync_pipe_read_fd, buf, PIPE_BUF_SIZE)) > 0) {
+    while ((count = ws_read(sync_pipe_read_fd, buf, PIPE_BUF_SIZE)) > 0) {
         buf[count] = '\0';
         g_string_append(msg_buf, buf);
     }
@@ -828,10 +839,10 @@ sync_pipe_run_command(const char** argv, gchar **msg) {
 }
 
 /*
- * Get an interface list using dumpcap.  On success, msg points to
- * a buffer containing the dumpcap output and returns 0.  On failure, msg
- * points to the error message returned by dumpcap, and returns dumpcap's
- * exit value.  In either case, msg must be freed with g_free().
+ * Get an interface list using dumpcap.  On success, *msg points to
+ * a buffer containing the dumpcap output, and 0 is returned.  On failure,
+ * *msg points to an error message, and -1 is returned.  In either case,
+ * msg must be freed with g_free().
  */
 int
 sync_interface_list_open(gchar **msg) {
@@ -849,7 +860,7 @@ sync_interface_list_open(gchar **msg) {
 
     if (!argv) {
         *msg = g_strdup_printf("We don't know where to find dumpcap.");
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 
     /* Ask for the interface list */
@@ -867,7 +878,7 @@ sync_interface_list_open(gchar **msg) {
     /*           currently be sent as is to stderr resulting in garbled output.           */
     /*     ToDo: Revise this code to be similar to sync_pipe_start so that 'dumpcap -Z'   */
     /*     special format error messages to stderr are captured and returned to caller    */
-    /*     (eg: so can be processed and displayed in a pop-up box).                       */ 
+    /*     (eg: so can be processed and displayed in a pop-up box).                       */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
     argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
@@ -878,13 +889,15 @@ sync_interface_list_open(gchar **msg) {
 }
 
 /*
- * Get an linktype list using dumpcap.  On success, msg points to
- * a buffer containing the dumpcap output and returns 0.  On failure, msg
- * points to the error message returned by dumpcap, and returns dumpcap's
- * exit value.  In either case, msg must be freed with g_free().
+ * Get interface capabilities using dumpcap.  On success, *msg points to
+ * a buffer containing the dumpcap output, and 0 is returned.  On failure,
+ * *msg points to an error message, and -1 is returned.  In either case,
+ * *msg must be freed with g_free().
  */
 int
-sync_linktype_list_open(const gchar *ifname, gchar **msg) {
+sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
+                          gchar **msg)
+{
     int argc;
     const char **argv;
 
@@ -899,13 +912,15 @@ sync_linktype_list_open(const gchar *ifname, gchar **msg) {
 
     if (!argv) {
         *msg = g_strdup_printf("We don't know where to find dumpcap.");
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 
-    /* Ask for the linktype list */
+    /* Ask for the interface capabilities */
     argv = sync_pipe_add_arg(argv, &argc, "-i");
     argv = sync_pipe_add_arg(argv, &argc, ifname);
     argv = sync_pipe_add_arg(argv, &argc, "-L");
+    if (monitor_mode)
+        argv = sync_pipe_add_arg(argv, &argc, "-I");
     argv = sync_pipe_add_arg(argv, &argc, "-M");
 
 #if 0
@@ -919,7 +934,7 @@ sync_linktype_list_open(const gchar *ifname, gchar **msg) {
     /*           currently be sent as is to stderr resulting in garbled output.           */
     /*     ToDo: Revise this code to be similar to sync_pipe_start so that 'dumpcap -Z'   */
     /*     special format error messages to stderr are captured and returned to caller    */
-    /*     (eg: so can be processed and displayed in a pop-up box).                       */ 
+    /*     (eg: so can be processed and displayed in a pop-up box).                       */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
     argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
@@ -930,9 +945,9 @@ sync_linktype_list_open(const gchar *ifname, gchar **msg) {
 
 /*
  * Start getting interface statistics using dumpcap.  On success, read_fd
- * contains the file descriptor for the pipe's stdout, msg is unchanged,
- * and zero is returned.  On failure, msg will point to an error message
- * that must be g_free()d and a nonzero error value will be returned.
+ * contains the file descriptor for the pipe's stdout, *msg is unchanged,
+ * and zero is returned.  On failure, *msg will point to an error message
+ * that must be g_free()d, and -1 will be returned.
  */
 int
 sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg) {
@@ -950,7 +965,7 @@ sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg) {
 
     if (!argv) {
         *msg = g_strdup_printf("We don't know where to find dumpcap.");
-        return CANT_RUN_DUMPCAP;
+        return -1;
     }
 
     /* Ask for the interface statistics */
@@ -968,7 +983,7 @@ sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg) {
     /*           currently be sent as is to stderr resulting in garbled output.           */
     /*     ToDo: Revise this code to be similar to sync_pipe_start so that 'dumpcap -Z'   */
     /*     special format error messages to stderr are captured and returned to caller    */
-    /*     (eg: so can be processed and displayed in a pop-up box).                       */ 
+    /*     (eg: so can be processed and displayed in a pop-up box).                       */
 #ifndef DEBUG_CHILD
     argv = sync_pipe_add_arg(argv, &argc, "-Z");
     argv = sync_pipe_add_arg(argv, &argc, SIGNAL_PIPE_CTRL_ID_NONE);
@@ -994,22 +1009,22 @@ _U_
 /* read a number of bytes from a pipe */
 /* (blocks until enough bytes read or an error occurs) */
 static int
-pipe_read_bytes(int pipe, char *bytes, int required) {
+pipe_read_bytes(int pipe_fd, char *bytes, int required) {
     int newly;
     int offset = 0;
 
     while(required) {
-        newly = read(pipe, &bytes[offset], required);
+        newly = read(pipe_fd, &bytes[offset], required);
         if (newly == 0) {
             /* EOF */
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-                  "read from pipe %d: EOF (capture closed?)", pipe);
+                  "read from pipe %d: EOF (capture closed?)", pipe_fd);
             return offset;
         }
         if (newly < 0) {
             /* error */
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-                  "read from pipe %d: error(%u): %s", pipe, errno, strerror(errno));
+                  "read from pipe %d: error(%u): %s", pipe_fd, errno, strerror(errno));
             return newly;
         }
 
@@ -1020,9 +1035,9 @@ pipe_read_bytes(int pipe, char *bytes, int required) {
     return offset;
 }
 
-static gboolean pipe_data_available(int pipe) {
+static gboolean pipe_data_available(int pipe_fd) {
 #ifdef _WIN32 /* PeekNamedPipe */
-    HANDLE hPipe = (HANDLE) _get_osfhandle(pipe);
+    HANDLE hPipe = (HANDLE) _get_osfhandle(pipe_fd);
     DWORD bytes_avail;
 
     if (hPipe == INVALID_HANDLE_VALUE)
@@ -1039,11 +1054,11 @@ static gboolean pipe_data_available(int pipe) {
     struct timeval timeout;
 
     FD_ZERO(&rfds);
-    FD_SET(pipe, &rfds);
+    FD_SET(pipe_fd, &rfds);
     timeout.tv_sec = 0;
     timeout.tv_usec = 0;
 
-    if (select(pipe+1, &rfds, NULL, NULL, &timeout) > 0)
+    if (select(pipe_fd+1, &rfds, NULL, NULL, &timeout) > 0)
         return TRUE;
 
     return FALSE;
@@ -1052,22 +1067,22 @@ static gboolean pipe_data_available(int pipe) {
 
 /* Read a line from a pipe, similar to fgets */
 int
-sync_pipe_gets_nonblock(int pipe, char *bytes, int max) {
+sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
     int newly;
     int offset = -1;
 
     while(offset < max - 1) {
         offset++;
-        if (! pipe_data_available(pipe))
+        if (! pipe_data_available(pipe_fd))
             break;
-        newly = read(pipe, &bytes[offset], 1);
+        newly = read(pipe_fd, &bytes[offset], 1);
         if (newly == 0) {
             /* EOF - not necessarily an error */
             break;
         } else if (newly < 0) {
             /* error */
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-                  "read from pipe %d: error(%u): %s", pipe, errno, strerror(errno));
+                  "read from pipe %d: error(%u): %s", pipe_fd, errno, strerror(errno));
             return newly;
         } else if (bytes[offset] == '\n') {
             break;
@@ -1096,17 +1111,17 @@ pipe_convert_header(const guchar *header, int header_len, char *indicator, int *
    (1-byte message indicator, 3-byte message length (excluding length
    and indicator field), and the rest is the message) */
 static int
-pipe_read_block(int pipe, char *indicator, int len, char *msg) {
+pipe_read_block(int pipe_fd, char *indicator, int len, char *msg) {
     int required;
     int newly;
     guchar header[4];
 
 
     /* read header (indicator and 3-byte length) */
-    newly = pipe_read_bytes(pipe, header, 4);
+    newly = pipe_read_bytes(pipe_fd, header, 4);
     if(newly != 4) {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-              "read %d failed to read header: %u", pipe, newly);
+              "read %d failed to read header: %u", pipe_fd, newly);
         return -1;
     }
 
@@ -1116,7 +1131,7 @@ pipe_read_block(int pipe, char *indicator, int len, char *msg) {
     /* only indicator with no value? */
     if(required == 0) {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-              "read %d indicator: %c empty value", pipe, *indicator);
+              "read %d indicator: %c empty value", pipe_fd, *indicator);
         return 4;
     }
 
@@ -1124,18 +1139,18 @@ pipe_read_block(int pipe, char *indicator, int len, char *msg) {
     if(required > len) {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
               "read %d length error, required %d > len %d, indicator: %u",
-              pipe, required, len, *indicator);
+              pipe_fd, required, len, *indicator);
 
         /* we have a problem here, try to read some more bytes from the pipe to debug where the problem really is */
         memcpy(msg, header, sizeof(header));
-        newly = read(pipe, &msg[sizeof(header)], len-sizeof(header));
+        newly = read(pipe_fd, &msg[sizeof(header)], len-sizeof(header));
         g_warning("Unknown message from dumpcap, try to show it as a string: %s", msg);
         return -1;
     }
     len = required;
 
     /* read the actual block data */
-    newly = pipe_read_bytes(pipe, msg, required);
+    newly = pipe_read_bytes(pipe_fd, msg, required);
     if(newly != required) {
         g_warning("Unknown message from dumpcap, try to show it as a string: %s", msg);
         return -1;
@@ -1143,7 +1158,7 @@ pipe_read_block(int pipe, char *indicator, int len, char *msg) {
 
     /* XXX If message is "2part", the msg probably won't be sent to debug log correctly */
     g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-          "read %d ok indicator: %c len: %u msg: %s", pipe, *indicator,
+          "read %d ok indicator: %c len: %u msg: %s", pipe_fd, *indicator,
           len, msg);
     return newly + 4;
 }
@@ -1186,7 +1201,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
     sync_pipe_wait_for_child(capture_opts);
 
 #ifdef _WIN32
-    eth_close(capture_opts->signal_pipe_write_fd);
+    ws_close(capture_opts->signal_pipe_write_fd);
 #endif
     capture_input_closed(capture_opts);
     return FALSE;
@@ -1200,7 +1215,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
 
       /* We weren't able to open the new capture file; user has been
          alerted. Close the sync pipe. */
-      eth_close(source);
+      ws_close(source);
 
       /* the child has send us a filename which we couldn't open.
          this probably means, the child is creating files faster than we can handle it.
@@ -1232,7 +1247,7 @@ sync_pipe_input_cb(gint source, gpointer user_data)
     /* the capture child will close the sync_pipe, nothing to do for now */
     break;
   case SP_DROPS:
-    capture_input_drops(capture_opts, atoi(buffer));
+    capture_input_drops(capture_opts, (guint32)strtoul(buffer, NULL, 10));
     break;
   default:
     g_assert_not_reached();
@@ -1255,8 +1270,8 @@ sync_pipe_wait_for_child(capture_options *capture_opts)
 
 #ifdef _WIN32
   if (_cwait(&wstatus, capture_opts->fork_child, _WAIT_CHILD) == -1) {
-    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-               "Child capture process stopped unexpectedly (errno:%u)", errno);
+    report_failure("Child capture process stopped unexpectedly (errno:%u)",
+                   errno);
   }
 #else
   if (wait(&wstatus) != -1) {
@@ -1268,26 +1283,22 @@ sync_pipe_wait_for_child(capture_options *capture_opts)
       /* If there are situations where the child won't send us such an error message, */
       /* this should be fixed in the child and not here! */
       if (WEXITSTATUS(wstatus) != 0 && WEXITSTATUS(wstatus) != 1) {
-        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                     "Child capture process exited: exit status %d",
-                     WEXITSTATUS(wstatus));
+        report_failure("Child capture process exited: exit status %d",
+                      WEXITSTATUS(wstatus));
       }
     } else if (WIFSTOPPED(wstatus)) {
       /* It stopped, rather than exiting.  "Should not happen." */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                   "Child capture process stopped: %s",
-                   sync_pipe_signame(WSTOPSIG(wstatus)));
+      report_failure("Child capture process stopped: %s",
+                    sync_pipe_signame(WSTOPSIG(wstatus)));
     } else if (WIFSIGNALED(wstatus)) {
       /* It died with a signal. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                   "Child capture process died: %s%s",
-                   sync_pipe_signame(WTERMSIG(wstatus)),
-                   WCOREDUMP(wstatus) ? " - core dumped" : "");
+      report_failure("Child capture process died: %s%s",
+                    sync_pipe_signame(WTERMSIG(wstatus)),
+                    WCOREDUMP(wstatus) ? " - core dumped" : "");
     } else {
       /* What?  It had to either have exited, or stopped, or died with
          a signal; what happened here? */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                   "Child capture process died: wait status %#o", wstatus);
+      report_failure("Child capture process died: wait status %#o", wstatus);
     }
   }
 #endif
@@ -1431,8 +1442,12 @@ sync_pipe_stop(capture_options *capture_opts)
 
   if (capture_opts->fork_child != -1) {
 #ifndef _WIN32
-    /* send the SIGUSR1 signal to close the capture child gracefully. */
-    kill(capture_opts->fork_child, SIGUSR1);
+    /* send the SIGINT signal to close the capture child gracefully. */
+    int sts = kill(capture_opts->fork_child, SIGINT);
+    if (sts != 0) {
+        g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
+              "Sending SIGINT to child failed: %s\n", strerror(errno));
+    }
 #else
 #define STOP_SLEEP_TIME 500 /* ms */
 #define STOP_CHECK_TIME 50
@@ -1466,9 +1481,13 @@ sync_pipe_stop(capture_options *capture_opts)
 void
 sync_pipe_kill(int fork_child)
 {
-  if (fork_child != -1) {
+    if (fork_child != -1) {
 #ifndef _WIN32
-      kill(fork_child, SIGTERM);       /* SIGTERM so it can clean up if necessary */
+        int sts = kill(fork_child, SIGTERM);   /* SIGTERM so it can clean up if necessary */
+        if (sts != 0) {
+            g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING,
+                  "Sending SIGTERM to child failed: %s\n", strerror(errno));
+        }
 #else
       /* Remark: This is not the preferred method of closing a process!
        * the clean way would be getting the process id of the child process,
@@ -1488,9 +1507,9 @@ sync_pipe_kill(int fork_child)
        * us, as we might not be running in a console.
        * And this also will require to have the process id.
        */
-      TerminateProcess((HANDLE) (fork_child), 0);
+        TerminateProcess((HANDLE) (fork_child), 0);
 #endif
-  }
+    }
 }
 
 #endif /* HAVE_LIBPCAP */