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