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 MERCHANTABILITY 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 $
26 #define _KERNEL_STRUCTURES
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"
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)
123 if (strncmp(interface
, ifmd
.ifmd_name
, IFNAMSIZ
) == 0
124 && ifmd
.ifmd_data
.ifi_type
== IFT_SLIP
) {
129 errx(1, "interface %s does not exist", interface
);
133 name
[5] = IFDATA_LINKSPECIFIC
;
138 #define V(offset) ((line % 20)? ((sc->offset - osc->offset) / \
139 (rflag ? interval : 1)) : sc->offset)
140 #define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate))
145 fprintf(stderr
, "usage: slstat [-i interval] [-vr] [unit]\n");
149 u_char signalled
; /* set if alarm goes off "early" */
152 * Print a running summary of interface statistics.
153 * Repeat display every interval seconds, showing statistics
154 * collected over that interval. Assumes that interval is non-zero.
155 * First line printed at top of screen is always cumulative.
162 struct sl_softc
*sc
, *osc
;
165 sc
= (struct sl_softc
*)malloc(AMT
);
166 osc
= (struct sl_softc
*)malloc(AMT
);
167 bzero((char *)osc
, AMT
);
171 if (sysctl(name
, 6, sc
, &len
, 0, 0) < 0 &&
172 (errno
!= ENOMEM
|| len
!= AMT
))
173 err(1, "sysctl linkspecific");
175 signal(SIGALRM
, catchalarm
);
179 if ((line
% 20) == 0) {
180 printf("%8.8s %6.6s %6.6s %6.6s %6.6s",
181 "in", "pack", "comp", "uncomp", "unknwn");
183 printf(" %6.6s %6.6s %6.6s",
184 "toss", "other", "err");
185 printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s",
186 "out", "pack", "comp", "uncomp", "other");
188 printf(" %6.6s %6.6s %6.6s %6.6s",
189 "search", "miss", "err", "coll");
192 printf("%8lu %6ld %6u %6u %6u",
194 V(sc_if
.if_ipackets
),
195 V(sc_comp
.sls_compressedin
),
196 V(sc_comp
.sls_uncompressedin
),
197 V(sc_comp
.sls_errorin
));
199 printf(" %6u %6lu %6lu",
200 V(sc_comp
.sls_tossed
),
201 V(sc_if
.if_ipackets
) -
202 V(sc_comp
.sls_compressedin
) -
203 V(sc_comp
.sls_uncompressedin
) -
204 V(sc_comp
.sls_errorin
),
205 V(sc_if
.if_ierrors
));
206 printf(" | %8lu %6ld %6u %6u %6lu",
207 V(sc_if
.if_obytes
) / (rflag
? interval
: 1),
208 V(sc_if
.if_opackets
),
209 V(sc_comp
.sls_compressed
),
210 V(sc_comp
.sls_packets
) - V(sc_comp
.sls_compressed
),
211 V(sc_if
.if_opackets
) - V(sc_comp
.sls_packets
));
213 printf(" %6u %6u %6lu %6lu",
214 V(sc_comp
.sls_searches
),
215 V(sc_comp
.sls_misses
),
217 V(sc_if
.if_collisions
));
221 oldmask
= sigblock(sigmask(SIGALRM
));
228 bcopy((char *)sc
, (char *)osc
, AMT
);
233 * Called if an interval expires before sidewaysintpr has completed a loop.
234 * Sets a flag to not wait for the alarm.