From pherman@tick.sc.omation.com  Wed Jul 25 12:39:54 2001
Return-Path: <pherman@tick.sc.omation.com>
Received: from iatl0x01.coxmail.com (iatl0x02.coxmail.com [206.157.225.11])
	by hub.freebsd.org (Postfix) with ESMTP id 8466937B403
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 25 Jul 2001 12:39:54 -0700 (PDT)
	(envelope-from pherman@tick.sc.omation.com)
Received: from tick.sc.omation.com ([64.58.167.31]) by iatl0x01.coxmail.com
          (InterMail vK.4.03.02.00 201-232-124 license eaa2928f5bcba31507d4d280f1027278)
          with ESMTP
          id <20010725193952.CCEJ27239.iatl0x01@tick.sc.omation.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Wed, 25 Jul 2001 15:39:52 -0400
Received: (from pherman@localhost)
	by tick.sc.omation.com (8.11.3/8.11.3) id f6PJdqX06597;
	Wed, 25 Jul 2001 12:39:52 -0700 (PDT)
	(envelope-from pherman)
Message-Id: <200107251939.f6PJdqX06597@tick.sc.omation.com>
Date: Wed, 25 Jul 2001 12:39:52 -0700 (PDT)
From: pherman@frenchfries.net
Reply-To: pherman@frenchfries.net
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: sockstat broken on alpha [patch]
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29231
>Category:       alpha
>Synopsis:       sockstat broken on alpha [patch]
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mjacob
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 25 12:40:07 PDT 2001
>Closed-Date:    Mon Jul 30 11:06:26 PDT 2001
>Last-Modified:  Mon Jul 30 11:06:41 PDT 2001
>Originator:     Paul Herman <pherman@frenchfries.net>
>Release:        FreeBSD 4.3-RELEASE alpha
>Organization:
>Environment:
System: FreeBSD tick.sc.omation.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Tue Jun 5 12:34:59 PDT 2001 root@fw1.sc.omation.com:/usr/src/sys/compile/fw1 alpha


	
>Description:

   sockstat prints only "?" for protocols & addresses when run on
   a 64-bit OS.

>How-To-Repeat:

  12:32:05{{ttyp0}pherman@arthur}~//> sockstat | head
  USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS 
  root     xterm    32538    3 ?      ?                     ?               
  root     sshd     32537    3 ?      ?                     ?               
  root     sshd     32537    4 ?      ?                     ?                
  root     sshd     32537    6 ?      ?                     ?               
  bind     named    28544    4 ?      ?                     ?               

>Fix:

   The reason is because the socket addresses printed by "netstat -A"
   are 64-bit u_long on a 64-bit platform.  fstat, however, prints them
   as ints which are always 32-bit.  A second problem is that
   sockstat.pl is hardcoded to expect only 8-byte socket addresses.

   The following patch for -STABLE fixes this issue:

Index: usr.bin/fstat/fstat.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/fstat/fstat.c,v
retrieving revision 1.21.2.3
diff -u -r1.21.2.3 fstat.c
--- usr.bin/fstat/fstat.c	2000/12/05 09:43:11	1.21.2.3
+++ usr.bin/fstat/fstat.c	2001/07/25 18:04:22
@@ -664,7 +664,7 @@
 		goto bad;
 	}
 
-	printf("* pipe %8x <-> %8x", (int)pi, (int)pip.pipe_peer);
+	printf("* pipe %8lx <-> %8lx", (u_long)pi, (u_long)pip.pipe_peer);
 	printf(" %6d", (int)pip.pipe_buffer.cnt);
 	rw[0] = '\0';
 	if (flag & FREAD)
@@ -762,16 +762,16 @@
 					    (void *)so.so_pcb);
 					goto bad;
 				}
-				printf(" %x", (int)inpcb.inp_ppcb);
+				printf(" %lx", (u_long)inpcb.inp_ppcb);
 			}
 		}
 		else if (so.so_pcb)
