2 * print PPP statistics:
3 * pppstats [-i interval] [-v] [-r] [-c] [interface]
5 * -i <update interval in seconds>
6 * -v Verbose mode for default display
7 * -r Show compression ratio in default display
8 * -c Show Compression statistics instead of default display
12 * perkins@cps.msu.edu: Added compression statistics and alternate
15 * Brad Parker (brad@cayman.com) 6/92
17 * from the original "slstats" by Van Jaconson
19 * Copyright (c) 1989 Regents of the University of California.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms are permitted
23 * provided that the above copyright notice and this paragraph are
24 * duplicated in all such forms and that any documentation,
25 * advertising materials, and other materials related to such
26 * distribution and use acknowledge that the software was developed
27 * by the University of California, Berkeley. The name of the
28 * University may not be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
32 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
34 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
35 * - Initial distribution.
39 static char rcsid[] = "$Id: pppstats.c,v 1.8 1995/05/02 05:51:22 paulus Exp $";
47 #include <sys/param.h>
49 #include <sys/types.h>
50 #include <sys/ioctl.h>
51 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/ip.h>
57 #include <netinet/ip_var.h>
59 #include <net/ppp_defs.h>
62 #include <net/if_ppp.h>
66 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
67 #include <sys/stream.h>
68 #include <net/ppp_str.h>
71 int vflag, rflag, cflag;
72 unsigned interval = 5;
74 int s; /* socket file descriptor */
75 int signalled; /* set if alarm goes off "early" */
77 extern char *malloc();
78 void catchalarm __P((int));
86 if (strcmp(argv[0], "-v") == 0) {
91 if (strcmp(argv[0], "-r") == 0) {
96 if (strcmp(argv[0], "-c") == 0) {
101 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
102 isdigit(argv[1][0])) {
103 interval = atoi(argv[1]);
110 if (isdigit(argv[0][0])) {
111 unit = atoi(argv[0]);
120 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
121 perror("couldn't create IP socket");
130 fprintf(stderr, "Usage: pppstats [-v] [-r] [-c] [-i interval] [unit]\n");
134 #define V(offset) (line % 20? req.stats.offset - osc.offset: req.stats.offset)
135 #define W(offset) (line % 20? creq.stats.offset - csc.offset: creq.stats.offset)
137 #define CRATE(comp, inc, unc) ((unc) == 0? 0.0: \
138 1.0 - (double)((comp) + (inc)) / (unc))
141 * Print a running summary of interface statistics.
142 * Repeat display every interval seconds, showing statistics
143 * collected over that interval. Assumes that interval is non-zero.
144 * First line printed at top of screen is always cumulative.
148 register int line = 0;
150 struct ifpppstatsreq req;
151 struct ifpppcstatsreq creq;
152 struct ppp_stats osc;
153 struct ppp_comp_stats csc;
155 bzero(&osc, sizeof(osc));
156 bzero(&csc, sizeof(csc));
158 sprintf(req.ifr_name, "ppp%d", unit);
159 sprintf(creq.ifr_name, "ppp%d", unit);
161 if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
163 fprintf(stderr, "pppstats: kernel support missing\n");
165 perror("ioctl(SIOCGPPPSTATS)");
168 if ((cflag || rflag) && ioctl(s, SIOCGPPPCSTATS, &creq) < 0) {
169 if (errno == ENOTTY) {
170 fprintf(stderr, "pppstats: no kernel compression support\n");
175 perror("ioctl(SIOCGPPPCSTATS)");
179 (void)signal(SIGALRM, catchalarm);
181 (void)alarm(interval);
183 if ((line % 20) == 0) {
188 printf("%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
189 "ubyte", "upack", "cbyte", "cpack", "ibyte", "ipack", "ratio");
190 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
191 "ubyte", "upack", "cbyte", "cpack", "ibyte", "ipack", "ratio");
195 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
196 "in", "pack", "comp", "uncomp", "err");
198 printf(" %6.6s %6.6s", "toss", "ip");
200 printf(" %6.6s %6.6s", "ratio", "ubyte");
201 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
202 "out", "pack", "comp", "uncomp", "ip");
204 printf(" %6.6s %6.6s", "search", "miss");
206 printf(" %6.6s %6.6s", "ratio", "ubyte");
209 bzero(&osc, sizeof(osc));
210 bzero(&csc, sizeof(csc));
214 printf("%6d %6d %6d %6d %6d %6d %6.2f",
221 W(d.ratio) == 0? 0.0: 1 - 1.0 / W(d.ratio) * 256.0);
223 printf(" | %6d %6d %6d %6d %6d %6d %6.2f",
230 W(d.ratio) == 0? 0.0: 1 - 1.0 / W(d.ratio) * 256.0);
235 printf("%6d %6d %6d %6d %6d",
237 V(p.ppp_ipackets), V(vj.vjs_compressedin),
238 V(vj.vjs_uncompressedin), V(vj.vjs_errorin));
240 printf(" %6d %6d", V(vj.vjs_tossed),
241 V(p.ppp_ipackets) - V(vj.vjs_compressedin) -
242 V(vj.vjs_uncompressedin) - V(vj.vjs_errorin));
245 CRATE(W(d.comp_bytes), W(d.unc_bytes), W(d.unc_bytes)),
247 printf(" | %6d %6d %6d %6d %6d", V(p.ppp_obytes),
248 V(p.ppp_opackets), V(vj.vjs_compressed),
249 V(vj.vjs_packets) - V(vj.vjs_compressed),
250 V(p.ppp_opackets) - V(vj.vjs_packets));
252 printf(" %6d %6d", V(vj.vjs_searches), V(vj.vjs_misses));
256 CRATE(W(d.comp_bytes), W(d.unc_bytes), W(d.unc_bytes)),
267 oldmask = sigblock(sigmask(SIGALRM));
273 (void)alarm(interval);
280 * Called if an interval expires before sidewaysintpr has completed a loop.
281 * Sets a flag to not wait for the alarm.