On Windows, convert all of our command-line arguments from UTF-16 to
authorGerald Combs <gerald@wireshark.org>
Thu, 6 Jan 2011 23:28:58 +0000 (23:28 -0000)
committerGerald Combs <gerald@wireshark.org>
Thu, 6 Jan 2011 23:28:58 +0000 (23:28 -0000)
UTF-8 where we don't already do so. In Wireshark use g_utf16_to_utf8
instead of utf_16to8. This should fix bug 5520.

svn path=/trunk/; revision=35411

Makefile.nmake
capinfos.c
dumpcap.c
editcap.c
gtk/main.c
mergecap.c
randpkt.c
rawshark.c
text2pcap.c
tshark.c

index d945a334a4f49adabb654984bf5df48fb4222ec7..efb9a54cc8610c63fae66c39568f5d1fcd2f9ea1 100644 (file)
@@ -92,7 +92,7 @@ wireshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
@@ -112,7 +112,7 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 rawshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
@@ -143,17 +143,17 @@ editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        $(GLIB_LIBS)
 
 mergecap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
 text2pcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
 dumpcap_LIBS= \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS) \
        $(GTHREAD_LIBS)
@@ -177,7 +177,7 @@ dftest_LIBS=  wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 randpkt_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       user32.lib \
+       user32.lib shell32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
index 08017999b4e4306a3c74ab97995f0e359b65d88d..86f9b81606c5e419b1ea3b0aade33045b47e1497 100644 (file)
 #include "wsutil/wsgetopt.h"
 #endif
 
+#ifdef _WIN32
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 #include "svnversion.h"
 
 /*
@@ -802,6 +806,13 @@ main(int argc, char *argv[])
   int err;
   gchar *err_info;
   int opt;
+
+#ifdef _WIN32
+  WSADATA             wsaData;
+  LPWSTR              *wc_argv;
+  int                  wc_argc, i;
+#endif  /* _WIN32 */
+
   int status = 0;
 #ifdef HAVE_PLUGINS
   char* init_progfile_dir_error;
@@ -813,6 +824,16 @@ main(int argc, char *argv[])
   size_t hash_bytes;
 #endif
 
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
   /*
    * Get credential information for later use.
    */
index c17394a7a3b52d6cc591fd7c39fd4c5a13972430..3dc0bf87ac82d9a44530c050a71466e922621c57 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -85,6 +85,7 @@
 #include "pcapio.h"
 
 #ifdef _WIN32
+#include <shellapi.h>
 #include "capture-wpcap.h"
 #include <wsutil/unicode-utils.h>
 #endif
@@ -3305,6 +3306,8 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   WSADATA              wsaData;
+  LPWSTR              *wc_argv;
+  int                  wc_argc;
 #else
   struct sigaction action, oldaction;
 #endif
@@ -3326,6 +3329,16 @@ main(int argc, char *argv[])
   struct utsname       osinfo;
 #endif
 
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
 #ifdef _WIN32
   /*
    * Initialize our DLL search path. MUST be called before LoadLibrary
index 0c54146401a71341d19a0f94dfe6aafe3937861f..89ecb33a10805743368bda111dd84a714532d08a 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -49,6 +49,8 @@
 #endif
 
 #ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
 #include <process.h>    /* getpid */
 #ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
@@ -813,6 +815,12 @@ main(int argc, char *argv[])
   int i, j, err;
   gchar *err_info;
   int opt;
+
+#ifdef _WIN32
+  LPWSTR              *wc_argv;
+  int                  wc_argc;
+#endif  /* _WIN32 */
+
   char *p;
   unsigned int snaplen = 0;             /* No limit               */
   unsigned int choplen = 0;             /* No chop                */
@@ -838,6 +846,16 @@ main(int argc, char *argv[])
   char* init_progfile_dir_error;
 #endif
 
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
   /*
    * Get credential information for later use.
    */
index 343708986fe28a802db95979c80a60e6db2d984d..99a3993c27198cf4fc4157bee516469e1ce57ca6 100644 (file)
 #include "../capture-wpcap.h"
 #include "../capture_wpcap_packet.h"
 #include <tchar.h> /* Needed for Unicode */
-#include <wsutil/unicode-utils.h>
 #include <commctrl.h>
 #include <shellapi.h>
 #endif /* _WIN32 */
@@ -2098,7 +2097,7 @@ main(int argc, char *argv[])
   wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
   if (wc_argv && wc_argc == argc) {
     for (i = 0; i < argc; i++) {
-      argv[i] = g_strdup(utf_16to8(wc_argv[i]));
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
     }
   } /* XXX else bail because something is horribly, horribly wrong? */
 #endif /* _WIN32 */
index 05bb517666d8090f66ad0d802e1e2bae64c13562..460f938ba9c383aa88cf4f5fbe09ab0e255863ff 100644 (file)
 #include <fcntl.h>
 #endif
 
+#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 static int
 get_natural_int(const char *string, const char *name)
 {
@@ -143,6 +148,12 @@ int
 main(int argc, char *argv[])
 {
   int          opt;
+
+#ifdef _WIN32
+  LPWSTR              *wc_argv;
+  int                  wc_argc;
+#endif  /* _WIN32 */
+
   gboolean     do_append     = FALSE;
   gboolean     verbose       = FALSE;
   int          in_file_count = 0;
@@ -162,6 +173,16 @@ main(int argc, char *argv[])
   gboolean     got_read_error = FALSE, got_write_error = FALSE;
   int          count;
 
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
   /* Process the options first */
   while ((opt = getopt(argc, argv, "hvas:T:F:w:")) != -1) {
 
index 941b267643d72935f24468d5dc8b8abe117cc12c..a9d157ac52d10a993240d008bd674a394ca274eb 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
 #include <glib.h>
 #include "wiretap/wtap.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 #define array_length(x)        (sizeof x / sizeof x[0])
 
 /* Types of produceable packets */
@@ -502,12 +507,29 @@ main(int argc, char **argv)
        guint8                  buffer[65536];
 
        int                     opt;
+
+#ifdef _WIN32
+       LPWSTR              *wc_argv;
+       int                  wc_argc;
+#endif  /* _WIN32 */
+       
+
        int                     produce_count = 1000; /* number of pkts to produce */
        int                     produce_type = PKT_ETHERNET;
        char                    *produce_filename = NULL;
        int                     produce_max_bytes = 5000;
        pkt_example             *example;
 
+#ifdef _WIN32
+       /* Convert our arg list to UTF-8. */
+       wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+       if (wc_argv && wc_argc == argc) {
+               for (i = 0; i < argc; i++) {
+                       argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+               }
+       } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
        while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
                switch (opt) {
                        case 'b':       /* max bytes */
index a88d6fee5ebf4e0bc939542073afe7944e210d1f..27d4d7639de98e4be8d06bc1650b4bcb3ce0bf6b 100644 (file)
 #endif /* HAVE_LIBPCAP */
 #include "log.h"
 
+#ifdef _WIN32
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 /*
  * This is the template for the decode as option; it is shared between the
  * various functions that output the usage for this parameter.
@@ -430,7 +434,9 @@ main(int argc, char *argv[])
     gboolean             arg_error = FALSE;
 
 #ifdef _WIN32
-    WSADATA       wsaData;
+    WSADATA              wsaData;
+    LPWSTR              *wc_argv;
+    int                  wc_argc;
 #endif  /* _WIN32 */
 
     char                *gpf_path, *pf_path;
@@ -453,6 +459,16 @@ main(int argc, char *argv[])
 
     static const char    optstring[] = OPTSTRING_INIT;
 
+#ifdef _WIN32
+    /* Convert our arg list to UTF-8. */
+    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+    if (wc_argv && wc_argc == argc) {
+        for (i = 0; i < argc; i++) {
+            argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+        }
+    } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
     /*
      * Get credential information for later use.
      */
index 4b0ee8a23617d4e2de7e4037b726ab7f85b326af..cb3d3737a0ee3f64af677d156b7458eec2696621 100644 (file)
 #include "text2pcap.h"
 #include "svnversion.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 /*--- Options --------------------------------------------------------------------*/
 
 /* Debug level */
@@ -1108,6 +1113,20 @@ parse_options (int argc, char *argv[])
 {
     int c;
     char *p;
+#ifdef _WIN32
+    LPWSTR *wc_argv;
+    int wc_argc, i;
+#endif  /* _WIN32 */
+
+#ifdef _WIN32
+    /* Convert our arg list to UTF-8. */
+    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+    if (wc_argv && wc_argc == argc) {
+       for (i = 0; i < argc; i++) {
+           argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+       }
+    } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
 
     /* Scan CLI parameters */
     while ((c = getopt(argc, argv, "dhqe:i:l:m:o:u:s:S:t:T:")) != -1) {
@@ -1351,7 +1370,8 @@ parse_options (int argc, char *argv[])
     }
 }
 
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
 {
     parse_options(argc, argv);
 
index ac81ba007d940f85555ba6e15996b5a2553f1705..276872e867438bacd4c856695c7eaf53cc129858 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -96,6 +96,7 @@
 #ifdef _WIN32
 #include "capture-wpcap.h"
 #include "capture_errs.h"
+#include <shellapi.h>
 #endif /* _WIN32 */
 #include "capture_sync.h"
 #endif /* HAVE_LIBPCAP */
@@ -765,6 +766,8 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   WSADATA              wsaData;
+  LPWSTR              *wc_argv;
+  int                  wc_argc, i;
 #endif  /* _WIN32 */
 
   char                *gpf_path, *pf_path;
@@ -816,6 +819,16 @@ main(int argc, char *argv[])
 
   static const char    optstring[] = OPTSTRING;
 
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
+
   /*
    * Get credential information for later use.
    */