From 8e7c2e14cffaa33f1f1413f8a3e462611217b8e8 Mon Sep 17 00:00:00 2001 From: Richard Scheffenegger Date: Fri, 9 Jun 2023 23:57:00 +0200 Subject: [PATCH] netstat: display c and C flags properly Restructure c and C flag checks for string length to work properly. Quickly bypass for non TCP protos too. Reviewed By: tuexen Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D40480 --- usr.bin/netstat/inet.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index fd1a6ff20e42..691f9d9e912c 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -237,23 +237,20 @@ protopr(u_long off, const char *name, int af1, int proto) if (!pcblist_sysctl(proto, name, &buf)) return; - if (cflag || Cflag) { + if (istcp && (cflag || Cflag)) { fnamelen = strlen("Stack"); cnamelen = strlen("CC"); oxig = xig = (struct xinpgen *)buf; for (xig = (struct xinpgen*)((char *)xig + xig->xig_len); xig->xig_len > sizeof(struct xinpgen); xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { - if (istcp) { - tp = (struct xtcpcb *)xig; - inp = &tp->xt_inp; - } else { - continue; - } - if (so->xso_protocol != proto) - continue; + tp = (struct xtcpcb *)xig; + inp = &tp->xt_inp; if (inp->inp_gencnt > oxig->xig_gen) continue; + so = &inp->xi_socket; + if (so->xso_protocol != proto) + continue; fnamelen = max(fnamelen, (int)strlen(tp->xt_stack)); cnamelen = max(cnamelen, (int)strlen(tp->xt_cc)); }