From owner-svn-src-all@freebsd.org Thu Jun 28 03:37:16 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 541D510325A0; Thu, 28 Jun 2018 03:37:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 01EE0854D3; Thu, 28 Jun 2018 03:37:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D78724AF8; Thu, 28 Jun 2018 03:37:15 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5S3bFWf004961; Thu, 28 Jun 2018 03:37:15 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5S3bFlE004960; Thu, 28 Jun 2018 03:37:15 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201806280337.w5S3bFlE004960@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 28 Jun 2018 03:37:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335757 - head/sbin/ifconfig X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sbin/ifconfig X-SVN-Commit-Revision: 335757 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2018 03:37:16 -0000 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 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 #include #include /* NB: for offsetof */ +#include +#include #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