if.c revision 1.26 1 1.26 kml /* $NetBSD: if.c,v 1.26 1998/03/19 02:42:57 kml 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.26 kml __RCSID("$NetBSD: if.c,v 1.26 1998/03/19 02:42:57 kml 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.1 cgd /*
74 1.1 cgd * Print a description of the network interfaces.
75 1.15 thorpej * NOTE: ifnetaddr is the location of the kernel global "ifnet",
76 1.15 thorpej * which is a TAILQ_HEAD.
77 1.1 cgd */
78 1.8 mycroft void
79 1.1 cgd intpr(interval, ifnetaddr)
80 1.1 cgd int interval;
81 1.7 cgd u_long ifnetaddr;
82 1.1 cgd {
83 1.1 cgd struct ifnet ifnet;
84 1.1 cgd union {
85 1.1 cgd struct ifaddr ifa;
86 1.1 cgd struct in_ifaddr in;
87 1.1 cgd struct ns_ifaddr ns;
88 1.1 cgd struct iso_ifaddr iso;
89 1.1 cgd } ifaddr;
90 1.7 cgd u_long ifaddraddr;
91 1.1 cgd struct sockaddr *sa;
92 1.15 thorpej struct ifnet_head ifhead; /* TAILQ_HEAD */
93 1.15 thorpej char name[IFNAMSIZ];
94 1.1 cgd
95 1.1 cgd if (ifnetaddr == 0) {
96 1.1 cgd printf("ifnet: symbol not defined\n");
97 1.1 cgd return;
98 1.1 cgd }
99 1.1 cgd if (interval) {
100 1.1 cgd sidewaysintpr((unsigned)interval, ifnetaddr);
101 1.1 cgd return;
102 1.1 cgd }
103 1.15 thorpej
104 1.15 thorpej /*
105 1.15 thorpej * Find the pointer to the first ifnet structure. Replace
106 1.15 thorpej * the pointer to the TAILQ_HEAD with the actual pointer
107 1.15 thorpej * to the first list element.
108 1.15 thorpej */
109 1.15 thorpej if (kread(ifnetaddr, (char *)&ifhead, sizeof ifhead))
110 1.8 mycroft return;
111 1.15 thorpej ifnetaddr = (u_long)ifhead.tqh_first;
112 1.15 thorpej
113 1.26 kml if (bflag) {
114 1.26 kml printf("%-5.5s %-5.5s %-13.13s %-17.17s "
115 1.26 kml "%10.10s %10.10s",
116 1.26 kml "Name", "Mtu", "Network", "Address",
117 1.26 kml "Ibytes", "Obytes");
118 1.26 kml } else {
119 1.26 kml printf("%-5.5s %-5.5s %-13.13s %-17.17s "
120 1.26 kml "%8.8s %5.5s %8.8s %5.5s",
121 1.26 kml "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
122 1.26 kml "Opkts", "Oerrs");
123 1.26 kml printf(" %5s", "Coll");
124 1.26 kml }
125 1.1 cgd if (tflag)
126 1.1 cgd printf(" %s", "Time");
127 1.1 cgd if (dflag)
128 1.1 cgd printf(" %s", "Drop");
129 1.1 cgd putchar('\n');
130 1.1 cgd ifaddraddr = 0;
131 1.1 cgd while (ifnetaddr || ifaddraddr) {
132 1.1 cgd struct sockaddr_in *sin;
133 1.25 lukem char *cp;
134 1.1 cgd int n, m;
135 1.1 cgd
136 1.1 cgd if (ifaddraddr == 0) {
137 1.15 thorpej if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
138 1.8 mycroft return;
139 1.25 lukem memmove(name, ifnet.if_xname, IFNAMSIZ);
140 1.15 thorpej name[IFNAMSIZ - 1] = '\0'; /* sanity */
141 1.10 mycroft ifnetaddr = (u_long)ifnet.if_list.tqe_next;
142 1.16 thorpej if (interface != 0 && strcmp(name, interface) != 0)
143 1.1 cgd continue;
144 1.25 lukem cp = strchr(name, '\0');
145 1.10 mycroft if ((ifnet.if_flags & IFF_UP) == 0)
146 1.1 cgd *cp++ = '*';
147 1.1 cgd *cp = '\0';
148 1.10 mycroft ifaddraddr = (u_long)ifnet.if_addrlist.tqh_first;
149 1.1 cgd }
150 1.21 christos printf("%-5.5s %-5ld ", name, ifnet.if_mtu);
151 1.1 cgd if (ifaddraddr == 0) {
152 1.21 christos printf("%-13.13s ", "none");
153 1.23 mikel printf("%-17.17s ", "none");
154 1.1 cgd } else {
155 1.20 thorpej char hexsep = '.'; /* for hexprint */
156 1.20 thorpej const char *hexfmt = "%x%c"; /* for hexprint */
157 1.8 mycroft if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
158 1.8 mycroft ifaddraddr = 0;
159 1.8 mycroft continue;
160 1.8 mycroft }
161 1.1 cgd #define CP(x) ((char *)(x))
162 1.8 mycroft cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
163 1.1 cgd CP(&ifaddr); sa = (struct sockaddr *)cp;
164 1.1 cgd switch (sa->sa_family) {
165 1.1 cgd case AF_UNSPEC:
166 1.21 christos printf("%-13.13s ", "none");
167 1.12 jtc printf("%-17.17s ", "none");
168 1.1 cgd break;
169 1.1 cgd case AF_INET:
170 1.1 cgd sin = (struct sockaddr_in *)sa;
171 1.1 cgd #ifdef notdef
172 1.1 cgd /* can't use inet_makeaddr because kernel
173 1.1 cgd * keeps nets unshifted.
174 1.1 cgd */
175 1.1 cgd in = inet_makeaddr(ifaddr.in.ia_subnet,
176 1.1 cgd INADDR_ANY);
177 1.21 christos printf("%-13.13s ", netname(in.s_addr,
178 1.8 mycroft ifaddr.in.ia_subnetmask));
179 1.1 cgd #else
180 1.21 christos printf("%-13.13s ",
181 1.11 mycroft netname(ifaddr.in.ia_subnet,
182 1.8 mycroft ifaddr.in.ia_subnetmask));
183 1.1 cgd #endif
184 1.12 jtc printf("%-17.17s ",
185 1.8 mycroft routename(sin->sin_addr.s_addr));
186 1.10 mycroft
187 1.10 mycroft if (aflag) {
188 1.10 mycroft u_long multiaddr;
189 1.10 mycroft struct in_multi inm;
190 1.10 mycroft
191 1.10 mycroft multiaddr = (u_long)ifaddr.in.ia_multiaddrs.lh_first;
192 1.10 mycroft while (multiaddr != 0) {
193 1.10 mycroft kread(multiaddr, (char *)&inm,
194 1.10 mycroft sizeof inm);
195 1.23 mikel printf("\n%25s %-17.17s ", "",
196 1.10 mycroft routename(inm.inm_addr.s_addr));
197 1.10 mycroft multiaddr = (u_long)inm.inm_list.le_next;
198 1.10 mycroft }
199 1.10 mycroft }
200 1.1 cgd break;
201 1.21 christos case AF_APPLETALK:
202 1.24 christos printf("atalk:%-7.7s ",
203 1.21 christos atalk_print(sa,0x10));
204 1.24 christos printf("%-17.17s ", atalk_print(sa,0x0b));
205 1.21 christos break;
206 1.1 cgd case AF_NS:
207 1.1 cgd {
208 1.1 cgd struct sockaddr_ns *sns =
209 1.1 cgd (struct sockaddr_ns *)sa;
210 1.1 cgd u_long net;
211 1.1 cgd char netnum[8];
212 1.1 cgd
213 1.1 cgd *(union ns_net *) &net = sns->sns_addr.x_net;
214 1.21 christos sprintf(netnum, "%xH", (u_int32_t) ntohl(net));
215 1.1 cgd upHex(netnum);
216 1.23 mikel printf("ns:%-10s ", netnum);
217 1.23 mikel printf("%-17.17s ",
218 1.8 mycroft ns_phost((struct sockaddr *)sns));
219 1.1 cgd }
220 1.1 cgd break;
221 1.1 cgd case AF_LINK:
222 1.1 cgd {
223 1.1 cgd struct sockaddr_dl *sdl =
224 1.1 cgd (struct sockaddr_dl *)sa;
225 1.1 cgd cp = (char *)LLADDR(sdl);
226 1.20 thorpej if (sdl->sdl_type == IFT_FDDI
227 1.20 thorpej || sdl->sdl_type == IFT_ETHER)
228 1.20 thorpej hexsep = ':', hexfmt = "%02x%c";
229 1.1 cgd n = sdl->sdl_alen;
230 1.1 cgd }
231 1.22 christos m = printf("%-13.13s ", "<Link>");
232 1.1 cgd goto hexprint;
233 1.1 cgd default:
234 1.1 cgd m = printf("(%d)", sa->sa_family);
235 1.1 cgd for (cp = sa->sa_len + (char *)sa;
236 1.1 cgd --cp > sa->sa_data && (*cp == 0);) {}
237 1.1 cgd n = cp - sa->sa_data + 1;
238 1.1 cgd cp = sa->sa_data;
239 1.1 cgd hexprint:
240 1.1 cgd while (--n >= 0)
241 1.20 thorpej m += printf(hexfmt, *cp++ & 0xff,
242 1.20 thorpej n > 0 ? hexsep : ' ');
243 1.22 christos m = 32 - m;
244 1.1 cgd while (m-- > 0)
245 1.1 cgd putchar(' ');
246 1.1 cgd break;
247 1.1 cgd }
248 1.10 mycroft ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
249 1.1 cgd }
250 1.26 kml if (bflag) {
251 1.26 kml printf("%10ld %10ld",
252 1.26 kml ifnet.if_ibytes, ifnet.if_obytes);
253 1.26 kml } else {
254 1.26 kml printf("%8ld %5ld %8ld %5ld %5ld",
255 1.26 kml ifnet.if_ipackets, ifnet.if_ierrors,
256 1.26 kml ifnet.if_opackets, ifnet.if_oerrors,
257 1.26 kml ifnet.if_collisions);
258 1.26 kml }
259 1.1 cgd if (tflag)
260 1.1 cgd printf(" %3d", ifnet.if_timer);
261 1.1 cgd if (dflag)
262 1.1 cgd printf(" %3d", ifnet.if_snd.ifq_drops);
263 1.1 cgd putchar('\n');
264 1.1 cgd }
265 1.1 cgd }
266 1.1 cgd
267 1.18 cgd #define MAXIF 100
268 1.1 cgd struct iftot {
269 1.15 thorpej char ift_name[IFNAMSIZ]; /* interface name */
270 1.1 cgd int ift_ip; /* input packets */
271 1.26 kml int ift_ib; /* input bytes */
272 1.1 cgd int ift_ie; /* input errors */
273 1.1 cgd int ift_op; /* output packets */
274 1.26 kml int ift_ob; /* output bytes */
275 1.1 cgd int ift_oe; /* output errors */
276 1.1 cgd int ift_co; /* collisions */
277 1.1 cgd int ift_dr; /* drops */
278 1.1 cgd } iftot[MAXIF];
279 1.1 cgd
280 1.1 cgd u_char signalled; /* set if alarm goes off "early" */
281 1.1 cgd
282 1.1 cgd /*
283 1.1 cgd * Print a running summary of interface statistics.
284 1.1 cgd * Repeat display every interval seconds, showing statistics
285 1.1 cgd * collected over that interval. Assumes that interval is non-zero.
286 1.1 cgd * First line printed at top of screen is always cumulative.
287 1.1 cgd */
288 1.8 mycroft static void
289 1.1 cgd sidewaysintpr(interval, off)
290 1.1 cgd unsigned interval;
291 1.7 cgd u_long off;
292 1.1 cgd {
293 1.1 cgd struct ifnet ifnet;
294 1.7 cgd u_long firstifnet;
295 1.25 lukem struct iftot *ip, *total;
296 1.25 lukem int line;
297 1.1 cgd struct iftot *lastif, *sum, *interesting;
298 1.15 thorpej struct ifnet_head ifhead; /* TAILQ_HEAD */
299 1.1 cgd int oldmask;
300 1.1 cgd
301 1.15 thorpej /*
302 1.15 thorpej * Find the pointer to the first ifnet structure. Replace
303 1.15 thorpej * the pointer to the TAILQ_HEAD with the actual pointer
304 1.15 thorpej * to the first list element.
305 1.15 thorpej */
306 1.15 thorpej if (kread(off, (char *)&ifhead, sizeof ifhead))
307 1.8 mycroft return;
308 1.15 thorpej firstifnet = (u_long)ifhead.tqh_first;
309 1.15 thorpej
310 1.1 cgd lastif = iftot;
311 1.1 cgd sum = iftot + MAXIF - 1;
312 1.1 cgd total = sum - 1;
313 1.17 cgd interesting = (interface == NULL) ? iftot : NULL;
314 1.1 cgd for (off = firstifnet, ip = iftot; off;) {
315 1.8 mycroft if (kread(off, (char *)&ifnet, sizeof ifnet))
316 1.8 mycroft break;
317 1.25 lukem memset(ip->ift_name, 0, sizeof(ip->ift_name));
318 1.19 thorpej snprintf(ip->ift_name, IFNAMSIZ, "(%s)", ifnet.if_xname);
319 1.19 thorpej if (interface && strcmp(ifnet.if_xname, interface) == 0)
320 1.1 cgd interesting = ip;
321 1.1 cgd ip++;
322 1.1 cgd if (ip >= iftot + MAXIF - 2)
323 1.1 cgd break;
324 1.10 mycroft off = (u_long)ifnet.if_list.tqe_next;
325 1.17 cgd }
326 1.17 cgd if (interesting == NULL) {
327 1.17 cgd fprintf(stderr, "%s: %s: unknown interface\n",
328 1.17 cgd __progname, interface);
329 1.17 cgd exit(1);
330 1.1 cgd }
331 1.1 cgd lastif = ip;
332 1.1 cgd
333 1.1 cgd (void)signal(SIGALRM, catchalarm);
334 1.1 cgd signalled = NO;
335 1.1 cgd (void)alarm(interval);
336 1.1 cgd banner:
337 1.1 cgd printf(" input %-6.6s output ", interesting->ift_name);
338 1.1 cgd if (lastif - iftot > 0) {
339 1.1 cgd if (dflag)
340 1.1 cgd printf(" ");
341 1.1 cgd printf(" input (Total) output");
342 1.1 cgd }
343 1.1 cgd for (ip = iftot; ip < iftot + MAXIF; ip++) {
344 1.1 cgd ip->ift_ip = 0;
345 1.26 kml ip->ift_ib = 0;
346 1.1 cgd ip->ift_ie = 0;
347 1.1 cgd ip->ift_op = 0;
348 1.26 kml ip->ift_ob = 0;
349 1.1 cgd ip->ift_oe = 0;
350 1.1 cgd ip->ift_co = 0;
351 1.1 cgd ip->ift_dr = 0;
352 1.1 cgd }
353 1.1 cgd putchar('\n');
354 1.26 kml if (bflag) {
355 1.26 kml printf("%10.10s %8.8s %10.10s %5.5s",
356 1.26 kml "bytes", " ", "bytes", " ");
357 1.26 kml } else {
358 1.26 kml printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
359 1.26 kml "packets", "errs", "packets", "errs", "colls");
360 1.26 kml }
361 1.1 cgd if (dflag)
362 1.1 cgd printf("%5.5s ", "drops");
363 1.1 cgd if (lastif - iftot > 0)
364 1.26 kml if (bflag) {
365 1.26 kml printf("%10.10s %8.8s %10.10s %5.5s",
366 1.26 kml "bytes", " ", "bytes", " ");
367 1.26 kml } else {
368 1.26 kml printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
369 1.26 kml "packets", "errs", "packets", "errs", "colls");
370 1.26 kml }
371 1.1 cgd if (dflag)
372 1.1 cgd printf(" %5.5s", "drops");
373 1.1 cgd putchar('\n');
374 1.1 cgd fflush(stdout);
375 1.1 cgd line = 0;
376 1.1 cgd loop:
377 1.1 cgd sum->ift_ip = 0;
378 1.26 kml sum->ift_ib = 0;
379 1.1 cgd sum->ift_ie = 0;
380 1.1 cgd sum->ift_op = 0;
381 1.26 kml sum->ift_ob = 0;
382 1.1 cgd sum->ift_oe = 0;
383 1.1 cgd sum->ift_co = 0;
384 1.1 cgd sum->ift_dr = 0;
385 1.1 cgd for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
386 1.8 mycroft if (kread(off, (char *)&ifnet, sizeof ifnet)) {
387 1.8 mycroft off = 0;
388 1.8 mycroft continue;
389 1.8 mycroft }
390 1.1 cgd if (ip == interesting) {
391 1.26 kml if (bflag) {
392 1.26 kml printf("%10ld %8.8s %10ld %5.5s",
393 1.26 kml ifnet.if_ibytes - ip->ift_ib, " ",
394 1.26 kml ifnet.if_obytes - ip->ift_ob, " ");
395 1.26 kml } else {
396 1.26 kml printf("%8ld %5ld %8ld %5ld %5ld",
397 1.26 kml ifnet.if_ipackets - ip->ift_ip,
398 1.26 kml ifnet.if_ierrors - ip->ift_ie,
399 1.26 kml ifnet.if_opackets - ip->ift_op,
400 1.26 kml ifnet.if_oerrors - ip->ift_oe,
401 1.26 kml ifnet.if_collisions - ip->ift_co);
402 1.26 kml }
403 1.1 cgd if (dflag)
404 1.1 cgd printf(" %5d",
405 1.1 cgd ifnet.if_snd.ifq_drops - ip->ift_dr);
406 1.1 cgd }
407 1.1 cgd ip->ift_ip = ifnet.if_ipackets;
408 1.26 kml ip->ift_ib = ifnet.if_ibytes;
409 1.1 cgd ip->ift_ie = ifnet.if_ierrors;
410 1.1 cgd ip->ift_op = ifnet.if_opackets;
411 1.26 kml ip->ift_ob = ifnet.if_obytes;
412 1.1 cgd ip->ift_oe = ifnet.if_oerrors;
413 1.1 cgd ip->ift_co = ifnet.if_collisions;
414 1.1 cgd ip->ift_dr = ifnet.if_snd.ifq_drops;
415 1.1 cgd sum->ift_ip += ip->ift_ip;
416 1.26 kml sum->ift_ib += ip->ift_ib;
417 1.1 cgd sum->ift_ie += ip->ift_ie;
418 1.1 cgd sum->ift_op += ip->ift_op;
419 1.26 kml sum->ift_ob += ip->ift_ob;
420 1.1 cgd sum->ift_oe += ip->ift_oe;
421 1.1 cgd sum->ift_co += ip->ift_co;
422 1.1 cgd sum->ift_dr += ip->ift_dr;
423 1.10 mycroft off = (u_long)ifnet.if_list.tqe_next;
424 1.1 cgd }
425 1.1 cgd if (lastif - iftot > 0) {
426 1.26 kml if (bflag) {
427 1.26 kml printf(" %10d %8.8s %10d %5.5s",
428 1.26 kml sum->ift_ib - total->ift_ib, " ",
429 1.26 kml sum->ift_ob - total->ift_ob, " ");
430 1.26 kml } else {
431 1.26 kml printf(" %8d %5d %8d %5d %5d",
432 1.26 kml sum->ift_ip - total->ift_ip,
433 1.26 kml sum->ift_ie - total->ift_ie,
434 1.26 kml sum->ift_op - total->ift_op,
435 1.26 kml sum->ift_oe - total->ift_oe,
436 1.26 kml sum->ift_co - total->ift_co);
437 1.26 kml }
438 1.1 cgd if (dflag)
439 1.1 cgd printf(" %5d", sum->ift_dr - total->ift_dr);
440 1.1 cgd }
441 1.1 cgd *total = *sum;
442 1.1 cgd putchar('\n');
443 1.1 cgd fflush(stdout);
444 1.1 cgd line++;
445 1.1 cgd oldmask = sigblock(sigmask(SIGALRM));
446 1.1 cgd if (! signalled) {
447 1.1 cgd sigpause(0);
448 1.1 cgd }
449 1.1 cgd sigsetmask(oldmask);
450 1.1 cgd signalled = NO;
451 1.1 cgd (void)alarm(interval);
452 1.1 cgd if (line == 21)
453 1.1 cgd goto banner;
454 1.1 cgd goto loop;
455 1.1 cgd /*NOTREACHED*/
456 1.1 cgd }
457 1.1 cgd
458 1.1 cgd /*
459 1.1 cgd * Called if an interval expires before sidewaysintpr has completed a loop.
460 1.1 cgd * Sets a flag to not wait for the alarm.
461 1.1 cgd */
462 1.8 mycroft static void
463 1.8 mycroft catchalarm(signo)
464 1.8 mycroft int signo;
465 1.1 cgd {
466 1.1 cgd signalled = YES;
467 1.1 cgd }
468