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.
23 * $FreeBSD: src/usr.sbin/slstat/slstat.c,v 1.14 1999/08/28 01:20:00 peter Exp $
24 * $DragonFly: src/usr.sbin/slstat/slstat.c,v 1.5 2004/03/20 17:46:48 cpressey Exp $
27 #include <sys/param.h>
29 #include <sys/socket.h>
30 #include <sys/sysctl.h>
43 #include <net/if_var.h>
44 #include <net/if_mib.h>
45 #include <net/if_types.h>
46 #include <netinet/in.h>
47 #include <netinet/in_systm.h>
48 #include <netinet/ip.h>
49 #include <net/slcompress.h>
50 #include <net/sl/if_slvar.h>
52 static void usage(void);
53 static void intpr(void);
54 static void catchalarm(int);
56 #define INTERFACE_PREFIX "sl%d"
57 char interface
[IFNAMSIZ
];
61 unsigned interval
= 5;
66 main(int argc
, char **argv
)
72 struct ifmibdata ifmd
;
74 while ((c
= getopt(argc
, argv
, "vri:")) != -1) {
83 interval
= atoi(optarg
);
92 sprintf(interface
, INTERFACE_PREFIX
, unit
);
93 else if (isdigit(argv
[optind
][0])) {
94 unit
= atoi(argv
[optind
]);
97 sprintf(interface
, INTERFACE_PREFIX
, unit
);
98 } else if (strncmp(argv
[optind
], "sl", 2) == 0
99 && isdigit(argv
[optind
][2])
100 && sscanf(argv
[optind
], "sl%d", &unit
) == 1) {
101 strncpy(interface
, argv
[optind
], IFNAMSIZ
);
107 name
[2] = NETLINK_GENERIC
;
108 name
[3] = IFMIB_SYSTEM
;
109 name
[4] = IFMIB_IFCOUNT
;
110 len
= sizeof maxifno
;
111 if (sysctl(name
, 5, &maxifno
, &len
, 0, 0) < 0)
112 err(1, "sysctl net.link.generic.system.ifcount");
114 name
[3] = IFMIB_IFDATA
;
115 name
[5] = IFDATA_GENERAL
;
120 if (sysctl(name
, 6, &ifmd
, &len
, 0, 0) < 0)
122 if (strncmp(interface
, ifmd
.ifmd_name
, IFNAMSIZ
) == 0
123 && ifmd
.ifmd_data
.ifi_type
== IFT_SLIP
) {
128 errx(1, "interface %s does not exist", interface
);
132 name
[5] = IFDATA_LINKSPECIFIC
;
137 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
138 (rflag ? interval : 1)) : sc->offset)
139 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
144 fprintf(stderr
, "usage: slstat [-i interval] [-vr] [unit]\n");
148 u_char signalled
; /* set if alarm goes off "early" */
151 * Print a running summary of interface statistics.
152 * Repeat display every interval seconds, showing statistics
153 * collected over that interval. Assumes that interval is non-zero.
154 * First line printed at top of screen is always cumulative.
161 struct sl_softc
*sc
, *osc
;
164 sc
= (struct sl_softc
*)malloc(AMT
);
165 osc
= (struct sl_softc
*)malloc(AMT
);
166 bzero((char *)osc
, AMT
);
170 if (sysctl(name
, 6, sc
, &len
, 0, 0) < 0 &&
171 (errno
!= ENOMEM
|| len
!= AMT
))
172 err(1, "sysctl linkspecific");
174 signal(SIGALRM
, catchalarm
);
178 if ((line
% 20) == 0) {
179 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
180 "in", "pack", "comp", "uncomp", "unknwn");
182 printf(" %6.6s %6.6s %6.6s",
183 "toss", "other", "err");
184 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
185 "out", "pack", "comp", "uncomp", "other");
187 printf(" %6.6s %6.6s %6.6s %6.6s",
188 "search", "miss", "err", "coll");
191 printf("%8lu %6ld %6u %6u %6u",
193 V(sc_if
.if_ipackets
),
194 V(sc_comp
.sls_compressedin
),
195 V(sc_comp
.sls_uncompressedin
),
196 V(sc_comp
.sls_errorin
));
198 printf(" %6u %6lu %6lu",
199 V(sc_comp
.sls_tossed
),
200 V(sc_if
.if_ipackets
) -
201 V(sc_comp
.sls_compressedin
) -
202 V(sc_comp
.sls_uncompressedin
) -
203 V(sc_comp
.sls_errorin
),
204 V(sc_if
.if_ierrors
));
205 printf(" | %8lu %6ld %6u %6u %6lu",
206 V(sc_if
.if_obytes
) / (rflag
? interval
: 1),
207 V(sc_if
.if_opackets
),
208 V(sc_comp
.sls_compressed
),
209 V(sc_comp
.sls_packets
) - V(sc_comp
.sls_compressed
),
210 V(sc_if
.if_opackets
) - V(sc_comp
.sls_packets
));
212 printf(" %6u %6u %6lu %6lu",
213 V(sc_comp
.sls_searches
),
214 V(sc_comp
.sls_misses
),
216 V(sc_if
.if_collisions
));
220 oldmask
= sigblock(sigmask(SIGALRM
));
227 bcopy((char *)sc
, (char *)osc
, AMT
);
232 * Called if an interval expires before sidewaysintpr has completed a loop.
233 * Sets a flag to not wait for the alarm.