git: a3a5f67d3949 - stable/13 - ifconfig: ifieee80211: print bssid name

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 26 Jun 2023 12:08:20 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=a3a5f67d394999dc79be1c32a02ae659eea24963

commit a3a5f67d394999dc79be1c32a02ae659eea24963
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-03-21 21:25:28 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-26 08:29:30 +0000

    ifconfig: ifieee80211: print bssid name
    
    In certain setups (e.g., autonomous APs) it is extremly helpful to have
    a way to map the BSSIDs to names for both normal status output as well
    as the scan list.  This often allows a quicker overview than remembering
    (or manually looking up) BSSIDs.
    Call ether_ntohost() on the bssid and consult /etc/ethers
    and print "(name)" after the bssid for the status output and "(name)"
    at the end of the line after the IE list.
    
    Reviewed by:    adrian, cy
    Differential Revision: https://reviews.freebsd.org/D39192
    
    (cherry picked from commit e091be417add7e9130653462012a9ab2f4fb5269)
---
 sbin/ifconfig/ifieee80211.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c
index cb465a02b794..065a141da0f1 100644
--- a/sbin/ifconfig/ifieee80211.c
+++ b/sbin/ifconfig/ifieee80211.c
@@ -3716,6 +3716,17 @@ printmimo(const struct ieee80211_mimo_info *mi)
 	    mi->ch[3].noise[0]);
 }
 
+static void
+printbssidname(const struct ether_addr *n)
+{
+	char name[MAXHOSTNAMELEN + 1];
+
+	if (ether_ntohost(name, n) != 0)
+		return;
+
+	printf(" (%s)", name);
+}
+
 static void
 list_scan(int s)
 {
@@ -3767,6 +3778,7 @@ list_scan(int s)
 		);
 		printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
 		    sr->isr_ie_len, 24);
+		printbssidname((const struct ether_addr *)sr->isr_bssid);
 		printf("\n");
 		cp += sr->isr_len, len -= sr->isr_len;
 	} while (len >= sizeof(struct ieee80211req_scan_result));
@@ -4904,8 +4916,10 @@ ieee80211_status(int s)
 		printf(" channel UNDEF");
 
 	if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
-	    (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
+	    (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) {
 		printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
+		printbssidname((struct ether_addr *)data);
+	}
 
 	if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
 		printf("\n\tstationname ");