Bug 29231

Summary: sockstat broken on alpha [patch]
Product: Base System Reporter: Paul Herman <pherman>
Component: alphaAssignee: Matt Jacob <mjacob>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Paul Herman 2001-07-25 20:40:07 UTC
   sockstat prints only "?" for protocols & addresses when run on
   a 64-bit OS.

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:
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 ?      ?                     ?
Comment 1 mjacob 2001-07-25 21:24:57 UTC
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
>
Comment 2 Matt Jacob freebsd_committer freebsd_triage 2001-07-25 21:25:31 UTC
Responsible Changed
From-To: freebsd-alpha->mjacob

I'll take it. 
.
Comment 3 Matt Jacob freebsd_committer freebsd_triage 2001-07-30 19:06:26 UTC
State Changed
From-To: open->closed

Fixed in -current && -stable