2 * print PPP statistics:
3 * pppstats [-i interval] [-v] [interface]
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.5 1994/09/19 04:14:37 paulus Exp $";
37 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/ip_var.h>
48 #include <net/ppp_defs.h>
51 #include <net/if_ppp.h>
55 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
56 #include <sys/stream.h>
57 #include <net/ppp_str.h>
61 unsigned interval = 5;
63 int s; /* socket file descriptor */
64 int signalled; /* set if alarm goes off "early" */
66 extern char *malloc();
67 void catchalarm __P((int));
75 if (strcmp(argv[0], "-v") == 0) {
80 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
81 isdigit(argv[1][0])) {
82 interval = atoi(argv[1]);
89 if (isdigit(argv[0][0])) {
98 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
99 perror("couldn't create IP socket");
108 fprintf(stderr, "Usage: pppstats [-v] [-i interval] [unit]\n");
112 #define V(offset) (line % 20? req.stats.offset - osc.offset: req.stats.offset)
115 * Print a running summary of interface statistics.
116 * Repeat display every interval seconds, showing statistics
117 * collected over that interval. Assumes that interval is non-zero.
118 * First line printed at top of screen is always cumulative.
122 register int line = 0;
124 struct ifpppstatsreq req;
125 struct ppp_stats osc;
127 bzero(&osc, sizeof(osc));
129 sprintf(req.ifr_name, "ppp%d", unit);
131 if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
133 fprintf(stderr, "pppstats: kernel support missing\n");
135 perror("ioctl(SIOCGPPPSTATS)");
138 (void)signal(SIGALRM, catchalarm);
140 (void)alarm(interval);
142 if ((line % 20) == 0) {
143 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
144 "in", "pack", "comp", "uncomp", "err");
146 printf(" %6.6s %6.6s", "toss", "ip");
147 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
148 "out", "pack", "comp", "uncomp", "ip");
150 printf(" %6.6s %6.6s", "search", "miss");
154 printf("%6d %6d %6d %6d %6d", V(p.ppp_ibytes),
155 V(p.ppp_ipackets), V(vj.vjs_compressedin),
156 V(vj.vjs_uncompressedin), V(vj.vjs_errorin));
158 printf(" %6d %6d", V(vj.vjs_tossed),
159 V(p.ppp_ipackets) - V(vj.vjs_compressedin) -
160 V(vj.vjs_uncompressedin) - V(vj.vjs_errorin));
161 printf(" | %6d %6d %6d %6d %6d", V(p.ppp_obytes),
162 V(p.ppp_opackets), V(vj.vjs_compressed),
163 V(vj.vjs_packets) - V(vj.vjs_compressed),
164 V(p.ppp_opackets) - V(vj.vjs_packets));
166 printf(" %6d %6d", V(vj.vjs_searches), V(vj.vjs_misses));
172 oldmask = sigblock(sigmask(SIGALRM));
178 (void)alarm(interval);
184 * Called if an interval expires before sidewaysintpr has completed a loop.
185 * Sets a flag to not wait for the alarm.