static char sccsid
[] = "@(#)main.c 4.7 83/03/23";
extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
u_char pr_index
; /* index into nlist of cb head */
u_char pr_sindex
; /* index into nlist of stat block */
u_char pr_wanted
; /* 1 if wanted, 0 otherwise */
int (*pr_cblocks
)(); /* control blocks printing routine */
int (*pr_stats
)(); /* statistics printing routine */
char *pr_name
; /* well-known name */
{ N_TCB
, N_TCPSTAT
, 1, protopr
,
{ N_UDB
, N_UDPSTAT
, 1, protopr
,
char *system
= "/vmunix";
char *kmemf
= "/dev/kmem";
char usage
[] = "[ -Aaihmnrst ] [ interval ] [ system ] [ core ]";
register struct protoent
*p
;
while (argc
> 0 && **argv
== '-') {
for (cp
= &argv
[0][1]; *cp
; cp
++)
printf("usage: %s %s\n", name
, usage
);
if (argc
> 0 && isdigit(argv
[0][0])) {
interval
= atoi(argv
[0]);
fprintf(stderr
, "%s: no namelist\n", system
);
fprintf(stderr
, "cannot open ");
off
= nl
[N_SYSMAP
].n_value
& 0x7fffffff;
nl
[N_SYSSIZE
].n_value
*= 4;
Sysmap
= (struct pte
*)malloc(nl
[N_SYSSIZE
].n_value
);
read(kmem
, Sysmap
, nl
[N_SYSSIZE
].n_value
);
mbpr(nl
[N_MBSTAT
].n_value
);
* Keep file descriptors open to avoid overhead
* of open/close on each call to get* routines.
intpr(interval
, nl
[N_IFNET
].n_value
);
hostpr(nl
[N_HOSTS
].n_value
);
routepr(nl
[N_RTHOST
].n_value
, nl
[N_RTNET
].n_value
);
while (p
= getprotoent()) {
register struct protox
*tp
;
for (tp
= protox
; tp
->pr_name
; tp
++)
if (strcmp(tp
->pr_name
, p
->p_name
) == 0)
if (tp
->pr_name
== 0 || tp
->pr_wanted
== 0)
if (sflag
&& tp
->pr_stats
) {
(*tp
->pr_stats
)(nl
[tp
->pr_sindex
].n_value
, p
->p_name
);
(*tp
->pr_cblocks
)(nl
[tp
->pr_index
].n_value
, p
->p_name
);
* Seek into the kernel for a value.
base
= ctob(Sysmap
[base
>> PGSHIFT
].pg_pfnum
) +