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.6 1994/09/21 01:52:58 paulus Exp $";
37 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <netinet/in_systm.h>
46 #include <netinet/ip.h>
47 #include <netinet/ip_var.h>
49 #include <net/ppp_defs.h>
52 #include <net/if_ppp.h>
56 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
57 #include <sys/stream.h>
58 #include <net/ppp_str.h>
62 unsigned interval = 5;
64 int s; /* socket file descriptor */
65 int signalled; /* set if alarm goes off "early" */
67 extern char *malloc();
68 void catchalarm __P((int));
76 if (strcmp(argv[0], "-v") == 0) {
81 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
82 isdigit(argv[1][0])) {
83 interval = atoi(argv[1]);
90 if (isdigit(argv[0][0])) {
99 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
100 perror("couldn't create IP socket");
109 fprintf(stderr, "Usage: pppstats [-v] [-i interval] [unit]\n");
113 #define V(offset) (line % 20? req.stats.offset - osc.offset: req.stats.offset)
116 * Print a running summary of interface statistics.
117 * Repeat display every interval seconds, showing statistics
118 * collected over that interval. Assumes that interval is non-zero.
119 * First line printed at top of screen is always cumulative.
123 register int line = 0;
125 struct ifpppstatsreq req;
126 struct ppp_stats osc;
128 bzero(&osc, sizeof(osc));
130 sprintf(req.ifr_name, "ppp%d", unit);
132 if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
134 fprintf(stderr, "pppstats: kernel support missing\n");
136 perror("ioctl(SIOCGPPPSTATS)");
139 (void)signal(SIGALRM, catchalarm);
141 (void)alarm(interval);
143 if ((line % 20) == 0) {
144 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
145 "in", "pack", "comp", "uncomp", "err");
147 printf(" %6.6s %6.6s", "toss", "ip");
148 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
149 "out", "pack", "comp", "uncomp", "ip");
151 printf(" %6.6s %6.6s", "search", "miss");
155 printf("%6d %6d %6d %6d %6d", V(p.ppp_ibytes),
156 V(p.ppp_ipackets), V(vj.vjs_compressedin),
157 V(vj.vjs_uncompressedin), V(vj.vjs_errorin));
159 printf(" %6d %6d", V(vj.vjs_tossed),
160 V(p.ppp_ipackets) - V(vj.vjs_compressedin) -
161 V(vj.vjs_uncompressedin) - V(vj.vjs_errorin));
162 printf(" | %6d %6d %6d %6d %6d", V(p.ppp_obytes),
163 V(p.ppp_opackets), V(vj.vjs_compressed),
164 V(vj.vjs_packets) - V(vj.vjs_compressed),
165 V(p.ppp_opackets) - V(vj.vjs_packets));
167 printf(" %6d %6d", V(vj.vjs_searches), V(vj.vjs_misses));
173 oldmask = sigblock(sigmask(SIGALRM));
179 (void)alarm(interval);
185 * Called if an interval expires before sidewaysintpr has completed a loop.
186 * Sets a flag to not wait for the alarm.