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.
24 #include <sys/cdefs.h>
25 __FBSDID("$FreeBSD$");
27 #include <sys/param.h>
28 #include <sys/socket.h>
29 #include <sys/sysctl.h>
42 #include <net/if_var.h>
43 #include <net/if_mib.h>
44 #include <net/if_types.h>
45 #include <netinet/in.h>
46 #include <netinet/in_systm.h>
47 #include <netinet/ip.h>
48 #include <net/slcompress.h>
49 #include <net/if_slvar.h>
51 static void usage(void);
52 static void intpr(void);
53 static void catchalarm(int);
55 #define INTERFACE_PREFIX "sl%d"
56 char interface[IFNAMSIZ];
60 unsigned interval = 5;
65 main(int argc, char *argv[])
71 struct ifmibdata ifmd;
73 while ((c = getopt(argc, argv, "vri:")) != -1) {
82 interval = atoi(optarg);
91 sprintf(interface, INTERFACE_PREFIX, unit);
92 else if (isdigit(argv[optind][0])) {
93 unit = atoi(argv[optind]);
96 sprintf(interface, INTERFACE_PREFIX, unit);
97 } else if (strncmp(argv[optind], "sl", 2) == 0
98 && isdigit(argv[optind][2])
99 && sscanf(argv[optind], "sl%d", &unit) == 1) {
100 strncpy(interface, argv[optind], IFNAMSIZ);
106 name[2] = NETLINK_GENERIC;
107 name[3] = IFMIB_SYSTEM;
108 name[4] = IFMIB_IFCOUNT;
109 len = sizeof maxifno;
110 if (sysctl(name, 5, &maxifno, &len, 0, 0) < 0)
111 err(1, "sysctl net.link.generic.system.ifcount");
113 name[3] = IFMIB_IFDATA;
114 name[5] = IFDATA_GENERAL;
119 if (sysctl(name, 6, &ifmd, &len, 0, 0) < 0) {
125 if (strncmp(interface, ifmd.ifmd_name, IFNAMSIZ) == 0
126 && ifmd.ifmd_data.ifi_type == IFT_SLIP) {
131 errx(1, "interface %s does not exist", interface);
135 name[5] = IFDATA_LINKSPECIFIC;
140 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
141 (rflag ? interval : 1)) : sc->offset)
142 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
147 fprintf(stderr, "usage: slstat [-i interval] [-vr] [unit]\n");
151 u_char signalled; /* set if alarm goes off "early" */
154 * Print a running summary of interface statistics.
155 * Repeat display every interval seconds, showing statistics
156 * collected over that interval. Assumes that interval is non-zero.
157 * First line printed at top of screen is always cumulative.
162 register int line = 0;
164 struct sl_softc *sc, *osc;
167 sc = (struct sl_softc *)malloc(AMT);
168 osc = (struct sl_softc *)malloc(AMT);
169 bzero((char *)osc, AMT);
173 if (sysctl(name, 6, sc, &len, 0, 0) < 0 &&
174 (errno != ENOMEM || len != AMT))
175 err(1, "sysctl linkspecific");
177 (void)signal(SIGALRM, catchalarm);
179 (void)alarm(interval);
181 if ((line % 20) == 0) {
182 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
183 "in", "pack", "comp", "uncomp", "unknwn");
185 printf(" %6.6s %6.6s %6.6s",
186 "toss", "other", "err");
187 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
188 "out", "pack", "comp", "uncomp", "other");
190 printf(" %6.6s %6.6s %6.6s %6.6s",
191 "search", "miss", "err", "coll");
194 printf("%8lu %6ld %6u %6u %6u",
195 V(sc_ifp->if_ibytes),
196 V(sc_ifp->if_ipackets),
197 V(sc_comp.sls_compressedin),
198 V(sc_comp.sls_uncompressedin),
199 V(sc_comp.sls_errorin));
201 printf(" %6u %6lu %6lu",
202 V(sc_comp.sls_tossed),
203 V(sc_ifp->if_ipackets) -
204 V(sc_comp.sls_compressedin) -
205 V(sc_comp.sls_uncompressedin) -
206 V(sc_comp.sls_errorin),
207 V(sc_ifp->if_ierrors));
208 printf(" | %8lu %6ld %6u %6u %6lu",
209 V(sc_ifp->if_obytes) / (rflag ? interval : 1),
210 V(sc_ifp->if_opackets),
211 V(sc_comp.sls_compressed),
212 V(sc_comp.sls_packets) - V(sc_comp.sls_compressed),
213 V(sc_ifp->if_opackets) - V(sc_comp.sls_packets));
215 printf(" %6u %6u %6lu %6lu",
216 V(sc_comp.sls_searches),
217 V(sc_comp.sls_misses),
218 V(sc_ifp->if_oerrors),
219 V(sc_ifp->if_collisions));
223 oldmask = sigblock(sigmask(SIGALRM));
229 (void)alarm(interval);
230 bcopy((char *)sc, (char *)osc, AMT);
235 * Called if an interval expires before sidewaysintpr has completed a loop.
236 * Sets a flag to not wait for the alarm.