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 __P((void));
54 static void intpr __P((void));
55 static void catchalarm __P((int));
57 #define INTERFACE_PREFIX "sl%d"
58 char interface[IFNAMSIZ];
62 unsigned interval = 5;
75 struct ifmibdata ifmd;
77 while ((c = getopt(argc, argv, "vri:")) != -1) {
86 interval = atoi(optarg);
95 sprintf(interface, INTERFACE_PREFIX, unit);
96 else if (isdigit(argv[optind][0])) {
97 unit = atoi(argv[optind]);
100 sprintf(interface, INTERFACE_PREFIX, unit);
101 } else if (strncmp(argv[optind], "sl", 2) == 0
102 && isdigit(argv[optind][2])
103 && sscanf(argv[optind], "sl%d", &unit) == 1) {
104 strncpy(interface, argv[optind], IFNAMSIZ);
110 name[2] = NETLINK_GENERIC;
111 name[3] = IFMIB_SYSTEM;
112 name[4] = IFMIB_IFCOUNT;
113 len = sizeof maxifno;
114 if (sysctl(name, 5, &maxifno, &len, 0, 0) < 0)
115 err(1, "sysctl net.link.generic.system.ifcount");
117 name[3] = IFMIB_IFDATA;
118 name[5] = IFDATA_GENERAL;
123 if (sysctl(name, 6, &ifmd, &len, 0, 0) < 0) {
129 if (strncmp(interface, ifmd.ifmd_name, IFNAMSIZ) == 0
130 && ifmd.ifmd_data.ifi_type == IFT_SLIP) {
135 errx(1, "interface %s does not exist", interface);
139 name[5] = IFDATA_LINKSPECIFIC;
144 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
145 (rflag ? interval : 1)) : sc->offset)
146 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
151 fprintf(stderr, "usage: slstat [-i interval] [-vr] [unit]\n");
155 u_char signalled; /* set if alarm goes off "early" */
158 * Print a running summary of interface statistics.
159 * Repeat display every interval seconds, showing statistics
160 * collected over that interval. Assumes that interval is non-zero.
161 * First line printed at top of screen is always cumulative.
166 register int line = 0;
168 struct sl_softc *sc, *osc;
171 sc = (struct sl_softc *)malloc(AMT);
172 osc = (struct sl_softc *)malloc(AMT);
173 bzero((char *)osc, AMT);
177 if (sysctl(name, 6, sc, &len, 0, 0) < 0 &&
178 (errno != ENOMEM || len != AMT))
179 err(1, "sysctl linkspecific");
181 (void)signal(SIGALRM, catchalarm);
183 (void)alarm(interval);
185 if ((line % 20) == 0) {
186 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
187 "in", "pack", "comp", "uncomp", "unknwn");
189 printf(" %6.6s %6.6s %6.6s",
190 "toss", "other", "err");
191 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
192 "out", "pack", "comp", "uncomp", "other");
194 printf(" %6.6s %6.6s %6.6s %6.6s",
195 "search", "miss", "err", "coll");
198 printf("%8lu %6ld %6u %6u %6u",
200 V(sc_if.if_ipackets),
201 V(sc_comp.sls_compressedin),
202 V(sc_comp.sls_uncompressedin),
203 V(sc_comp.sls_errorin));
205 printf(" %6u %6lu %6lu",
206 V(sc_comp.sls_tossed),
207 V(sc_if.if_ipackets) -
208 V(sc_comp.sls_compressedin) -
209 V(sc_comp.sls_uncompressedin) -
210 V(sc_comp.sls_errorin),
211 V(sc_if.if_ierrors));
212 printf(" | %8lu %6ld %6u %6u %6lu",
213 V(sc_if.if_obytes) / (rflag ? interval : 1),
214 V(sc_if.if_opackets),
215 V(sc_comp.sls_compressed),
216 V(sc_comp.sls_packets) - V(sc_comp.sls_compressed),
217 V(sc_if.if_opackets) - V(sc_comp.sls_packets));
219 printf(" %6u %6u %6lu %6lu",
220 V(sc_comp.sls_searches),
221 V(sc_comp.sls_misses),
223 V(sc_if.if_collisions));
227 oldmask = sigblock(sigmask(SIGALRM));
233 (void)alarm(interval);
234 bcopy((char *)sc, (char *)osc, AMT);
239 * Called if an interval expires before sidewaysintpr has completed a loop.
240 * Sets a flag to not wait for the alarm.