From pepper@reppep.com  Sat Nov  2 20:41:49 2002
Return-Path: <pepper@reppep.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 9B5CF37B401; Sat,  2 Nov 2002 20:41:49 -0800 (PST)
Received: from www.reppep.com (www.reppep.com [66.92.104.200])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 9A1DA43EAC; Sat,  2 Nov 2002 20:41:45 -0800 (PST)
	(envelope-from pepper@reppep.com)
Received: by www.reppep.com (Postfix, from userid 501)
	id E3811AC42; Fri,  1 Nov 2002 22:46:59 -0500 (EST)
Message-Id: <20021102034659.E3811AC42@www.reppep.com>
Date: Fri,  1 Nov 2002 22:46:59 -0500 (EST)
From: Chris Pepper <pepper@reppep.com>
Reply-To: Chris Pepper <pepper@reppep.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Luigi Rizzo <luigi@FreeBSD.org>
Subject: ipfw -t l doesn't align columns quite right
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         44843
>Category:       kern
>Synopsis:       ipfw -t l doesn't align columns quite right
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    keramida
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 02 20:50:01 PST 2002
>Closed-Date:    Sat Dec 14 15:49:01 PST 2002
>Last-Modified:  Sat Dec 14 15:49:01 PST 2002
>Originator:     Chris Pepper
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
>Environment:
System: FreeBSD www.reppep.com 4.7-STABLE FreeBSD 4.7-STABLE #6: Sun Oct 20 18:15:59 EDT 2002 root@www.reppep.com:/usr/obj/usr/src/sys/GENERIC i386


	
>Description:
	"ipfw -t l" doesn't align columns very well.
	With "ipfw -t l", rules that haven't been triggered yet should leave 6 more characters of space in the date/time column, so they line up right with rules that have actual dates in the column.

	An example from ipfw1 in FreeBSD 4.7-STABLE follows:

[www:~] root# ipfw -t l
00100 Fri Nov  1 22:40:38 2002 allow ip from any to any via lo0
00200                    deny ip from any to 127.0.0.0/8
00300                    deny ip from 127.0.0.0/8 to any
00400                    check-state
00500 Fri Nov  1 22:40:50 2002 allow tcp from any to any established
00600                    allow ip from any to any frag
00700 Fri Nov  1 21:55:37 2002 allow tcp from 10.0.0.10 to any setup
00800 Fri Nov  1 22:40:50 2002 allow ip from 10.0.0.10 to any

	
>How-To-Repeat:
	
>Fix:
	For rules with no last accessed time, add 6 more spaces to the date/time column.
	


>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Chris Pepper <pepper@reppep.com>
Cc: bug-followup@freebsd.org, Luigi Rizzo <luigi@freebsd.org>
Subject: Re: kern/44843: ipfw -t l doesn't align columns quite right
Date: Mon, 4 Nov 2002 11:19:48 +0200

 On 2002-11-01 22:46, Chris Pepper <pepper@reppep.com> wrote:
 > "ipfw -t l" doesn't align columns very well.
 
 > [www:~] root# ipfw -t l
 > 00100 Fri Nov  1 22:40:38 2002 allow ip from any to any via lo0
 > 00200                    deny ip from any to 127.0.0.0/8
 
 Can you try the following patch?  It seems to fix the problem here.
 
 %%%
 Index: ipfw2.c
 ===================================================================
 RCS file: /home/ncvs/src/sbin/ipfw/ipfw2.c,v
 retrieving revision 1.14
 diff -u -r1.14 ipfw2.c
 --- ipfw2.c	24 Oct 2002 18:04:44 -0000	1.14
 +++ ipfw2.c	4 Nov 2002 03:58:37 -0000
 @@ -810,6 +810,7 @@
  	int flags = 0;	/* prerequisites */
  	ipfw_insn_log *logptr = NULL; /* set if we find an O_LOG */
  	int or_block = 0;	/* we are in an or block */
 +	int twidth = 0;		/* timestamp column width */
  
  	u_int32_t set_disable = rule->set_disable;
  
 @@ -825,15 +826,23 @@
  		printf("%10qu %10qu ", rule->pcnt, rule->bcnt);
  
  	if (do_time) {
 +		char timestr[30];
 +
 +		if (twidth == 0) {
 +			time_t t = 0;
 +
 +			strcpy(timestr, ctime(&t));
 +			*strchr(timestr, '\n') = '\0';
 +			twidth = strlen(timestr);
 +		}
  		if (rule->timestamp) {
 -			char timestr[30];
  			time_t t = _long_to_time(rule->timestamp);
  
  			strcpy(timestr, ctime(&t));
  			*strchr(timestr, '\n') = '\0';
  			printf("%s ", timestr);
  		} else {
 -			printf("			 ");
 +			printf("%*s ", twidth, " ");
  		}
  	}
  
 %%%

