From d5e6c24f77ac1154d7c486381fc10f51c2d9e087 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 12 Apr 2020 20:56:39 +0800 Subject: [PATCH] ifconfig(8): Render non-ASCII SSID names with UTF-8 locales Currently ifconfig(8) only prints the hex representation of ssid names with non-ASCII characters. Many modern terminals are able to properly render non-ASCII characters. This change checks if the terminal charmap is UTF-8, and if so, will render the characters, rather than the hex value. This behavior is circumvented by running ifconfig(8) in a non-UTF8 locale; e.g. C or POSIX. Obtained from FreeBSD: https://github.com/freebsd/freebsd/commit/137a4801848fde80544a987fb168ff56face2ffd https://reviews.freebsd.org/D15922 --- sbin/ifconfig/ifieee80211.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c index 129784be60..64b61e67c9 100644 --- a/sbin/ifconfig/ifieee80211.c +++ b/sbin/ifconfig/ifieee80211.c @@ -82,12 +82,14 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include -#include -#include /* NB: for offsetof */ #include "ifconfig.h" #include "regdomain.h" @@ -4971,16 +4973,21 @@ print_string(const u_int8_t *buf, int len) { int i; int hasspc; + int utf8; i = 0; hasspc = 0; + + setlocale(LC_CTYPE, ""); + utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0; + for (; i < len; i++) { - if (!isprint(buf[i]) && buf[i] != '\0') + if (!isprint(buf[i]) && buf[i] != '\0' && !utf8) break; if (isspace(buf[i])) hasspc++; } - if (i == len) { + if (i == len || utf8) { if (hasspc || len == 0 || buf[0] == '\0') printf("\"%.*s\"", len, buf); else -- 2.41.0