]> git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/route.c
1e7befcbf441301149eb10f2356d97e62d9bc239
[apple/network_cmds.git] / netstat.tproj / route.c
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1983, 1988, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 */
60
61 #include <stdint.h>
62 #include <sys/param.h>
63 #include <sys/socket.h>
64 #include <sys/time.h>
65
66 #include <net/if.h>
67 #include <net/if_var.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/route.h>
71 #include <net/radix.h>
72
73 #include <netinet/in.h>
74
75 #include <sys/sysctl.h>
76
77 #include <arpa/inet.h>
78 #include <netdb.h>
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <string.h>
82 #include <unistd.h>
83 #include <err.h>
84 #include <time.h>
85 #include "netstat.h"
86
87 /* alignment constraint for routing socket */
88 #define ROUNDUP(a) \
89 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
90 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
91
92 /*
93 * Definitions for showing gateway flags.
94 */
95 struct bits {
96 uint32_t b_mask;
97 char b_val;
98 } bits[] = {
99 { RTF_UP, 'U' },
100 { RTF_GATEWAY, 'G' },
101 { RTF_HOST, 'H' },
102 { RTF_REJECT, 'R' },
103 { RTF_DYNAMIC, 'D' },
104 { RTF_MODIFIED, 'M' },
105 { RTF_MULTICAST,'m' },
106 { RTF_DONE, 'd' }, /* Completed -- for routing messages only */
107 { RTF_CLONING, 'C' },
108 { RTF_XRESOLVE, 'X' },
109 { RTF_LLINFO, 'L' },
110 { RTF_STATIC, 'S' },
111 { RTF_PROTO1, '1' },
112 { RTF_PROTO2, '2' },
113 { RTF_WASCLONED,'W' },
114 { RTF_PRCLONING,'c' },
115 { RTF_PROTO3, '3' },
116 { RTF_BLACKHOLE,'B' },
117 { RTF_BROADCAST,'b' },
118 { RTF_IFSCOPE, 'I' },
119 { RTF_IFREF, 'i' },
120 { 0 }
121 };
122
123 typedef union {
124 uint32_t dummy; /* Helps align structure. */
125 struct sockaddr u_sa;
126 u_short u_data[128];
127 } sa_u;
128
129 static void ntreestuff __P((void));
130 static void np_rtentry __P((struct rt_msghdr2 *));
131 static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
132 static void p_flags __P((int, char *));
133 static uint32_t forgemask __P((uint32_t));
134 static void domask __P((char *, uint32_t, uint32_t));
135
136 /*
137 * Print routing tables.
138 */
139 void
140 routepr(uint32_t rtree)
141 {
142 printf("Routing tables\n");
143
144 if (dflag == 0) {
145 ntreestuff();
146 } else {
147 if (rtree == 0) {
148 printf("rt_tables: symbol not in namelist\n");
149 return;
150 }
151 }
152 }
153
154 /*
155 * Print address family header before a section of the routing table.
156 */
157 void
158 pr_family(int af)
159 {
160 char *afname;
161
162 switch (af) {
163 case AF_INET:
164 afname = "Internet";
165 break;
166 #ifdef INET6
167 case AF_INET6:
168 afname = "Internet6";
169 break;
170 #endif /*INET6*/
171 case AF_IPX:
172 afname = "IPX";
173 break;
174 default:
175 afname = NULL;
176 break;
177 }
178 if (afname)
179 printf("\n%s:\n", afname);
180 else
181 printf("\nProtocol Family %d:\n", af);
182 }
183
184 /* column widths; each followed by one space */
185 #ifndef INET6
186 #define WID_DST(af) 18 /* width of destination column */
187 #define WID_GW(af) 18 /* width of gateway column */
188 #define WID_IF(af) 7 /* width of netif column */
189 #else
190 #define WID_DST(af) \
191 ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
192 #define WID_GW(af) \
193 ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
194 #define WID_IF(af) ((af) == AF_INET6 ? 8 : 7)
195 #endif /*INET6*/
196
197 /*
198 * Print header for routing table columns.
199 */
200 void
201 pr_rthdr(int af)
202 {
203
204 if (Aflag)
205 printf("%-8.8s ","Address");
206 if (af == AF_INET || lflag)
207 if (lflag)
208 printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
209 WID_DST(af), WID_DST(af), "Destination",
210 WID_GW(af), WID_GW(af), "Gateway",
211 "Flags", "Refs", "Use", "Mtu",
212 WID_IF(af), WID_IF(af), "Netif", "Expire");
213 else
214 printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %*.*s %6s\n",
215 WID_DST(af), WID_DST(af), "Destination",
216 WID_GW(af), WID_GW(af), "Gateway",
217 "Flags", "Refs", "Use",
218 WID_IF(af), WID_IF(af), "Netif", "Expire");
219 else
220 printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n",
221 WID_DST(af), WID_DST(af), "Destination",
222 WID_GW(af), WID_GW(af), "Gateway",
223 "Flags", "Netif", "Expire");
224 }
225
226 static void
227 ntreestuff(void)
228 {
229 size_t needed;
230 int mib[6];
231 char *buf, *next, *lim;
232 struct rt_msghdr2 *rtm;
233
234 mib[0] = CTL_NET;
235 mib[1] = PF_ROUTE;
236 mib[2] = 0;
237 mib[3] = 0;
238 mib[4] = NET_RT_DUMP2;
239 mib[5] = 0;
240 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
241 err(1, "sysctl: net.route.0.0.dump estimate");
242 }
243
244 if ((buf = malloc(needed)) == 0) {
245 err(2, "malloc(%lu)", (unsigned long)needed);
246 }
247 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
248 err(1, "sysctl: net.route.0.0.dump");
249 }
250 lim = buf + needed;
251 for (next = buf; next < lim; next += rtm->rtm_msglen) {
252 rtm = (struct rt_msghdr2 *)next;
253 np_rtentry(rtm);
254 }
255 }
256
257 static void
258 get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
259 {
260 int i;
261
262 for (i = 0; i < RTAX_MAX; i++) {
263 if (addrs & (1 << i)) {
264 rti_info[i] = sa;
265 sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
266 } else {
267 rti_info[i] = NULL;
268 }
269 }
270 }
271
272 static void
273 np_rtentry(struct rt_msghdr2 *rtm)
274 {
275 struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
276 struct sockaddr *rti_info[RTAX_MAX];
277 static int old_fam;
278 int fam = 0;
279 u_short lastindex = 0xffff;
280 static char ifname[IFNAMSIZ + 1];
281 sa_u addr, mask;
282
283 /*
284 * Don't print protocol-cloned routes unless -a.
285 */
286 if ((rtm->rtm_flags & RTF_WASCLONED) &&
287 (rtm->rtm_parentflags & RTF_PRCLONING) &&
288 !aflag) {
289 return;
290 }
291
292 fam = sa->sa_family;
293 if (af != AF_UNSPEC && af != fam)
294 return;
295 if (fam != old_fam) {
296 pr_family(fam);
297 pr_rthdr(fam);
298 old_fam = fam;
299 }
300 get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
301 bzero(&addr, sizeof(addr));
302 if ((rtm->rtm_addrs & RTA_DST))
303 bcopy(rti_info[RTAX_DST], &addr, rti_info[RTAX_DST]->sa_len);
304 bzero(&mask, sizeof(mask));
305 if ((rtm->rtm_addrs & RTA_NETMASK))
306 bcopy(rti_info[RTAX_NETMASK], &mask, rti_info[RTAX_NETMASK]->sa_len);
307 p_sockaddr(&addr.u_sa, &mask.u_sa, rtm->rtm_flags,
308 WID_DST(addr.u_sa.sa_family));
309
310 p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST,
311 WID_GW(addr.u_sa.sa_family));
312
313 p_flags(rtm->rtm_flags, "%-10.10s ");
314
315 if (addr.u_sa.sa_family == AF_INET || lflag) {
316 printf("%6u %8u ", rtm->rtm_refcnt, (unsigned int)rtm->rtm_use);
317 if (lflag) {
318 if (rtm->rtm_rmx.rmx_mtu != 0)
319 printf("%6u ", rtm->rtm_rmx.rmx_mtu);
320 else
321 printf("%6s ", "");
322 }
323 }
324 if (rtm->rtm_index != lastindex) {
325 if_indextoname(rtm->rtm_index, ifname);
326 lastindex = rtm->rtm_index;
327 }
328 printf("%*.*s", WID_IF(addr.u_sa.sa_family),
329 WID_IF(addr.u_sa.sa_family), ifname);
330
331 if (rtm->rtm_rmx.rmx_expire) {
332 time_t expire_time;
333
334 if ((expire_time =
335 rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0)
336 printf(" %6d", (int)expire_time);
337 }
338 putchar('\n');
339 }
340
341 static void
342 p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width)
343 {
344 char workbuf[128], *cplim;
345 char *cp = workbuf;
346
347 switch(sa->sa_family) {
348 case AF_INET: {
349 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
350
351 if ((sin->sin_addr.s_addr == INADDR_ANY) &&
352 mask &&
353 (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L || mask->sa_len == 0))
354 cp = "default" ;
355 else if (flags & RTF_HOST)
356 cp = routename(sin->sin_addr.s_addr);
357 else if (mask)
358 cp = netname(sin->sin_addr.s_addr,
359 ntohl(((struct sockaddr_in *)mask)->
360 sin_addr.s_addr));
361 else
362 cp = netname(sin->sin_addr.s_addr, 0L);
363 break;
364 }
365
366 #ifdef INET6
367 case AF_INET6: {
368 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
369 struct in6_addr *in6 = &sa6->sin6_addr;
370
371 /*
372 * XXX: This is a special workaround for KAME kernels.
373 * sin6_scope_id field of SA should be set in the future.
374 */
375 if (IN6_IS_ADDR_LINKLOCAL(in6) ||
376 IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
377 /* XXX: override is ok? */
378 sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
379 *(u_short *)&in6->s6_addr[2] = 0;
380 }
381
382 if (flags & RTF_HOST)
383 cp = routename6(sa6);
384 else if (mask)
385 cp = netname6(sa6, mask);
386 else
387 cp = netname6(sa6, NULL);
388 break;
389 }
390 #endif /*INET6*/
391
392 case AF_LINK: {
393 struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
394
395 if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
396 sdl->sdl_slen == 0) {
397 (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
398 } else {
399 switch (sdl->sdl_type) {
400
401 case IFT_ETHER: {
402 int i;
403 u_char *lla = (u_char *)sdl->sdl_data +
404 sdl->sdl_nlen;
405
406 cplim = "";
407 for (i = 0; i < sdl->sdl_alen; i++, lla++) {
408 cp += sprintf(cp, "%s%x", cplim, *lla);
409 cplim = ":";
410 }
411 cp = workbuf;
412 break;
413 }
414
415 default:
416 cp = link_ntoa(sdl);
417 break;
418 }
419 }
420 break;
421 }
422
423 default: {
424 u_char *s = (u_char *)sa->sa_data, *slim;
425
426 slim = sa->sa_len + (u_char *) sa;
427 cplim = cp + sizeof(workbuf) - 6;
428 cp += sprintf(cp, "(%d)", sa->sa_family);
429 while (s < slim && cp < cplim) {
430 cp += sprintf(cp, " %02x", *s++);
431 if (s < slim)
432 cp += sprintf(cp, "%02x", *s++);
433 }
434 cp = workbuf;
435 }
436 }
437 if (width < 0 ) {
438 printf("%s ", cp);
439 } else {
440 if (nflag)
441 printf("%-*s ", width, cp);
442 else
443 printf("%-*.*s ", width, width, cp);
444 }
445 }
446
447 static void
448 p_flags(int f, char *format)
449 {
450 char name[33], *flags;
451 struct bits *p = bits;
452
453 for (flags = name; p->b_mask; p++)
454 if (p->b_mask & f)
455 *flags++ = p->b_val;
456 *flags = '\0';
457 printf(format, name);
458 }
459
460 char *
461 routename(uint32_t in)
462 {
463 char *cp;
464 static char line[MAXHOSTNAMELEN];
465 struct hostent *hp;
466
467 cp = 0;
468 if (!nflag) {
469 hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
470 AF_INET);
471 if (hp) {
472 cp = hp->h_name;
473 //### trimdomain(cp, strlen(cp));
474 }
475 }
476 if (cp) {
477 strncpy(line, cp, sizeof(line) - 1);
478 line[sizeof(line) - 1] = '\0';
479 } else {
480 #define C(x) ((x) & 0xff)
481 in = ntohl(in);
482 sprintf(line, "%u.%u.%u.%u",
483 C(in >> 24), C(in >> 16), C(in >> 8), C(in));
484 }
485 return (line);
486 }
487
488 static uint32_t
489 forgemask(uint32_t a)
490 {
491 uint32_t m;
492
493 if (IN_CLASSA(a))
494 m = IN_CLASSA_NET;
495 else if (IN_CLASSB(a))
496 m = IN_CLASSB_NET;
497 else
498 m = IN_CLASSC_NET;
499 return (m);
500 }
501
502 static void
503 domask(char *dst, uint32_t addr, uint32_t mask)
504 {
505 int b, i;
506
507 if (!mask || (forgemask(addr) == mask)) {
508 *dst = '\0';
509 return;
510 }
511 i = 0;
512 for (b = 0; b < 32; b++)
513 if (mask & (1 << b)) {
514 int bb;
515
516 i = b;
517 for (bb = b+1; bb < 32; bb++)
518 if (!(mask & (1 << bb))) {
519 i = -1; /* noncontig */
520 break;
521 }
522 break;
523 }
524 if (i == -1)
525 sprintf(dst, "&0x%x", mask);
526 else
527 sprintf(dst, "/%d", 32-i);
528 }
529
530 /*
531 * Return the name of the network whose address is given.
532 * The address is assumed to be that of a net or subnet, not a host.
533 */
534 char *
535 netname(uint32_t in, uint32_t mask)
536 {
537 char *cp = 0;
538 static char line[MAXHOSTNAMELEN];
539 struct netent *np = 0;
540 uint32_t net, omask, dmask;
541 uint32_t i;
542
543 i = ntohl(in);
544 dmask = forgemask(i);
545 omask = mask;
546 if (!nflag && i) {
547 net = i & dmask;
548 if (!(np = getnetbyaddr(i, AF_INET)) && net != i)
549 np = getnetbyaddr(net, AF_INET);
550 if (np) {
551 cp = np->n_name;
552 //### trimdomain(cp, strlen(cp));
553 }
554 }
555 if (cp)
556 strncpy(line, cp, sizeof(line) - 1);
557 else {
558 switch (dmask) {
559 case IN_CLASSA_NET:
560 if ((i & IN_CLASSA_HOST) == 0) {
561 sprintf(line, "%u", C(i >> 24));
562 break;
563 }
564 /* FALLTHROUGH */
565 case IN_CLASSB_NET:
566 if ((i & IN_CLASSB_HOST) == 0) {
567 sprintf(line, "%u.%u",
568 C(i >> 24), C(i >> 16));
569 break;
570 }
571 /* FALLTHROUGH */
572 case IN_CLASSC_NET:
573 if ((i & IN_CLASSC_HOST) == 0) {
574 sprintf(line, "%u.%u.%u",
575 C(i >> 24), C(i >> 16), C(i >> 8));
576 break;
577 }
578 /* FALLTHROUGH */
579 default:
580 sprintf(line, "%u.%u.%u.%u",
581 C(i >> 24), C(i >> 16), C(i >> 8), C(i));
582 break;
583 }
584 }
585 domask(line+strlen(line), i, omask);
586 return (line);
587 }
588
589 #ifdef INET6
590 char *
591 netname6(struct sockaddr_in6 *sa6, struct sockaddr *sam)
592 {
593 static char line[MAXHOSTNAMELEN];
594 u_char *lim;
595 int masklen, illegal = 0, flag = NI_WITHSCOPEID;
596 struct in6_addr *mask = sam ? &((struct sockaddr_in6 *)sam)->sin6_addr : 0;
597
598 if (sam && sam->sa_len == 0) {
599 masklen = 0;
600 } else if (mask) {
601 u_char *p = (u_char *)mask;
602 for (masklen = 0, lim = p + 16; p < lim; p++) {
603 switch (*p) {
604 case 0xff:
605 masklen += 8;
606 break;
607 case 0xfe:
608 masklen += 7;
609 break;
610 case 0xfc:
611 masklen += 6;
612 break;
613 case 0xf8:
614 masklen += 5;
615 break;
616 case 0xf0:
617 masklen += 4;
618 break;
619 case 0xe0:
620 masklen += 3;
621 break;
622 case 0xc0:
623 masklen += 2;
624 break;
625 case 0x80:
626 masklen += 1;
627 break;
628 case 0x00:
629 break;
630 default:
631 illegal ++;
632 break;
633 }
634 }
635 if (illegal)
636 fprintf(stderr, "illegal prefixlen\n");
637 } else {
638 masklen = 128;
639 }
640 if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
641 return("default");
642
643 if (nflag)
644 flag |= NI_NUMERICHOST;
645 getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
646 NULL, 0, flag);
647
648 if (nflag)
649 sprintf(&line[strlen(line)], "/%d", masklen);
650
651 return line;
652 }
653
654 char *
655 routename6(struct sockaddr_in6 *sa6)
656 {
657 static char line[MAXHOSTNAMELEN];
658 int flag = NI_WITHSCOPEID;
659 /* use local variable for safety */
660 struct sockaddr_in6 sa6_local = {sizeof(sa6_local), AF_INET6, };
661
662 sa6_local.sin6_addr = sa6->sin6_addr;
663 sa6_local.sin6_scope_id = sa6->sin6_scope_id;
664
665 if (nflag)
666 flag |= NI_NUMERICHOST;
667
668 getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
669 line, sizeof(line), NULL, 0, flag);
670
671 return line;
672 }
673 #endif /*INET6*/
674
675 /*
676 * Print routing statistics
677 */
678 void
679 rt_stats(void)
680 {
681 struct rtstat rtstat;
682 int rttrash;
683 int mib[6];
684 size_t len;
685
686 mib[0] = CTL_NET;
687 mib[1] = AF_ROUTE;
688 mib[2] = 0;
689 mib[3] = 0;
690 mib[4] = NET_RT_STAT;
691 mib[5] = 0;
692 len = sizeof(struct rtstat);
693 if (sysctl(mib, 6, &rtstat, &len, 0, 0) == -1)
694 return;
695
696 mib[0] = CTL_NET;
697 mib[1] = AF_ROUTE;
698 mib[2] = 0;
699 mib[3] = 0;
700 mib[4] = NET_RT_TRASH;
701 mib[5] = 0;
702 len = sizeof(rttrash);
703 if (sysctl(mib, 6, &rttrash, &len, 0, 0) == -1)
704 return;
705
706 printf("routing:\n");
707
708 #define p(f, m) if (rtstat.f || sflag <= 1) \
709 printf(m, rtstat.f, plural(rtstat.f))
710
711 p(rts_badredirect, "\t%u bad routing redirect%s\n");
712 p(rts_dynamic, "\t%u dynamically created route%s\n");
713 p(rts_newgateway, "\t%u new gateway%s due to redirects\n");
714 p(rts_unreach, "\t%u destination%s found unreachable\n");
715 p(rts_wildcard, "\t%u use%s of a wildcard route\n");
716 #undef p
717
718 if (rttrash || sflag <= 1)
719 printf("\t%u route%s not in table but not freed\n",
720 rttrash, plural(rttrash));
721 }
722
723 void
724 upHex(char *p0)
725 {
726 char *p = p0;
727
728 for (; *p; p++)
729 switch (*p) {
730
731 case 'a':
732 case 'b':
733 case 'c':
734 case 'd':
735 case 'e':
736 case 'f':
737 *p += ('A' - 'a');
738 break;
739 }
740 }