-			printf(" %x", (int)so.so_pcb);
+			printf(" %lx", (u_long)so.so_pcb);
 		break;
 	case AF_UNIX:
 		/* print address of pcb and connected pcb */
 		if (so.so_pcb) {
-			printf(" %x", (int)so.so_pcb);
+			printf(" %lx", (u_long)so.so_pcb);
 			if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb,
 			    sizeof(struct unpcb)) != sizeof(struct unpcb)){
 				dprintf(stderr, "can't read unpcb at %p\n",
@@ -788,14 +788,14 @@
 				if (!(so.so_state & SS_CANTSENDMORE))
 					*cp++ = '>';
 				*cp = '\0';
-				printf(" %s %x", shoconn,
-				    (int)unpcb.unp_conn);
+				printf(" %s %lx", shoconn,
+				    (u_long)unpcb.unp_conn);
 			}
 		}
 		break;
 	default:
 		/* print protocol number and socket address */
-		printf(" %d %x", proto.pr_protocol, (int)sock);
+		printf(" %d %lx", proto.pr_protocol, (u_long)sock);
 	}
 	printf("\n");
 	return;
Index: usr.bin/sockstat/sockstat.pl
===================================================================
RCS file: /home/ncvs/src/usr.bin/sockstat/sockstat.pl,v
retrieving revision 1.6.2.4
diff -u -r1.6.2.4 sockstat.pl
--- usr.bin/sockstat/sockstat.pl	2001/03/22 13:49:51	1.6.2.4
+++ usr.bin/sockstat/sockstat.pl	2001/07/25 19:15:26
@@ -57,7 +57,7 @@
 	die("exec(netstat): $!\n");
     }
     while ($line = <PIPE>) {
-	next unless ($line =~ m/^[0-9a-f]{8} /);
+	next unless ($line =~ m/^[0-9a-f]{8} /) || ($line =~ m/^[0-9a-f]{16} /);
 	chomp($line);
 	@fields = split(' ', $line);
 	$netstat{$fields[0]} = [ @fields ];
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-alpha->mjacob 
Responsible-Changed-By: mjacob 
Responsible-Changed-When: Wed Jul 25 13:25:31 PDT 2001 
Responsible-Changed-Why:  
I'll take it. 
. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29231 

From: Matthew Jacob <mjacob@feral.com>
To: pherman@frenchfries.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: alpha/29231: sockstat broken on alpha [patch]
Date: Wed, 25 Jul 2001 13:24:57 -0700 (PDT)

 Thanks. Looks good and will check the changes into -current and this will
 trickle to -stable in a few weeks.
 
 
 On Wed, 25 Jul 2001 pherman@frenchfries.net wrote:
 
 > 
 > >Number:         29231
 > >Category:       alpha
 > >Synopsis:       sockstat broken on alpha [patch]
 > >Confidential:   no
 > >Severity:       serious
 > >Priority:       medium
 > >Responsible:    freebsd-alpha
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          sw-bug
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Wed Jul 25 12:40:07 PDT 2001
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Paul Herman <pherman@frenchfries.net>
 > >Release:        FreeBSD 4.3-RELEASE alpha
 > >Organization:
 > >Environment:
 > System: FreeBSD tick.sc.omation.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Tue Jun 5 12:34:59 PDT 2001 root@fw1.sc.omation.com:/usr/src/sys/compile/fw1 alpha
 > 
 > 
 > 	
 > >Description:
 > 
 >    sockstat prints only "?" for protocols & addresses when run on
 >    a 64-bit OS.
 > 
 > >How-To-Repeat:
 > 
 >   12:32:05{{ttyp0}pherman@arthur}~//> sockstat | head
 >   USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS 
 >   root     xterm    32538    3 ?      ?                     ?               
 >   root     sshd     32537    3 ?      ?                     ?               
 >   root     sshd     32537    4 ?      ?                     ?                
 >   root     sshd     32537    6 ?      ?                     ?               
 >   bind     named    28544    4 ?      ?                     ?               
 > 
 > >Fix:
 > 
 >    The reason is because the socket addresses printed by "netstat -A"
 >    are 64-bit u_long on a 64-bit platform.  fstat, however, prints them
 >    as ints which are always 32-bit.  A second problem is that
 >    sockstat.pl is hardcoded to expect only 8-byte socket addresses.
 > 
 >    The following patch for -STABLE fixes this issue:
 > 
 > Index: usr.bin/fstat/fstat.c
 > ===================================================================
 > RCS file: /home/ncvs/src/usr.bin/fstat/fstat.c,v
 > retrieving revision 1.21.2.3
 > diff -u -r1.21.2.3 fstat.c
 > --- usr.bin/fstat/fstat.c	2000/12/05 09:43:11	1.21.2.3
 > +++ usr.bin/fstat/fstat.c	2001/07/25 18:04:22
 > @@ -664,7 +664,7 @@
 >  		goto bad;
 >  	}
 >  
 > -	printf("* pipe %8x <-> %8x", (int)pi, (int)pip.pipe_peer);
 > +	printf("* pipe %8lx <-> %8lx", (u_long)pi, (u_long)pip.pipe_peer);
 >  	printf(" %6d", (int)pip.pipe_buffer.cnt);
 >  	rw[0] = '\0';
 >  	if (flag & FREAD)
 > @@ -762,16 +762,16 @@
 >  					    (void *)so.so_pcb);
 >  					goto bad;
 >  				}
 > -				printf(" %x", (int)inpcb.inp_ppcb);
 > +				printf(" %lx", (u_long)inpcb.inp_ppcb);
 >  			}
 >  		}
 >  		else if (so.so_pcb)
 > -			printf(" %x", (int)so.so_pcb);
 > +			printf(" %lx", (u_long)so.so_pcb);
 >  		break;
 >  	case AF_UNIX:
 >  		/* print address of pcb and connected pcb */
 >  		if (so.so_pcb) {
 > -			printf(" %x", (int)so.so_pcb);
 > +			printf(" %lx", (u_long)so.so_pcb);
 >  			if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb,
 >  			    sizeof(struct unpcb)) != sizeof(struct unpcb)){
 >  				dprintf(stderr, "can't read unpcb at %p\n",
 > @@ -788,14 +788,14 @@
 >  				if (!(so.so_state & SS_CANTSENDMORE))
 >  					*cp++ = '>';
 >  				*cp = '\0';
 > -				printf(" %s %x", shoconn,
 > -				    (int)unpcb.unp_conn);
 > +				printf(" %s %lx", shoconn,
 > +				    (u_long)unpcb.unp_conn);
 >  			}
 >  		}
 >  		break;
 >  	default:
 >  		/* print protocol number and socket address */
 > -		printf(" %d %x", proto.pr_protocol, (int)sock);
 > +		printf(" %d %lx", proto.pr_protocol, (u_long)sock);
 >  	}
 >  	printf("\n");
 >  	return;
 > Index: usr.bin/sockstat/sockstat.pl
 > ===================================================================
 > RCS file: /home/ncvs/src/usr.bin/sockstat/sockstat.pl,v
 > retrieving revision 1.6.2.4
 > diff -u -r1.6.2.4 sockstat.pl
 > --- usr.bin/sockstat/sockstat.pl	2001/03/22 13:49:51	1.6.2.4
 > +++ usr.bin/sockstat/sockstat.pl	2001/07/25 19:15:26
 > @@ -57,7 +57,7 @@
 >  	die("exec(netstat): $!\n");
 >      }
 >      while ($line = <PIPE>) {
 > -	next unless ($line =~ m/^[0-9a-f]{8} /);
 > +	next unless ($line =~ m/^[0-9a-f]{8} /) || ($line =~ m/^[0-9a-f]{16} /);
 >  	chomp($line);
 >  	@fields = split(' ', $line);
 >  	$netstat{$fields[0]} = [ @fields ];
 > >Release-Note:
 > >Audit-Trail:
 > >Unformatted:
 > 
 > To Unsubscribe: send mail to majordomo@FreeBSD.org
 > with "unsubscribe freebsd-alpha" in the body of the message
 > 
 
State-Changed-From-To: open->closed 
State-Changed-By: mjacob 
State-Changed-When: Mon Jul 30 11:06:26 PDT 2001 
State-Changed-Why:  
Fixed in -current && -stable 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29231 
>Unformatted:
