aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-06-24 16:02:39 -0700
committerGerald Combs <gerald@wireshark.org>2020-07-06 16:20:25 +0000
commit4dc3114c050ac2fb6da2b19103ce4995f6d91561 (patch)
tree08c7406a69bd8bc383f205cd5789556abcf6bdb4
parent0d7d7fe3c6295cd40e3c96407f7208ef19b43b61 (diff)
Windows: Set our locale to ".UTF-8".
In each of our executables we were calling "setlocale(LC_ALL, "")" at startup. This told Windows that output was encoded using the current system code page. Unless the code page was 65001 (UTF-8), this was a lie. We write UTF-8 to stdout and stderr, so call "setlocale(LC_ALL, ".UTF-8)" at startup on Windows. This lets the CRT translate our output correctly in more cases. Clarify and expand the OUTPUT section in the tshark man page. Bug: 16649 Change-Id: If93231fe5b332c292946c7f8e5e813e2f543e799 Reviewed-on: https://code.wireshark.org/review/37560 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--capinfos.c9
-rw-r--r--captype.c9
-rw-r--r--dftest.c9
-rw-r--r--doc/tshark.pod7
-rw-r--r--rawshark.c9
-rw-r--r--tfshark.c9
-rw-r--r--tshark.c13
-rw-r--r--ui/qt/main.cpp9
8 files changed, 63 insertions, 11 deletions
diff --git a/capinfos.c b/capinfos.c
index 8e7e7b8455..719659a4a6 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -1551,8 +1551,15 @@ main(int argc, char *argv[])
gcry_md_hd_t hd = NULL;
size_t hash_bytes;
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
diff --git a/captype.c b/captype.c
index b2815b2841..f57a02530f 100644
--- a/captype.c
+++ b/captype.c
@@ -93,8 +93,15 @@ main(int argc, char *argv[])
{0, 0, 0, 0 }
};
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
diff --git a/dftest.c b/dftest.c
index 09b549cd28..ec6b00e251 100644
--- a/dftest.c
+++ b/dftest.c
@@ -80,8 +80,15 @@ main(int argc, char **argv)
if (!epan_init(NULL, NULL, FALSE))
return 2;
- /* set the c-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
/* Load libwireshark settings from the current profile. */
epan_load_settings();
diff --git a/doc/tshark.pod b/doc/tshark.pod
index 4344f625e6..a175c383fd 100644
--- a/doc/tshark.pod
+++ b/doc/tshark.pod
@@ -1986,8 +1986,11 @@ If B<TShark> detects that it is writing to a TTY on UNIX or Linux and
the locale does not support UTF-8, output will be re-encoded to match the
current locale.
-If B<TShark> detects that it is writing to a TTY on Windows, output will be
-encoded as UTF-16LE.
+If B<TShark> detects that it is writing to the console on Windows,
+dissection output will be encoded as UTF-16LE. Other output will be
+UTF-8. If extended characters don't display properly in your terminal
+you might try setting your console code page to UTF-8 (B<chcp 65001>)
+and using a modern terminal application if possible.
=head1 ENVIRONMENT VARIABLES
diff --git a/rawshark.c b/rawshark.c
index 780b33a532..1a573d3ce3 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -433,8 +433,15 @@ main(int argc, char *argv[])
static const char optstring[] = OPTSTRING_INIT;
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
cmdarg_err_init(rawshark_cmdarg_err, rawshark_cmdarg_err_cont);
diff --git a/tfshark.c b/tfshark.c
index e079749c75..fcd1f6b520 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -348,8 +348,15 @@ main(int argc, char *argv[])
static const char optstring[] = OPTSTRING;
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
diff --git a/tshark.c b/tshark.c
index f0d73c579e..0c7da3f3e2 100644
--- a/tshark.c
+++ b/tshark.c
@@ -764,10 +764,17 @@ main(int argc, char *argv[])
static const char optstring[] = OPTSTRING;
- tshark_debug("tshark started with %d args", argc);
-
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
+
+ tshark_debug("tshark started with %d args", argc);
cmdarg_err_init(failure_warning_message, failure_message_cont);
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index abb3a728e4..a834dcaf51 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -419,8 +419,15 @@ int main(int argc, char *qt_argv[])
CocoaBridge::cleanOSGeneratedMenuItems();
#endif
- /* Set the C-language locale to the native environment. */
+ /*
+ * Set the C-language locale to the native environment and set the
+ * code page to UTF-8 on Windows.
+ */
+#ifdef _WIN32
+ setlocale(LC_ALL, ".UTF-8");
+#else
setlocale(LC_ALL, "");
+#endif
#ifdef _WIN32
//