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.2 1993/12/15 05:00:47 paulus Exp $";
32 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/ip.h>
53 #include <netinet/ip_var.h>
56 #include <net/slcompress.h>
57 #include <net/if_ppp.h>
60 #include <sys/stream.h>
61 #include <net/ppp_str.h>
83 char *system = "/vmunix";
85 char *system = _PATH_UNIX;
91 unsigned interval = 5;
94 extern char *malloc();
102 if (strcmp(argv[0], "-v") == 0) {
107 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
108 isdigit(argv[1][0])) {
109 interval = atoi(argv[1]);
116 if (isdigit(argv[0][0])) {
117 unit = atoi(argv[0]);
136 if ((kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, NULL)) == NULL) {
142 if (kvm_openfiles(system, kmemf, (char *)0) == -1) {
143 fprintf(stderr, "kvm_openfiles: %s", kvm_geterr());
149 if (kvm_nlist(kd, nl)) {
153 fprintf(stderr, "pppstats: can't find symbols in nlist\n");
162 fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n");
166 u_char signalled; /* set if alarm goes off "early" */
168 #define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
171 * Print a running summary of interface statistics.
172 * Repeat display every interval seconds, showing statistics
173 * collected over that interval. Assumes that interval is non-zero.
174 * First line printed at top of screen is always cumulative.
178 register int line = 0;
181 void catchalarm(int);
187 #define STRUCT struct ppp_if_info
189 #define STRUCT struct ppp_softc
194 nl[N_SOFTC].n_value += unit * sizeof(struct ppp_softc);
195 sc = (STRUCT *)malloc(sizeof(STRUCT));
196 osc = (STRUCT *)malloc(sizeof(STRUCT));
198 bzero((char *)osc, sizeof(STRUCT));
202 if (kvm_read(kd, nl[N_SOFTC].n_value,
204 if (kvm_read(nl[N_SOFTC].n_value,
206 sc, sizeof(STRUCT)) !=
210 (void)signal(SIGALRM, catchalarm);
212 (void)alarm(interval);
214 if ((line % 20) == 0) {
215 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
216 "in", "pack", "comp", "uncomp", "err");
218 printf(" %6.6s %6.6s", "toss", "ip");
219 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
220 "out", "pack", "comp", "uncomp", "ip");
222 printf(" %6.6s %6.6s", "search", "miss");
227 #define COMP pii_sc_comp
228 #define STATS pii_ifnet
234 printf("%6d %6d %6d %6d %6d",
240 V(STATS.if_ipackets),
241 V(COMP.sls_compressedin),
242 V(COMP.sls_uncompressedin),
243 V(COMP.sls_errorin));
247 V(STATS.if_ipackets) -
248 V(COMP.sls_compressedin) -
249 V(COMP.sls_uncompressedin) -
250 V(COMP.sls_errorin));
251 printf(" | %6d %6d %6d %6d %6d",
257 V(STATS.if_opackets),
258 V(COMP.sls_compressed),
259 V(COMP.sls_packets) - V(COMP.sls_compressed),
260 V(STATS.if_opackets) - V(COMP.sls_packets));
263 V(COMP.sls_searches),
269 oldmask = sigblock(sigmask(SIGALRM));
275 (void)alarm(interval);
276 bcopy((char *)sc, (char *)osc, sizeof(STRUCT));
281 * Called if an interval expires before sidewaysintpr has completed a loop.
282 * Sets a flag to not wait for the alarm.