Update supported Win32 versions and NSIS version.
[obnox/wireshark/wip.git] / dumpcap.c
index a34816a66f67b32f6586ce8089ecddc025d28685..1909a97891ce2d4de59b17834c82233a4de2b26c 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -25,6 +25,7 @@
 # include "config.h"
 #endif
 
+#include <stdlib.h> /* for exit() */
 #include <glib.h>
 
 #include <string.h>
@@ -193,13 +194,17 @@ cmdarg_err_cont(const char *fmt, ...)
 BOOL WINAPI ConsoleCtrlHandlerRoutine(DWORD dwCtrlType)
 {
     g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO,
-        "Console: Ctrl+C");
+        "Console: Control signal");
     g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
-        "Console: Ctrl+C CtrlType: %u", dwCtrlType);
+        "Console: Control signal, CtrlType: %u", dwCtrlType);
 
-    capture_loop_stop();
-
-    return TRUE;
+    /* Keep capture running if we're a service and a user logs off */
+    if (capture_child || (dwCtrlType != CTRL_LOGOFF_EVENT)) {
+        capture_loop_stop();
+        return TRUE;
+    } else {
+        return FALSE;
+    }
 }
 #endif
 
@@ -228,8 +233,6 @@ main(int argc, char *argv[])
   int                  opt;
   extern char         *optarg;
   gboolean             arg_error = FALSE;
-  GString             *comp_info_str;
-  GString             *runtime_info_str;
 
 #ifdef _WIN32
   WSADATA              wsaData;
@@ -268,14 +271,6 @@ main(int argc, char *argv[])
   SetConsoleCtrlHandler(&ConsoleCtrlHandlerRoutine, TRUE);
 #endif  /* _WIN32 */
 
-  /* Assemble the compile-time version information string */
-  comp_info_str = g_string_new("Compiled ");
-  g_string_append(comp_info_str, "with ");
-  get_compiled_version_info(comp_info_str);
-
-  /* Assemble the run-time version information string */
-  runtime_info_str = g_string_new("Running ");
-  get_runtime_version_info(runtime_info_str);
 
   /* the default_log_handler will use stdout, which makes trouble in */
   /* capture child mode, as it uses stdout for it's sync_pipe */
@@ -322,9 +317,22 @@ main(int argc, char *argv[])
         exit_main(0);
         break;
       case 'v':        /* Show version and exit */
+      {
+        GString             *comp_info_str;
+        GString             *runtime_info_str;
+        /* Assemble the compile-time version information string */
+        comp_info_str = g_string_new("Compiled with ");
+        get_compiled_version_info(comp_info_str, NULL);
+
+        /* Assemble the run-time version information string */
+        runtime_info_str = g_string_new("Running ");
+        get_runtime_version_info(runtime_info_str, NULL);              
         show_version(comp_info_str, runtime_info_str);
+        g_string_free(comp_info_str, TRUE);
+        g_string_free(runtime_info_str, TRUE);
         exit_main(0);
         break;
+      }
       /*** capture option specific ***/
       case 'a':        /* autostop criteria */
       case 'b':        /* Ringbuffer option */
@@ -626,49 +634,3 @@ signal_pipe_check_running(void)
 
 const char *netsnmp_get_version(void) { return ""; }
 
-
-#ifdef _WIN32
-
-/* Convert from UTF-16 to UTF-8. */
-/* XXX - copied from epan/strutil.c */
-#define        INITIAL_FMTBUF_SIZE     128
-
-gchar * utf_16to8(const wchar_t *utf16str) {
-  static gchar *utf8buf[3];
-  static int utf8buf_len[3];
-  static int idx;
-
-  if (utf16str == NULL)
-    return NULL;
-
-  idx = (idx + 1) % 3;
-
-  /*
-   * Allocate the buffer if it's not already allocated.
-   */
-  if (utf8buf[idx] == NULL) {
-    utf8buf_len[idx] = INITIAL_FMTBUF_SIZE;
-    utf8buf[idx] = g_malloc(utf8buf_len[idx]);
-  }
-
-  while (WideCharToMultiByte(CP_UTF8, 0, utf16str, -1,
-      NULL, 0, NULL, NULL) >= utf8buf_len[idx]) {
-    /*
-     * Double the buffer's size if it's not big enough.
-     * The size of the buffer starts at 128, so doubling its size
-     * adds at least another 128 bytes, which is more than enough
-     * for one more character plus a terminating '\0'.
-     */
-    utf8buf_len[idx] *= 2;
-    utf8buf[idx] = g_realloc(utf8buf[idx], utf8buf_len[idx]);
-  }
-
-  if (WideCharToMultiByte(CP_UTF8, 0, utf16str, -1,
-      utf8buf[idx], utf8buf_len[idx], NULL, NULL) == 0)
-    return NULL;
-
-  return utf8buf[idx];
-}
-
-#endif /* _WIN32 */
-