Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1002/1

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Add -p option.
 [rsc] --rw-rw-r-- M 733409 glenda sys 942 Oct  2 08:17 sys/man/1/netstat
	/n/sourcesdump/2005/1002/plan9/sys/man/1/netstat:6,11 - 
	/n/sourcesdump/2005/1003/plan9/sys/man/1/netstat:6,14
	  [
	  .B -in
	  ] [
	+ .B -p
	+ .I proto
	+ ] [
	  .I netmtpt
	  ]
	  .SH DESCRIPTION
	/n/sourcesdump/2005/1002/plan9/sys/man/1/netstat:14,36 - 
	/n/sourcesdump/2005/1003/plan9/sys/man/1/netstat:17,48
	  .IR netmtpt ,
	  default
	  .BR /net .
	- With the
	- .B \-i
	- option, it reports one line per network interface listing the
	- device, MTU, local address, masl, remote address, packets in,
	- packets out, errors in, and errors out for this interface.
	  For
	  .I IP
	- connections
	+ connections,
	  .I netstat
	- reports the connection number, user,
	+ reports the protocol, connection number, user,
	  connection state, local port, remote port and
	  remote address.
	- .I Netstat
	- looks up port numbers and addresses in the network databases
	- to print symbolic names if possible, but if the
	+ .PP
	+ The options are:
	+ .TP
	+ .B -i
	+ Instead of the usual listing, print one line per network interface.
	+ Each line gives the
	+ device, MTU, local address, mask, remote address, packets in,
	+ packets out, errors in, and errors out for this interface.
	+ .TP
	  .B -n
	- option is specified, it does not translate to symbolic form.
	+ By default,
	+ .I netstat
	+ looks up port numbers and addresses in the network databases
	+ to print symbolic names if possible.
	+ This option disables such translation.
	+ .TP
	+ .B -p
	+ Show only connections with the given protocol.
	+ .PD
	  .SH FILES
	  .B /net/*/*
	  .SH SOURCE
 [rsc] --rw-rw-r-- M 733409 glenda sys 4086 Oct  2 08:17 sys/src/cmd/netstat.c
	/n/sourcesdump/2005/1002/plan9/sys/src/cmd/netstat.c:10,20 - 
	/n/sourcesdump/2005/1003/plan9/sys/src/cmd/netstat.c:10,23
	  
	  Biobuf	out;
	  char	*netroot;
	+ char *proto[20];
	+ int nproto;
	  int	notrans;
	  
	  void
	- usage(void){
	- 	fprint(2, "usage: %s [-in] [network-dir]\n", argv0);
	+ usage(void)
	+ {
	+ 	fprint(2, "usage: %s [-in] [-p proto] [network-dir]\n", argv0);
	  	exits("usage");
	  }
	  
	/n/sourcesdump/2005/1002/plan9/sys/src/cmd/netstat.c:27,37 - 
	/n/sourcesdump/2005/1003/plan9/sys/src/cmd/netstat.c:30,45
	  	char buf[128];
	  
	  	ARGBEGIN{
	+ 	case 'i':
	+ 		justinterfaces = 1;
	+ 		break;
	  	case 'n':
	  		notrans = 1;
	  		break;
	- 	case 'i':
	- 		justinterfaces = 1;
	+ 	case 'p':
	+ 		if(nproto >= nelem(proto))
	+ 			sysfatal("too many protos");
	+ 		proto[nproto++] = EARGF(usage());
	  		break;
	  	default:
	  		usage();
	/n/sourcesdump/2005/1002/plan9/sys/src/cmd/netstat.c:59,73 - 
	/n/sourcesdump/2005/1003/plan9/sys/src/cmd/netstat.c:67,85
	  	if(fd < 0)
	  		sysfatal("open %s: %r", netroot);
	  
	- 	tot = dirreadall(fd, &d);
	- 	for(i=0; i<tot; i++){
	- 		if(strcmp(d[i].name, "ipifc") == 0)
	- 			continue;
	- 		snprint(buf, sizeof buf, "%s/%s/0/local", netroot, d[i].name);
	- 		if(access(buf, 0) >= 0)
	- 			nstat(d[i].name, pip);
	+ 	if(nproto){
	+ 		for(i=0; i<nproto; i++)
	+ 			nstat(proto[i], pip);
	+ 	}else{
	+ 		tot = dirreadall(fd, &d);
	+ 		for(i=0; i<tot; i++){
	+ 			if(strcmp(d[i].name, "ipifc") == 0)
	+ 				continue;
	+ 			snprint(buf, sizeof buf, "%s/%s/0/local", netroot, d[i].name);
	+ 			if(access(buf, 0) >= 0)
	+ 				nstat(d[i].name, pip);
	+ 		}
	  	}
	- 
	  	exits(0);
	  }
	  
 [sys] --rwxrwxr-x M 733409 glenda sys 84664 Oct  2 23:11 386/bin/netstat
	/sys/src/cmd/netstat.c:getport
	/sys/src/cmd/netstat.c:main
	/sys/src/cmd/netstat.c:nstat
	/sys/src/cmd/netstat.c:pip
	/sys/src/cmd/netstat.c:pipifc
	/sys/src/cmd/netstat.c:usage
	/sys/src/libc/9sys/dirread.c:dirread
	/sys/src/libc/9sys/dirread.c:dirreadall
	/sys/src/libc/fmt/fmt.c:_fmtinstall
	/sys/src/libc/port/rune.c:chartorune


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.