2 * print PPP statistics:
3 * pppstats [-i interval] [-v] [interface] [system] [core]
5 * Brad Parker (brad@cayman.com) 6/92
7 * from the original "slstats" by Van Jaconson
9 * Copyright (c) 1989 Regents of the University of California.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms are permitted
13 * provided that the above copyright notice and this paragraph are
14 * duplicated in all such forms and that any documentation,
15 * advertising materials, and other materials related to such
16 * distribution and use acknowledge that the software was developed
17 * by the University of California, Berkeley. The name of the
18 * University may not be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
25 * - Initial distribution.
29 static char rcsid[] = "$Id: pppstats.c,v 1.1 1993/11/11 03:54:25 paulus Exp $";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
38 #include <machine/pte.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/ip.h>
52 #include <netinet/ip_var.h>
55 #include <net/slcompress.h>
56 #include <net/if_ppp.h>
59 #include <sys/stream.h>
88 char *system = "/vmunix";
91 char *system = "/netbsd";
93 char *system = "/386bsd";
98 char *kmemf = "/dev/kmem";
104 unsigned interval = 5;
107 extern char *malloc();
116 if (strcmp(argv[0], "-v") == 0) {
121 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
122 isdigit(argv[1][0])) {
123 interval = atoi(argv[1]);
130 if (isdigit(argv[0][0])) {
131 unit = atoi(argv[0]);
149 if (nlist(system, nl) < 0 || nl[0].n_type == 0) {
150 fprintf(stderr, "%s: no namelist\n", system);
153 kmem = open(kmemf, O_RDONLY);
161 Sysmap = (struct pte *)
162 malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
164 fputs("netstat: can't get memory for Sysmap.\n", stderr);
167 off = nl[N_SYSMAP].n_value & ~KERNBASE;
168 (void)lseek(kmem, off, L_SET);
169 (void)read(kmem, (char *)Sysmap,
170 (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
175 if ((kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, NULL)) == NULL) {
181 if (kvm_openfiles(system, kmemf, (char *)0) == -1) {
182 fprintf(stderr, "kvm_openfiles: %s", kvm_geterr());
188 if (kvm_nlist(kd, nl)) {
192 fprintf(stderr, "pppstats: can't find symbols in nlist\n");
202 * Seek into the kernel for a value.
205 klseek(fd, base, off)
212 base = ctob(Sysmap[btop(base)].pg_pfnum) + (base & PGOFSET);
214 return (lseek(fd, base, off));
220 fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n");
224 u_char signalled; /* set if alarm goes off "early" */
226 #define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
229 * Print a running summary of interface statistics.
230 * Repeat display every interval seconds, showing statistics
231 * collected over that interval. Assumes that interval is non-zero.
232 * First line printed at top of screen is always cumulative.
236 register int line = 0;
239 void catchalarm(int);
245 #define STRUCT struct ppp_if_info
247 #define STRUCT struct ppp_softc
252 nl[N_SOFTC].n_value += unit * sizeof(struct ppp_softc);
253 sc = (STRUCT *)malloc(sizeof(STRUCT));
254 osc = (STRUCT *)malloc(sizeof(STRUCT));
256 bzero((char *)osc, sizeof(STRUCT));
260 if (klseek(kmem, (off_t)nl[N_SOFTC].n_value, 0) < 0)
263 if (read(kmem, (char *)sc, sizeof(STRUCT)) <= 0)
267 if (kvm_read(kd, nl[N_SOFTC].n_value,
269 if (kvm_read(nl[N_SOFTC].n_value,
271 sc, sizeof(STRUCT)) !=
276 (void)signal(SIGALRM, catchalarm);
278 (void)alarm(interval);
280 if ((line % 20) == 0) {
281 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
282 "in", "pack", "comp", "uncomp", "err");
284 printf(" %6.6s %6.6s", "toss", "ip");
285 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
286 "out", "pack", "comp", "uncomp", "ip");
288 printf(" %6.6s %6.6s", "search", "miss");
293 #define COMP pii_sc_comp
294 #define STATS pii_ifnet
300 printf("%6d %6d %6d %6d %6d",
306 V(STATS.if_ipackets),
307 V(COMP.sls_compressedin),
308 V(COMP.sls_uncompressedin),
309 V(COMP.sls_errorin));
313 V(STATS.if_ipackets) -
314 V(COMP.sls_compressedin) -
315 V(COMP.sls_uncompressedin) -
316 V(COMP.sls_errorin));
317 printf(" | %6d %6d %6d %6d %6d",
323 V(STATS.if_opackets),
324 V(COMP.sls_compressed),
325 V(COMP.sls_packets) - V(COMP.sls_compressed),
326 V(STATS.if_opackets) - V(COMP.sls_packets));
329 V(COMP.sls_searches),
335 oldmask = sigblock(sigmask(SIGALRM));
341 (void)alarm(interval);
342 bcopy((char *)sc, (char *)osc, sizeof(STRUCT));
347 * Called if an interval expires before sidewaysintpr has completed a loop.
348 * Sets a flag to not wait for the alarm.