From d2d77d2aeec7b84f7205134f87f2409d8d543e03 Mon Sep 17 00:00:00 2001 From: Giorgos Keramidas Date: Sun, 12 Nov 2006 19:03:39 +0000 Subject: [PATCH] In revision 1.14 I broke the -4 and -6 options of sockstat(1). Using either one of the two would result in an empty protos[] array, and no sockets were actually listed: % sockstat -4 USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS % sockstat -6 USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS % Fix this bug by tweaking appropriately the logic of handling opt_4, opt_6, opt_u and protos_defined. Submitted by: des Pointy hat: keramida --- usr.bin/sockstat/sockstat.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index f128d38a5004..bd71c5352f92 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -713,17 +713,12 @@ main(int argc, char *argv[]) if (argc > 0) usage(); - /* - * If protos_defined remains -1, no -P was provided, so we have to - * set up the default protocol list in protos[] first. - */ - if (!opt_4 && !opt_6 && !opt_u && protos_defined == -1) { - opt_u = 1; - protos_defined = set_default_protos(); - } - - if (!opt_4 && !opt_6) + if ((!opt_4 && !opt_6) && protos_defined != -1) opt_4 = opt_6 = 1; + if (!opt_4 && !opt_6 && !opt_u) + opt_4 = opt_6 = opt_u = 1; + if ((opt_4 || opt_6) && protos_defined == -1) + protos_defined = set_default_protos(); if (!opt_c && !opt_l) opt_c = opt_l = 1;