if.c revision 1.32 1 1.32 itojun /* $NetBSD: if.c,v 1.32 1999/07/01 18:40:35 itojun Exp $ */
2 1.13 thorpej
3 1.1 cgd /*
4 1.8 mycroft * Copyright (c) 1983, 1988, 1993
5 1.8 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.25 lukem #include <sys/cdefs.h>
37 1.1 cgd #ifndef lint
38 1.13 thorpej #if 0
39 1.13 thorpej static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
40 1.13 thorpej #else
41 1.32 itojun __RCSID("$NetBSD: if.c,v 1.32 1999/07/01 18:40:35 itojun Exp $");
42 1.13 thorpej #endif
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.1 cgd #include <sys/types.h>
46 1.8 mycroft #include <sys/protosw.h>
47 1.1 cgd #include <sys/socket.h>
48 1.1 cgd
49 1.1 cgd #include <net/if.h>
50 1.1 cgd #include <net/if_dl.h>
51 1.20 thorpej #include <net/if_types.h>
52 1.1 cgd #include <netinet/in.h>
53 1.1 cgd #include <netinet/in_var.h>
54 1.1 cgd #include <netns/ns.h>
55 1.1 cgd #include <netns/ns_if.h>
56 1.1 cgd #include <netiso/iso.h>
57 1.1 cgd #include <netiso/iso_var.h>
58 1.8 mycroft #include <arpa/inet.h>
59 1.1 cgd
60 1.8 mycroft #include <signal.h>
61 1.1 cgd #include <stdio.h>
62 1.8 mycroft #include <string.h>
63 1.8 mycroft #include <unistd.h>
64 1.8 mycroft
65 1.8 mycroft #include "netstat.h"
66 1.1 cgd
67 1.1 cgd #define YES 1
68 1.1 cgd #define NO 0
69 1.1 cgd
70 1.8 mycroft static void sidewaysintpr __P((u_int, u_long));
71 1.8 mycroft static void catchalarm __P((int));
72 1.1 cgd
73 1.32 itojun #ifdef INET6
74 1.32 itojun char *netname6 __P((struct in6_addr *, struct in6_addr *));
75 1.32 itojun static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */
76 1.32 itojun #endif
77 1.32 itojun
78 1.1 cgd /*
79 1.1 cgd * Print a description of the network interfaces.
80 1.15 thorpej * NOTE: ifnetaddr is the location of the kernel global "ifnet",
81 1.15 thorpej * which is a TAILQ_HEAD.
82 1.1 cgd */
83 1.8 mycroft void
84 1.1 cgd intpr(interval, ifnetaddr)
85 1.1 cgd int interval;
86 1.7 cgd u_long ifnetaddr;
87 1.1 cgd {
88 1.1 cgd struct ifnet ifnet;
89 1.1 cgd union {
90 1.1 cgd struct ifaddr ifa;
91 1.1 cgd struct in_ifaddr in;
92 1.32 itojun #ifdef INET6
93 1.32 itojun struct in6_ifaddr in6;
94 1.32 itojun #endif /* INET6 */
95 1.1 cgd struct ns_ifaddr ns;
96 1.1 cgd struct iso_ifaddr iso;
97 1.1 cgd } ifaddr;
98 1.7 cgd u_long ifaddraddr;
99 1.1 cgd struct sockaddr *sa;
100 1.15 thorpej struct ifnet_head ifhead; /* TAILQ_HEAD */
101 1.15 thorpej char name[IFNAMSIZ];
102 1.1 cgd
103 1.1 cgd if (ifnetaddr == 0) {
104 1.1 cgd printf("ifnet: symbol not defined\n");
105 1.1 cgd return;
106 1.1 cgd }
107 1.1 cgd if (interval) {
108 1.1 cgd sidewaysintpr((unsigned)interval, ifnetaddr);
109 1.1 cgd return;
110 1.1 cgd }
111 1.15 thorpej
112 1.15 thorpej /*
113 1.15 thorpej * Find the pointer to the first ifnet structure. Replace
114 1.15 thorpej * the pointer to the TAILQ_HEAD with the actual pointer
115 1.15 thorpej * to the first list element.
116 1.15 thorpej */
117 1.15 thorpej if (kread(ifnetaddr, (char *)&ifhead, sizeof ifhead))
118 1.8 mycroft return;
119 1.15 thorpej ifnetaddr = (u_long)ifhead.tqh_first;
120 1.15 thorpej
121 1.26 kml if (bflag) {
122 1.26 kml printf("%-5.5s %-5.5s %-13.13s %-17.17s "
123 1.26 kml "%10.10s %10.10s",
124 1.26 kml "Name", "Mtu", "Network", "Address",
125 1.26 kml "Ibytes", "Obytes");
126 1.26 kml } else {
127 1.26 kml printf("%-5.5s %-5.5s %-13.13s %-17.17s "
128 1.31 mycroft "%8.8s %5.5s %8.8s %5.5s %5.5s",
129 1.26 kml "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
130 1.31 mycroft "Opkts", "Oerrs", "Colls");
131 1.26 kml }
132 1.1 cgd if (tflag)
133 1.31 mycroft printf(" %4.4s", "Time");
134 1.1 cgd if (dflag)
135 1.31 mycroft printf(" %5.5s", "Drops");
136 1.1 cgd putchar('\n');
137 1.1 cgd ifaddraddr = 0;
138 1.1 cgd while (ifnetaddr || ifaddraddr) {
139 1.1 cgd struct sockaddr_in *sin;
140 1.32 itojun #ifdef INET6
141 1.32 itojun struct sockaddr_in6 *sin6;
142 1.32 itojun #endif /* INET6 */
143 1.25 lukem char *cp;
144 1.1 cgd int n, m;
145 1.1 cgd
146 1.1 cgd if (ifaddraddr == 0) {
147 1.15 thorpej if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
148 1.8 mycroft return;
149 1.25 lukem memmove(name, ifnet.if_xname, IFNAMSIZ);
150 1.15 thorpej name[IFNAMSIZ - 1] = '\0'; /* sanity */
151 1.10 mycroft ifnetaddr = (u_long)ifnet.if_list.tqe_next;
152 1.16 thorpej if (interface != 0 && strcmp(name, interface) != 0)
153 1.1 cgd continue;
154 1.25 lukem cp = strchr(name, '\0');
155 1.10 mycroft if ((ifnet.if_flags & IFF_UP) == 0)
156 1.1 cgd *cp++ = '*';
157 1.1 cgd *cp = '\0';
158 1.10 mycroft ifaddraddr = (u_long)ifnet.if_addrlist.tqh_first;
159 1.1 cgd }
160 1.27 kml printf("%-5.5s %-5lu ", name, ifnet.if_mtu);
161 1.1 cgd if (ifaddraddr == 0) {
162 1.21 christos printf("%-13.13s ", "none");
163 1.23 mikel printf("%-17.17s ", "none");
164 1.1 cgd } else {
165 1.20 thorpej char hexsep = '.'; /* for hexprint */
166 1.20 thorpej const char *hexfmt = "%x%c"; /* for hexprint */
167 1.8 mycroft if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
168 1.8 mycroft ifaddraddr = 0;
169 1.8 mycroft continue;
170 1.8 mycroft }
171 1.1 cgd #define CP(x) ((char *)(x))
172 1.8 mycroft cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
173 1.1 cgd CP(&ifaddr); sa = (struct sockaddr *)cp;
174 1.1 cgd switch (sa->sa_family) {
175 1.1 cgd case AF_UNSPEC:
176 1.21 christos printf("%-13.13s ", "none");
177 1.12 jtc printf("%-17.17s ", "none");
178 1.1 cgd break;
179 1.1 cgd case AF_INET:
180 1.1 cgd sin = (struct sockaddr_in *)sa;
181 1.1 cgd #ifdef notdef
182 1.28 mrg /*
183 1.28 mrg * can't use inet_makeaddr because kernel
184 1.1 cgd * keeps nets unshifted.
185 1.1 cgd */
186 1.1 cgd in = inet_makeaddr(ifaddr.in.ia_subnet,
187 1.1 cgd INADDR_ANY);
188 1.21 christos printf("%-13.13s ", netname(in.s_addr,
189 1.8 mycroft ifaddr.in.ia_subnetmask));
190 1.1 cgd #else
191 1.21 christos printf("%-13.13s ",
192 1.11 mycroft netname(ifaddr.in.ia_subnet,
193 1.8 mycroft ifaddr.in.ia_subnetmask));
194 1.1 cgd #endif
195 1.12 jtc printf("%-17.17s ",
196 1.8 mycroft routename(sin->sin_addr.s_addr));
197 1.10 mycroft
198 1.10 mycroft if (aflag) {
199 1.10 mycroft u_long multiaddr;
200 1.10 mycroft struct in_multi inm;
201 1.10 mycroft
202 1.28 mrg multiaddr = (u_long)
203 1.28 mrg ifaddr.in.ia_multiaddrs.lh_first;
204 1.10 mycroft while (multiaddr != 0) {
205 1.10 mycroft kread(multiaddr, (char *)&inm,
206 1.28 mrg sizeof inm);
207 1.23 mikel printf("\n%25s %-17.17s ", "",
208 1.28 mrg routename(
209 1.28 mrg inm.inm_addr.s_addr));
210 1.28 mrg multiaddr =
211 1.28 mrg (u_long)inm.inm_list.le_next;
212 1.10 mycroft }
213 1.10 mycroft }
214 1.1 cgd break;
215 1.32 itojun #ifdef INET6
216 1.32 itojun case AF_INET6:
217 1.32 itojun sin6 = (struct sockaddr_in6 *)sa;
218 1.32 itojun printf("%-13.13s ",
219 1.32 itojun netname6(&ifaddr.in6.ia_addr.sin6_addr,
220 1.32 itojun &ifaddr.in6.ia_prefixmask.sin6_addr));
221 1.32 itojun printf("%-17.17s ",
222 1.32 itojun (char *)inet_ntop(AF_INET6,
223 1.32 itojun &sin6->sin6_addr,
224 1.32 itojun ntop_buf, sizeof(ntop_buf)));
225 1.32 itojun break;
226 1.32 itojun #endif /*INET6*/
227 1.30 mrg #ifndef SMALL
228 1.21 christos case AF_APPLETALK:
229 1.24 christos printf("atalk:%-7.7s ",
230 1.21 christos atalk_print(sa,0x10));
231 1.24 christos printf("%-17.17s ", atalk_print(sa,0x0b));
232 1.21 christos break;
233 1.1 cgd case AF_NS:
234 1.1 cgd {
235 1.1 cgd struct sockaddr_ns *sns =
236 1.1 cgd (struct sockaddr_ns *)sa;
237 1.1 cgd u_long net;
238 1.1 cgd char netnum[8];
239 1.1 cgd
240 1.28 mrg *(union ns_net *)&net = sns->sns_addr.x_net;
241 1.28 mrg (void)sprintf(netnum, "%xH",
242 1.28 mrg (u_int32_t)ntohl(net));
243 1.1 cgd upHex(netnum);
244 1.23 mikel printf("ns:%-10s ", netnum);
245 1.23 mikel printf("%-17.17s ",
246 1.8 mycroft ns_phost((struct sockaddr *)sns));
247 1.1 cgd }
248 1.1 cgd break;
249 1.30 mrg #endif
250 1.1 cgd case AF_LINK:
251 1.1 cgd {
252 1.1 cgd struct sockaddr_dl *sdl =
253 1.1 cgd (struct sockaddr_dl *)sa;
254 1.1 cgd cp = (char *)LLADDR(sdl);
255 1.20 thorpej if (sdl->sdl_type == IFT_FDDI
256 1.20 thorpej || sdl->sdl_type == IFT_ETHER)
257 1.20 thorpej hexsep = ':', hexfmt = "%02x%c";
258 1.1 cgd n = sdl->sdl_alen;
259 1.1 cgd }
260 1.22 christos m = printf("%-13.13s ", "<Link>");
261 1.1 cgd goto hexprint;
262 1.1 cgd default:
263 1.1 cgd m = printf("(%d)", sa->sa_family);
264 1.1 cgd for (cp = sa->sa_len + (char *)sa;
265 1.1 cgd --cp > sa->sa_data && (*cp == 0);) {}
266 1.1 cgd n = cp - sa->sa_data + 1;
267 1.1 cgd cp = sa->sa_data;
268 1.1 cgd hexprint:
269 1.1 cgd while (--n >= 0)
270 1.20 thorpej m += printf(hexfmt, *cp++ & 0xff,
271 1.20 thorpej n > 0 ? hexsep : ' ');
272 1.22 christos m = 32 - m;
273 1.1 cgd while (m-- > 0)
274 1.1 cgd putchar(' ');
275 1.1 cgd break;
276 1.1 cgd }
277 1.10 mycroft ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
278 1.1 cgd }
279 1.26 kml if (bflag) {
280 1.27 kml printf("%10lu %10lu",
281 1.26 kml ifnet.if_ibytes, ifnet.if_obytes);
282 1.26 kml } else {
283 1.27 kml printf("%8lu %5lu %8lu %5lu %5lu",
284 1.26 kml ifnet.if_ipackets, ifnet.if_ierrors,
285 1.26 kml ifnet.if_opackets, ifnet.if_oerrors,
286 1.26 kml ifnet.if_collisions);
287 1.26 kml }
288 1.1 cgd if (tflag)
289 1.31 mycroft printf(" %4d", ifnet.if_timer);
290 1.1 cgd if (dflag)
291 1.31 mycroft printf(" %5d", ifnet.if_snd.ifq_drops);
292 1.1 cgd putchar('\n');
293 1.1 cgd }
294 1.1 cgd }
295 1.1 cgd
296 1.18 cgd #define MAXIF 100
297 1.1 cgd struct iftot {
298 1.15 thorpej char ift_name[IFNAMSIZ]; /* interface name */
299 1.27 kml u_long ift_ip; /* input packets */
300 1.27 kml u_long ift_ib; /* input bytes */
301 1.27 kml u_long ift_ie; /* input errors */
302 1.27 kml u_long ift_op; /* output packets */
303 1.27 kml u_long ift_ob; /* output bytes */
304 1.27 kml u_long ift_oe; /* output errors */
305 1.27 kml u_long ift_co; /* collisions */
306 1.1 cgd int ift_dr; /* drops */
307 1.1 cgd } iftot[MAXIF];
308 1.1 cgd
309 1.1 cgd u_char signalled; /* set if alarm goes off "early" */
310 1.1 cgd
311 1.1 cgd /*
312 1.1 cgd * Print a running summary of interface statistics.
313 1.1 cgd * Repeat display every interval seconds, showing statistics
314 1.1 cgd * collected over that interval. Assumes that interval is non-zero.
315 1.1 cgd * First line printed at top of screen is always cumulative.
316 1.1 cgd */
317 1.8 mycroft static void
318 1.1 cgd sidewaysintpr(interval, off)
319 1.1 cgd unsigned interval;
320 1.7 cgd u_long off;
321 1.1 cgd {
322 1.1 cgd struct ifnet ifnet;
323 1.7 cgd u_long firstifnet;
324 1.25 lukem struct iftot *ip, *total;
325 1.25 lukem int line;
326 1.1 cgd struct iftot *lastif, *sum, *interesting;
327 1.15 thorpej struct ifnet_head ifhead; /* TAILQ_HEAD */
328 1.1 cgd int oldmask;
329 1.1 cgd
330 1.15 thorpej /*
331 1.15 thorpej * Find the pointer to the first ifnet structure. Replace
332 1.15 thorpej * the pointer to the TAILQ_HEAD with the actual pointer
333 1.15 thorpej * to the first list element.
334 1.15 thorpej */
335 1.15 thorpej if (kread(off, (char *)&ifhead, sizeof ifhead))
336 1.8 mycroft return;
337 1.15 thorpej firstifnet = (u_long)ifhead.tqh_first;
338 1.15 thorpej
339 1.1 cgd lastif = iftot;
340 1.1 cgd sum = iftot + MAXIF - 1;
341 1.1 cgd total = sum - 1;
342 1.17 cgd interesting = (interface == NULL) ? iftot : NULL;
343 1.1 cgd for (off = firstifnet, ip = iftot; off;) {
344 1.8 mycroft if (kread(off, (char *)&ifnet, sizeof ifnet))
345 1.8 mycroft break;
346 1.25 lukem memset(ip->ift_name, 0, sizeof(ip->ift_name));
347 1.31 mycroft snprintf(ip->ift_name, IFNAMSIZ, "%s", ifnet.if_xname);
348 1.19 thorpej if (interface && strcmp(ifnet.if_xname, interface) == 0)
349 1.1 cgd interesting = ip;
350 1.1 cgd ip++;
351 1.1 cgd if (ip >= iftot + MAXIF - 2)
352 1.1 cgd break;
353 1.10 mycroft off = (u_long)ifnet.if_list.tqe_next;
354 1.17 cgd }
355 1.17 cgd if (interesting == NULL) {
356 1.17 cgd fprintf(stderr, "%s: %s: unknown interface\n",
357 1.17 cgd __progname, interface);
358 1.17 cgd exit(1);
359 1.1 cgd }
360 1.1 cgd lastif = ip;
361 1.1 cgd
362 1.1 cgd (void)signal(SIGALRM, catchalarm);
363 1.1 cgd signalled = NO;
364 1.1 cgd (void)alarm(interval);
365 1.1 cgd banner:
366 1.31 mycroft if (bflag)
367 1.31 mycroft printf("%7.7s in %8.8s %6.6s out %5.5s",
368 1.31 mycroft interesting->ift_name, " ",
369 1.31 mycroft interesting->ift_name, " ");
370 1.31 mycroft else
371 1.31 mycroft printf("%5.5s in %5.5s%5.5s out %5.5s %5.5s",
372 1.31 mycroft interesting->ift_name, " ",
373 1.31 mycroft interesting->ift_name, " ", " ");
374 1.31 mycroft if (dflag)
375 1.31 mycroft printf(" %5.5s", " ");
376 1.1 cgd if (lastif - iftot > 0) {
377 1.31 mycroft if (bflag)
378 1.31 mycroft printf(" %7.7s in %8.8s %6.6s out %5.5s",
379 1.31 mycroft "total", " ", "total", " ");
380 1.31 mycroft else
381 1.31 mycroft printf(" %5.5s in %5.5s%5.5s out %5.5s %5.5s",
382 1.31 mycroft "total", " ", "total", " ", " ");
383 1.1 cgd if (dflag)
384 1.31 mycroft printf(" %5.5s", " ");
385 1.1 cgd }
386 1.1 cgd for (ip = iftot; ip < iftot + MAXIF; ip++) {
387 1.1 cgd ip->ift_ip = 0;
388 1.26 kml ip->ift_ib = 0;
389 1.1 cgd ip->ift_ie = 0;
390 1.1 cgd ip->ift_op = 0;
391 1.26 kml ip->ift_ob = 0;
392 1.1 cgd ip->ift_oe = 0;
393 1.1 cgd ip->ift_co = 0;
394 1.1 cgd ip->ift_dr = 0;
395 1.1 cgd }
396 1.1 cgd putchar('\n');
397 1.31 mycroft if (bflag)
398 1.26 kml printf("%10.10s %8.8s %10.10s %5.5s",
399 1.31 mycroft "bytes", " ", "bytes", " ");
400 1.31 mycroft else
401 1.31 mycroft printf("%8.8s %5.5s %8.8s %5.5s %5.5s",
402 1.31 mycroft "packets", "errs", "packets", "errs", "colls");
403 1.1 cgd if (dflag)
404 1.31 mycroft printf(" %5.5s", "drops");
405 1.29 ross if (lastif - iftot > 0) {
406 1.31 mycroft if (bflag)
407 1.31 mycroft printf(" %10.10s %8.8s %10.10s %5.5s",
408 1.31 mycroft "bytes", " ", "bytes", " ");
409 1.31 mycroft else
410 1.31 mycroft printf(" %8.8s %5.5s %8.8s %5.5s %5.5s",
411 1.31 mycroft "packets", "errs", "packets", "errs", "colls");
412 1.31 mycroft if (dflag)
413 1.31 mycroft printf(" %5.5s", "drops");
414 1.29 ross }
415 1.1 cgd putchar('\n');
416 1.1 cgd fflush(stdout);
417 1.1 cgd line = 0;
418 1.1 cgd loop:
419 1.1 cgd sum->ift_ip = 0;
420 1.26 kml sum->ift_ib = 0;
421 1.1 cgd sum->ift_ie = 0;
422 1.1 cgd sum->ift_op = 0;
423 1.26 kml sum->ift_ob = 0;
424 1.1 cgd sum->ift_oe = 0;
425 1.1 cgd sum->ift_co = 0;
426 1.1 cgd sum->ift_dr = 0;
427 1.1 cgd for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
428 1.8 mycroft if (kread(off, (char *)&ifnet, sizeof ifnet)) {
429 1.8 mycroft off = 0;
430 1.8 mycroft continue;
431 1.8 mycroft }
432 1.1 cgd if (ip == interesting) {
433 1.26 kml if (bflag) {
434 1.27 kml printf("%10lu %8.8s %10lu %5.5s",
435 1.26 kml ifnet.if_ibytes - ip->ift_ib, " ",
436 1.26 kml ifnet.if_obytes - ip->ift_ob, " ");
437 1.26 kml } else {
438 1.27 kml printf("%8lu %5lu %8lu %5lu %5lu",
439 1.26 kml ifnet.if_ipackets - ip->ift_ip,
440 1.26 kml ifnet.if_ierrors - ip->ift_ie,
441 1.26 kml ifnet.if_opackets - ip->ift_op,
442 1.26 kml ifnet.if_oerrors - ip->ift_oe,
443 1.26 kml ifnet.if_collisions - ip->ift_co);
444 1.26 kml }
445 1.1 cgd if (dflag)
446 1.1 cgd printf(" %5d",
447 1.1 cgd ifnet.if_snd.ifq_drops - ip->ift_dr);
448 1.1 cgd }
449 1.1 cgd ip->ift_ip = ifnet.if_ipackets;
450 1.26 kml ip->ift_ib = ifnet.if_ibytes;
451 1.1 cgd ip->ift_ie = ifnet.if_ierrors;
452 1.1 cgd ip->ift_op = ifnet.if_opackets;
453 1.26 kml ip->ift_ob = ifnet.if_obytes;
454 1.1 cgd ip->ift_oe = ifnet.if_oerrors;
455 1.1 cgd ip->ift_co = ifnet.if_collisions;
456 1.1 cgd ip->ift_dr = ifnet.if_snd.ifq_drops;
457 1.1 cgd sum->ift_ip += ip->ift_ip;
458 1.26 kml sum->ift_ib += ip->ift_ib;
459 1.1 cgd sum->ift_ie += ip->ift_ie;
460 1.1 cgd sum->ift_op += ip->ift_op;
461 1.26 kml sum->ift_ob += ip->ift_ob;
462 1.1 cgd sum->ift_oe += ip->ift_oe;
463 1.1 cgd sum->ift_co += ip->ift_co;
464 1.1 cgd sum->ift_dr += ip->ift_dr;
465 1.10 mycroft off = (u_long)ifnet.if_list.tqe_next;
466 1.1 cgd }
467 1.1 cgd if (lastif - iftot > 0) {
468 1.26 kml if (bflag) {
469 1.27 kml printf(" %10lu %8.8s %10lu %5.5s",
470 1.26 kml sum->ift_ib - total->ift_ib, " ",
471 1.26 kml sum->ift_ob - total->ift_ob, " ");
472 1.26 kml } else {
473 1.27 kml printf(" %8lu %5lu %8lu %5lu %5lu",
474 1.26 kml sum->ift_ip - total->ift_ip,
475 1.26 kml sum->ift_ie - total->ift_ie,
476 1.26 kml sum->ift_op - total->ift_op,
477 1.26 kml sum->ift_oe - total->ift_oe,
478 1.26 kml sum->ift_co - total->ift_co);
479 1.26 kml }
480 1.1 cgd if (dflag)
481 1.1 cgd printf(" %5d", sum->ift_dr - total->ift_dr);
482 1.1 cgd }
483 1.1 cgd *total = *sum;
484 1.1 cgd putchar('\n');
485 1.1 cgd fflush(stdout);
486 1.1 cgd line++;
487 1.1 cgd oldmask = sigblock(sigmask(SIGALRM));
488 1.1 cgd if (! signalled) {
489 1.1 cgd sigpause(0);
490 1.1 cgd }
491 1.1 cgd sigsetmask(oldmask);
492 1.1 cgd signalled = NO;
493 1.1 cgd (void)alarm(interval);
494 1.1 cgd if (line == 21)
495 1.1 cgd goto banner;
496 1.1 cgd goto loop;
497 1.1 cgd /*NOTREACHED*/
498 1.1 cgd }
499 1.1 cgd
500 1.1 cgd /*
501 1.1 cgd * Called if an interval expires before sidewaysintpr has completed a loop.
502 1.1 cgd * Sets a flag to not wait for the alarm.
503 1.1 cgd */
504 1.8 mycroft static void
505 1.8 mycroft catchalarm(signo)
506 1.8 mycroft int signo;
507 1.1 cgd {
508 1.28 mrg
509 1.1 cgd signalled = YES;
510 1.1 cgd }
511