From owner-freebsd-bugs Mon Nov 4 7:20: 7 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 494BD37B401 for ; Mon, 4 Nov 2002 07:20:04 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 86CBD43E4A for ; Mon, 4 Nov 2002 07:20:03 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id gA4FK3x3041876 for ; Mon, 4 Nov 2002 07:20:03 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id gA4FK3Xe041875; Mon, 4 Nov 2002 07:20:03 -0800 (PST) Date: Mon, 4 Nov 2002 07:20:03 -0800 (PST) Message-Id: <200211041520.gA4FK3Xe041875@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Giorgos Keramidas Subject: Re: kern/44843: ipfw -t l doesn't align columns quite right Reply-To: Giorgos Keramidas Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR kern/44843; it has been noted by GNATS. From: Giorgos Keramidas To: Chris Pepper Cc: bug-followup@freebsd.org, Luigi Rizzo Subject: Re: kern/44843: ipfw -t l doesn't align columns quite right Date: Mon, 4 Nov 2002 17:17:54 +0200 On 2002-11-04 09:26, Chris Pepper wrote: > Sorry, I'm using ipfw1 -- isn't this for v2? Err, yes. Sorry 'bout that. I don't have a -STABLE machine right now. Does the following work for your ipfw version? I have tested that it compiles on ref4.freebsd.org but I don't have access to a -stable system to run ipfw and see if it fixes it all. I've tried to make changes both to ipfw.c and ipfw2.c since the necessary diffs were pretty similar... %%% Index: ipfw.c =================================================================== RCS file: /home/ncvs/src/sbin/ipfw/ipfw.c,v retrieving revision 1.80.2.24 diff -u -r1.80.2.24 ipfw.c --- ipfw.c 26 Sep 2002 07:19:05 -0000 1.80.2.24 +++ ipfw.c 4 Nov 2002 14:52:51 -0000 @@ -183,6 +183,7 @@ static void show_ipfw(struct ip_fw *chain, int pcwidth, int bcwidth) { + static int twidth = 0; char comma; u_long adrt; struct hostent *he; @@ -200,14 +201,19 @@ printf("%*qu %*qu ", pcwidth, chain->fw_pcnt, bcwidth, chain->fw_bcnt); if (do_time) { - if (chain->timestamp) { - char timestr[30]; + char timestr[30]; + if (twidth == 0) { + strcpy(timestr, ctime((time_t *)&twidth)); + *strchr(timestr, '\n') = '\0'; + twidth = strlen(timestr); + } + if (chain->timestamp) { strcpy(timestr, ctime((time_t *)&chain->timestamp)); *strchr(timestr, '\n') = '\0'; printf("%s ", timestr); } else { - printf(" "); + printf("%*s ", twidth, " "); } } if (chain->fw_flg == IP_FW_F_CHECK_S) { Index: ipfw2.c =================================================================== RCS file: /home/ncvs/src/sbin/ipfw/ipfw2.c,v retrieving revision 1.4.2.6 diff -u -r1.4.2.6 ipfw2.c --- ipfw2.c 10 Oct 2002 20:46:04 -0000 1.4.2.6 +++ ipfw2.c 4 Nov 2002 14:57:24 -0000 @@ -803,6 +803,7 @@ static void show_ipfw(struct ip_fw *rule) { + static int twidth = 0; int l; ipfw_insn *cmd; int proto = 0; /* default */ @@ -824,8 +825,14 @@ printf("%10qu %10qu ", rule->pcnt, rule->bcnt); if (do_time) { + char timestr[30]; + + if (twidth == 0) { + strcpy(timestr, ctime((time_t *)&twidth)); + *strchr(timestr, '\n') = '\0'; + twidth = strlen(timestr); + } if (rule->timestamp) { - char timestr[30]; #if _FreeBSD_version < 500000 /* XXX check */ #define _long_to_time(x) (time_t)(x) #endif @@ -835,7 +842,7 @@ *strchr(timestr, '\n') = '\0'; printf("%s ", timestr); } else { - printf(" "); + printf("%*s ", twidth, " "); } } %%% To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message