2 * print serial line IP statistics:
3 * slstat [-i interval] [-v] [interface]
5 * Copyright (c) 1989, 1990, 1991, 1992 Regents of the University of
6 * California. All rights reserved.
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the University of California, Berkeley. The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * Van Jacobson (van@ee.lbl.gov), Dec 31, 1989:
21 * - Initial distribution.
25 static const char rcsid[] =
29 #include <sys/param.h>
30 #include <sys/socket.h>
31 #include <sys/sysctl.h>
44 #include <net/if_var.h>
45 #include <net/if_mib.h>
46 #include <net/if_types.h>
47 #include <netinet/in.h>
48 #include <netinet/in_systm.h>
49 #include <netinet/ip.h>
50 #include <net/slcompress.h>
51 #include <net/if_slvar.h>
53 static void usage(void);
54 static void intpr(void);
55 static void catchalarm(int);
57 #define INTERFACE_PREFIX "sl%d"
58 char interface[IFNAMSIZ];
62 unsigned interval = 5;
67 main(int argc, char *argv[])
73 struct ifmibdata ifmd;
75 while ((c = getopt(argc, argv, "vri:")) != -1) {
84 interval = atoi(optarg);
93 sprintf(interface, INTERFACE_PREFIX, unit);
94 else if (isdigit(argv[optind][0])) {
95 unit = atoi(argv[optind]);
98 sprintf(interface, INTERFACE_PREFIX, unit);
99 } else if (strncmp(argv[optind], "sl", 2) == 0
100 && isdigit(argv[optind][2])
101 && sscanf(argv[optind], "sl%d", &unit) == 1) {
102 strncpy(interface, argv[optind], IFNAMSIZ);
108 name[2] = NETLINK_GENERIC;
109 name[3] = IFMIB_SYSTEM;
110 name[4] = IFMIB_IFCOUNT;
111 len = sizeof maxifno;
112 if (sysctl(name, 5, &maxifno, &len, 0, 0) < 0)
113 err(1, "sysctl net.link.generic.system.ifcount");
115 name[3] = IFMIB_IFDATA;
116 name[5] = IFDATA_GENERAL;
121 if (sysctl(name, 6, &ifmd, &len, 0, 0) < 0) {
127 if (strncmp(interface, ifmd.ifmd_name, IFNAMSIZ) == 0
128 && ifmd.ifmd_data.ifi_type == IFT_SLIP) {
133 errx(1, "interface %s does not exist", interface);
137 name[5] = IFDATA_LINKSPECIFIC;
142 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
143 (rflag ? interval : 1)) : sc->offset)
144 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
149 fprintf(stderr, "usage: slstat [-i interval] [-vr] [unit]\n");
153 u_char signalled; /* set if alarm goes off "early" */
156 * Print a running summary of interface statistics.
157 * Repeat display every interval seconds, showing statistics
158 * collected over that interval. Assumes that interval is non-zero.
159 * First line printed at top of screen is always cumulative.
164 register int line = 0;
166 struct sl_softc *sc, *osc;
169 sc = (struct sl_softc *)malloc(AMT);
170 osc = (struct sl_softc *)malloc(AMT);
171 bzero((char *)osc, AMT);
175 if (sysctl(name, 6, sc, &len, 0, 0) < 0 &&
176 (errno != ENOMEM || len != AMT))
177 err(1, "sysctl linkspecific");
179 (void)signal(SIGALRM, catchalarm);
181 (void)alarm(interval);
183 if ((line % 20) == 0) {
184 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
185 "in", "pack", "comp", "uncomp", "unknwn");
187 printf(" %6.6s %6.6s %6.6s",
188 "toss", "other", "err");
189 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
190 "out", "pack", "comp", "uncomp", "other");
192 printf(" %6.6s %6.6s %6.6s %6.6s",
193 "search", "miss", "err", "coll");
196 printf("%8lu %6ld %6u %6u %6u",
198 V(sc_if.if_ipackets),
199 V(sc_comp.sls_compressedin),
200 V(sc_comp.sls_uncompressedin),
201 V(sc_comp.sls_errorin));
203 printf(" %6u %6lu %6lu",
204 V(sc_comp.sls_tossed),
205 V(sc_if.if_ipackets) -
206 V(sc_comp.sls_compressedin) -
207 V(sc_comp.sls_uncompressedin) -
208 V(sc_comp.sls_errorin),
209 V(sc_if.if_ierrors));
210 printf(" | %8lu %6ld %6u %6u %6lu",
211 V(sc_if.if_obytes) / (rflag ? interval : 1),
212 V(sc_if.if_opackets),
213 V(sc_comp.sls_compressed),
214 V(sc_comp.sls_packets) - V(sc_comp.sls_compressed),
215 V(sc_if.if_opackets) - V(sc_comp.sls_packets));
217 printf(" %6u %6u %6lu %6lu",
218 V(sc_comp.sls_searches),
219 V(sc_comp.sls_misses),
221 V(sc_if.if_collisions));
225 oldmask = sigblock(sigmask(SIGALRM));
231 (void)alarm(interval);
232 bcopy((char *)sc, (char *)osc, AMT);
237 * Called if an interval expires before sidewaysintpr has completed a loop.
238 * Sets a flag to not wait for the alarm.