From: Chris Pepper <pepper@reppep.com>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org, Luigi Rizzo <luigi@freebsd.org>
Subject: Re: kern/44843: ipfw -t l doesn't align columns quite right
Date: Mon, 4 Nov 2002 09:26:48 -0500

 	Sorry, I'm using ipfw1 -- isn't this for v2?
 
 
 						Chris
 
 At 11:19 AM +0200 2002/11/04, Giorgos Keramidas wrote:
 >On 2002-11-01 22:46, Chris Pepper <pepper@reppep.com> wrote:
 >>  "ipfw -t l" doesn't align columns very well.
 >
 >>  [www:~] root# ipfw -t l
 >>  00100 Fri Nov  1 22:40:38 2002 allow ip from any to any via lo0
 >>  00200                    deny ip from any to 127.0.0.0/8
 >
 >Can you try the following patch?  It seems to fix the problem here.
 >
 >%%%
 >Index: ipfw2.c
 >===================================================================
 >RCS file: /home/ncvs/src/sbin/ipfw/ipfw2.c,v
 >retrieving revision 1.14
 >diff -u -r1.14 ipfw2.c
 >--- ipfw2.c	24 Oct 2002 18:04:44 -0000	1.14
 >+++ ipfw2.c	4 Nov 2002 03:58:37 -0000
 >@@ -810,6 +810,7 @@
 >  	int flags = 0;	/* prerequisites */
 >  	ipfw_insn_log *logptr = NULL; /* set if we find an O_LOG */
 >  	int or_block = 0;	/* we are in an or block */
 >+	int twidth = 0;		/* timestamp column width */
 >
 >  	u_int32_t set_disable = rule->set_disable;
 >
 >@@ -825,15 +826,23 @@
 >  		printf("%10qu %10qu ", rule->pcnt, rule->bcnt);
 >
 >  	if (do_time) {
 >+		char timestr[30];
 >+
 >+		if (twidth == 0) {
 >+			time_t t = 0;
 >+
 >+			strcpy(timestr, ctime(&t));
 >+			*strchr(timestr, '\n') = '\0';
 >+			twidth = strlen(timestr);
 >+		}
 >  		if (rule->timestamp) {
 >-			char timestr[30];
 >  			time_t t = _long_to_time(rule->timestamp);
 >
 >  			strcpy(timestr, ctime(&t));
 >  			*strchr(timestr, '\n') = '\0';
 >  			printf("%s ", timestr);
 >  		} else {
 >-			printf("			 ");
 >+			printf("%*s ", twidth, " ");
 >  		}
 >  	}
 >
 >%%%
 
 
 -- 
 Chris Pepper:               <http://www.reppep.com/~pepper/>
 Rockefeller University:     <http://www.rockefeller.edu/>

From: Giorgos Keramidas <keramida@freebsd.org>
To: Chris Pepper <pepper@reppep.com>
Cc: bug-followup@freebsd.org, Luigi Rizzo <luigi@freebsd.org>
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 <pepper@reppep.com> 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, " ");
  		}
  	}
  
 %%%

From: Chris Pepper <pepper@reppep.com>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org, Luigi Rizzo <luigi@freebsd.org>
Subject: Re: kern/44843: ipfw -t l doesn't align columns quite right
Date: Mon, 4 Nov 2002 21:28:43 -0500

 	Looks much better, thanks.
 
 
 						Chris
 
 At 5:17 PM +0200 2002/11/04, Giorgos Keramidas wrote:
 >On 2002-11-04 09:26, Chris Pepper <pepper@reppep.com> 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, " ");
 >  		}
 >  	}
 >
 >%%%
 
 
 -- 
 Chris Pepper:               <http://www.reppep.com/~pepper/>
 Rockefeller University:     <http://www.rockefeller.edu/>
State-Changed-From-To: open->patched 
State-Changed-By: keramida 
State-Changed-When: Mon Nov 4 18:57:24 PST 2002 
State-Changed-Why:  
I just fixed this on 4.x.  The same change neds to be done in current, 
but a little differently.  I'll merge this and pending RE approval and 
Luigi's review will do the same change. 

Thanks for the report :) 


Responsible-Changed-From-To: freebsd-bugs->keramida 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Mon Nov 4 18:57:24 PST 2002 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=44843 
State-Changed-From-To: patched->closed 
State-Changed-By: keramida 
State-Changed-When: Sat Dec 14 15:47:40 PST 2002 
State-Changed-Why:  
I've already fixed this. -stable first, -current a bit later, 
and forgot to close the PR. 

Thanks for submitting a very useful bug report. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44843 
>Unformatted:
