From nobody Wed Jul 13 13:20:46 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1648017FDB37; Wed, 13 Jul 2022 13:20:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LjdXv05j0z44VX; Wed, 13 Jul 2022 13:20:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657718447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dPyvXBtuL0drD7tCEdI1IYo/YjETIdM5wdGdUidzK5Q=; b=JD4B9oOumOsgrVXZGm6tnZlupYxYc2Ng4PZPx1f/wN3SAlk/PC0BLrvgRQYwR0JE9oqXzp K1AydL0nO1mWOAy+PIxvlvp4E3G7KiWLPHDvqQ8FpDBTdTFS3DG1KCbRZ1Zcn6IGLMQz7s O/uJQjcUqkAIYAy5Af5b0VvnGu9i1Y3C+6mPLwsV6SBi08B9nHK1tt6AXR2Ou2y/MwulWP wqCi4HesJFTdn43zp842oEwprWxFIhu7jv6ZrL3bcFOo1I2Mc6eRnhczSUGKqrjTWlviVW mjywguTM9FsV2tRMqjFQSLSVEc2BZg5a8Tfbtji0BE8xI1hsH34FvW4YnVxaFw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LjdXt6GFYzPMq; Wed, 13 Jul 2022 13:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26DDKkao075895; Wed, 13 Jul 2022 13:20:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26DDKkUI075894; Wed, 13 Jul 2022 13:20:46 GMT (envelope-from git) Date: Wed, 13 Jul 2022 13:20:46 GMT Message-Id: <202207131320.26DDKkUI075894@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mike Karels Subject: git: 913ebccc8e16 - stable/13 - netstat -i: do not truncate interface names List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 913ebccc8e16c74126728faeafda5139f3784cdc Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657718447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dPyvXBtuL0drD7tCEdI1IYo/YjETIdM5wdGdUidzK5Q=; b=kHzARb5g70hVMtFrTFboIfJrPOr6PQuNCXokv7n3ZTvzze6XQHmYLn4SwvgwdeyPvoPinB Mme+hjTo5Y/29OnchAGvpJTDP0KiDywHgUUMiJtQV3QRMx5dnLmmaybwb49ZKYAjePeuh0 yUQDKXDz974O2D5Wm5nMPoqoXvNQwsoC/gGDD2YAZ65+N5WHsKiov3ltFjaIaB3PC6c/ej Cr6r6YySo71EyFaSi2uqQ0xeSSl5aeI41PjTGc12I68Cl/9O51ubdTnrK4HPg9v1PYMPeU 0cquMqdXraj+q7+jwxbqm7jOq3Ljc4rRgtU+m9S8oHqMXzeNSaGRIhTrI5XpuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657718447; a=rsa-sha256; cv=none; b=aw338mQmf1J6gY6WoIrkzrOsXEdfg3beRI1j+0TuifFsUJZDn4N1pPuNO4bwnAdtsUoRwa hSI/fM3tqPXI59gAnKOx0BEyJLnUaLxNa2X4IAYesZZ/ZGP1iWZzzH2pNUncYbuAgSxYBD 7J6bNj9cA8lNEh1oxEfwzpvAI1L9Wm+yTJG5mX4Gt2eRtN1XNAXzAzUPiCFI4iP2wm1LM+ QNMFSGjY2LIPVcbNd+zP9zoi50hZ38ZoocJbDstCSyN/I1ionV3jsIJLH3tNGHstWpX8FP a8K9/lNmxKihTVzW1ldvFVtz7AiL7/o5AVJ7iQFJlgO+oP+j4AcL1H+AendQ1w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=913ebccc8e16c74126728faeafda5139f3784cdc commit 913ebccc8e16c74126728faeafda5139f3784cdc Author: Mike Karels AuthorDate: 2022-07-02 16:03:36 +0000 Commit: Mike Karels CommitDate: 2022-07-13 13:20:03 +0000 netstat -i: do not truncate interface names The field for interface names for netstat -i was 5 characters by default, which is no longer sufficient with names like "vlan1234" and "vtnet0". netstat -iW computed the necessary field width, but also enlarged the address field by a lot (especially with IPv6 enabled). Make netstat -i compute the field width for interface names with or without -W. Note that the existing default output does not fit in 80 columns in any case. Update the man page accordingly, documenting the remaining effect of -W with -i. Also add -W to the list of General Options, as there are numerous pointers to this. Reported by: Chris Ross Reviewed by: melifaro, rgrimes, cy Differential Revision: https://reviews.freebsd.org/D35703 (cherry picked from commit 231092bb6fda75b922fc324edef6523e78e9e8ed) --- usr.bin/netstat/if.c | 26 +++++++++++++------------- usr.bin/netstat/netstat.1 | 8 +++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index d9a7574c9e22..5ba4f3afc67b 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -284,20 +284,20 @@ intpr(void (*pfunc)(char *), int af) if (aflag && getifmaddrs(&ifmap) != 0) err(EX_OSERR, "getifmaddrs"); + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (interface != NULL && + strcmp(ifa->ifa_name, interface) != 0) + continue; + if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af) + continue; + ifn_len = strlen(ifa->ifa_name); + if ((ifa->ifa_flags & IFF_UP) == 0) + ++ifn_len; + ifn_len_max = MAX(ifn_len_max, ifn_len); + if (ifa->ifa_addr->sa_family == AF_INET6) + has_ipv6 = 1; + } if (Wflag) { - for (ifa = ifap; ifa; ifa = ifa->ifa_next) { - if (interface != NULL && - strcmp(ifa->ifa_name, interface) != 0) - continue; - if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af) - continue; - ifn_len = strlen(ifa->ifa_name); - if ((ifa->ifa_flags & IFF_UP) == 0) - ++ifn_len; - ifn_len_max = MAX(ifn_len_max, ifn_len); - if (ifa->ifa_addr->sa_family == AF_INET6) - has_ipv6 = 1; - } if (has_ipv6) { net_len = 24; addr_len = 39; diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index e4186b9c9999..d2c6d2509f88 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -314,7 +314,8 @@ Do not resolve numeric addresses and port numbers to names. See .Sx GENERAL OPTIONS . .It Fl W -Avoid truncating interface names even if this causes some fields to overflow. +Avoid truncating addresses even if this causes some fields to overflow. +See .Sx GENERAL OPTIONS . .It Fl f Ar protocol_family Filter by @@ -800,6 +801,11 @@ Normally .Nm attempts to resolve addresses and ports, and display them symbolically. +.It Fl W +Wider output; expand address fields, etc, to avoid truncation. +Non-numeric values such as domain names may still be truncated; use the +.Fl n +option if necessary to avoid ambiguity. .El .Sh EXAMPLES Show packet traffic information (packets, bytes, errors, packet drops, etc) for