svn commit: r335757 - head/sbin/ifconfig

Kyle Evans kevans at FreeBSD.org
Thu Jun 28 03:37:16 UTC 2018


Author: kevans
Date: Thu Jun 28 03:37:15 2018
New Revision: 335757
URL: https://svnweb.freebsd.org/changeset/base/335757

Log:
  ifconfig(8): Attempt to render non-printable sequences w/ UTF-8 Environment
  
  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.
  
  It was pointed out by kp@ during the review that APs have the option to
  broadcast whether their SSIDs may be interpreted as UTF-8. Ideally, we would
  honor this and only attempt this behavior if it's so-broadcasted by the AP.
  
  However, a sample survey showed that hostapd will advertise this if
  indicated in config but it doesn't seem to be so common in the AP market, so
  this would be effectively useless as we'll rarely know if the SSID should be
  renderable as UTF-8.
  
  Despite this, it was decided to be OK with this anyways- there's a
  straightforward path to doing it the right way based on advertisement by AP
  if we need to go that route, and one can revert to old behavior easily
  enough at runtime if we get it wrong.
  
  Submitted by:	Farhan Khan <khanzf at gmail.com>
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D15922

Modified:
  head/sbin/ifconfig/ifieee80211.c

Modified: head/sbin/ifconfig/ifieee80211.c
==============================================================================
--- head/sbin/ifconfig/ifieee80211.c	Thu Jun 28 01:45:53 2018	(r335756)
+++ head/sbin/ifconfig/ifieee80211.c	Thu Jun 28 03:37:15 2018	(r335757)
@@ -90,6 +90,8 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <stddef.h>		/* NB: for offsetof */
+#include <locale.h>
+#include <langinfo.h>
 
 #include "ifconfig.h"
 
@@ -5383,16 +5385,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


More information about the svn-src-head mailing list