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[] =
26 "$FreeBSD: src/usr.sbin/slstat/slstat.c,v 1.14 1999/08/28 01:20:00 peter Exp $";
29 #include <sys/param.h>
31 #include <sys/socket.h>
32 #include <sys/sysctl.h>
45 #include <net/if_var.h>
46 #include <net/if_mib.h>
47 #include <net/if_types.h>
48 #include <netinet/in.h>
49 #include <netinet/in_systm.h>
50 #include <netinet/ip.h>
51 #include <net/slcompress.h>
52 #include <net/if_slvar.h>
54 static void usage __P((void));
55 static void intpr __P((void));
56 static void catchalarm __P((int));
58 #define INTERFACE_PREFIX "sl%d"
59 char interface[IFNAMSIZ];
63 unsigned interval = 5;
76 struct ifmibdata ifmd;
78 while ((c = getopt(argc, argv, "vri:")) != -1) {
87 interval = atoi(optarg);
96 sprintf(interface, INTERFACE_PREFIX, unit);
97 else if (isdigit(argv[optind][0])) {
98 unit = atoi(argv[optind]);
101 sprintf(interface, INTERFACE_PREFIX, unit);
102 } else if (strncmp(argv[optind], "sl", 2) == 0
103 && isdigit(argv[optind][2])
104 && sscanf(argv[optind], "sl%d", &unit) == 1) {
105 strncpy(interface, argv[optind], IFNAMSIZ);
111 name[2] = NETLINK_GENERIC;
112 name[3] = IFMIB_SYSTEM;
113 name[4] = IFMIB_IFCOUNT;
114 len = sizeof maxifno;
115 if (sysctl(name, 5, &maxifno, &len, 0, 0) < 0)
116 err(1, "sysctl net.link.generic.system.ifcount");
118 name[3] = IFMIB_IFDATA;
119 name[5] = IFDATA_GENERAL;
124 if (sysctl(name, 6, &ifmd, &len, 0, 0) < 0)
126 if (strncmp(interface, ifmd.ifmd_name, IFNAMSIZ) == 0
127 && ifmd.ifmd_data.ifi_type == IFT_SLIP) {
132 errx(1, "interface %s does not exist", interface);
136 name[5] = IFDATA_LINKSPECIFIC;
141 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
142 (rflag ? interval : 1)) : sc->offset)
143 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
148 fprintf(stderr, "usage: slstat [-i interval] [-vr] [unit]\n");
152 u_char signalled; /* set if alarm goes off "early" */
155 * Print a running summary of interface statistics.
156 * Repeat display every interval seconds, showing statistics
157 * collected over that interval. Assumes that interval is non-zero.
158 * First line printed at top of screen is always cumulative.
163 register int line = 0;
165 struct sl_softc *sc, *osc;
168 sc = (struct sl_softc *)malloc(AMT);
169 osc = (struct sl_softc *)malloc(AMT);
170 bzero((char *)osc, AMT);
174 if (sysctl(name, 6, sc, &len, 0, 0) < 0 &&
175 (errno != ENOMEM || len != AMT))
176 err(1, "sysctl linkspecific");
178 (void)signal(SIGALRM, catchalarm);
180 (void)alarm(interval);
182 if ((line % 20) == 0) {
183 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
184 "in", "pack", "comp", "uncomp", "unknwn");
186 printf(" %6.6s %6.6s %6.6s",
187 "toss", "other", "err");
188 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
189 "out", "pack", "comp", "uncomp", "other");
191 printf(" %6.6s %6.6s %6.6s %6.6s",
192 "search", "miss", "err", "coll");
195 printf("%8lu %6ld %6u %6u %6u",
197 V(sc_if.if_ipackets),
198 V(sc_comp.sls_compressedin),
199 V(sc_comp.sls_uncompressedin),
200 V(sc_comp.sls_errorin));
202 printf(" %6u %6lu %6lu",
203 V(sc_comp.sls_tossed),
204 V(sc_if.if_ipackets) -
205 V(sc_comp.sls_compressedin) -
206 V(sc_comp.sls_uncompressedin) -
207 V(sc_comp.sls_errorin),
208 V(sc_if.if_ierrors));
209 printf(" | %8lu %6ld %6u %6u %6lu",
210 V(sc_if.if_obytes) / (rflag ? interval : 1),
211 V(sc_if.if_opackets),
212 V(sc_comp.sls_compressed),
213 V(sc_comp.sls_packets) - V(sc_comp.sls_compressed),
214 V(sc_if.if_opackets) - V(sc_comp.sls_packets));
216 printf(" %6u %6u %6lu %6lu",
217 V(sc_comp.sls_searches),
218 V(sc_comp.sls_misses),
220 V(sc_if.if_collisions));
224 oldmask = sigblock(sigmask(SIGALRM));
230 (void)alarm(interval);
231 bcopy((char *)sc, (char *)osc, AMT);
236 * Called if an interval expires before sidewaysintpr has completed a loop.
237 * Sets a flag to not wait for the alarm.