]> git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/route.c
576d51e0fac5d09413c1feafba7536f60bc33238
[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 { 0 }
120 };
121
122 typedef union {
123 uint32_t dummy; /* Helps align structure. */
124 struct sockaddr u_sa;
125 u_short u_data[128];
126 } sa_u;
127
128 static void ntreestuff __P((void));
129 static void np_rtentry __P((struct rt_msghdr2 *));
130 static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
131 static void p_flags __P((int, char *));
132 static uint32_t forgemask __P((uint32_t));
133 static void domask __P((char *, uint32_t, uint32_t));
134
135 /*
136 * Print routing tables.
137 */
138 void
139 routepr(uint32_t rtree)
140 {
141 printf("Routing tables\n");
142
143 if (dflag == 0) {
144 ntreestuff();
145 } else {
146 if (rtree == 0) {
147 printf("rt_tables: symbol not in namelist\n");
148 return;
149 }
150 }
151 }
152
153 /*
154 * Print address family header before a section of the routing table.
155 */
156 void
157 pr_family(int af)
158 {
159 char *afname;
160
161 switch (af) {
162 case AF_INET:
163 afname = "Internet";
164 break;
165 #ifdef INET6
166 case AF_INET6:
167 afname = "Internet6";
168 break;
169 #endif /*INET6*/
170 case AF_IPX:
171 afname = "IPX";
172 break;
173 default:
174 afname = NULL;
175 break;
176 }
177 if (afname)
178 printf("\n%s:\n", afname);
179 else
180 printf("\nProtocol Family %d:\n", af);
181 }
182
183 /* column widths; each followed by one space */
184 #ifndef INET6
185 #define WID_DST(af) 18 /* width of destination column */
186 #define WID_GW(af) 18 /* width of gateway column */
187 #define WID_IF(af) 7 /* width of netif column */
188 #else
189 #define WID_DST(af) \
190 ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
191 #define WID_GW(af) \
192 ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
193 #define WID_IF(af) ((af) == AF_INET6 ? 8 : 7)
194 #endif /*INET6*/
195
196 /*
197 * Print header for routing table columns.
198 */
199 void
200 pr_rthdr(int af)
201 {
202
203 if (Aflag)
204 printf("%-8.8s ","Address");
205 if (af == AF_INET || lflag)
206 if (lflag)
207 printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
208 WID_DST(af), WID_DST(af), "Destination",
209 WID_GW(af), WID_GW(af), "Gateway",
210 "Flags", "Refs", "Use", "Mtu",
211 WID_IF(af), WID_IF(af), "Netif", "Expire");
212 else
213 printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %*.*s %6s\n",
214 WID_DST(af), WID_DST(af), "Destination",
215 WID_GW(af), WID_GW(af), "Gateway",
216 "Flags", "Refs", "Use",
217 WID_IF(af), WID_IF(af), "Netif", "Expire");
218 else
219 printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n",
220 WID_DST(af), WID_DST(af), "Destination",
221 WID_GW(af), WID_GW(af), "Gateway",
222 "Flags", "Netif", "Expire");
223 }
224
225 static void
226 ntreestuff(void)
227 {
228 size_t needed;
229 int mib[6];
230 char *buf, *next, *lim;
231 struct rt_msghdr2 *rtm;
232
233 mib[0] = CTL_NET;
234 mib[1] = PF_ROUTE;
235 mib[2] = 0;
236 mib[3] = 0;
237 mib[4] = NET_RT_DUMP2;
238 mib[5] = 0;
239 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
240 err(1, "sysctl: net.route.0.0.dump estimate");
241 }
242
243 if ((buf = malloc(needed)) == 0) {
244 err(2, "malloc(%lu)", (unsigned long)needed);
245 }
246 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
247 err(1, "sysctl: net.route.0.0.dump");
248 }
249 lim = buf + needed;
250 for (next = buf; next < lim; next += rtm->rtm_msglen) {
251 rtm = (struct rt_msghdr2 *)next;
252 np_rtentry(rtm);
253 }
254 }
255
256 static void
257 get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
258 {
259 int i;
260
261 for (i = 0; i < RTAX_MAX; i++) {
262 if (addrs & (1 << i)) {
263 rti_info[i] = sa;
264 sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
265 } else {
266 rti_info[i] = NULL;
267 }
268 }
269 }
270
271 static void
272 np_rtentry(struct rt_msghdr2 *rtm)
273 {
274 struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
275 struct sockaddr *rti_info[RTAX_MAX];
276 static int old_fam;
277 int fam = 0;
278 u_short lastindex = 0xffff;
279 static char ifname[IFNAMSIZ + 1];
280 sa_u addr, mask;
281
282 /*
283 * Don't print protocol-cloned routes unless -a.
284 */
285 if ((rtm->rtm_flags & RTF_WASCLONED) &&
286 (rtm->rtm_parentflags & RTF_PRCLONING) &&
287 !aflag) {
288 return;
289 }
290
291 fam = sa->sa_family;
292 if (af != AF_UNSPEC && af != fam)
293 return;
294 if (fam != old_fam) {
295 pr_family(fam);
296 pr_rthdr(fam);
297 old_fam = fam;
298 }
299 get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
300 bzero(&addr, sizeof(addr));
301 if ((rtm->rtm_addrs & RTA_DST))
302 bcopy(rti_info[RTAX_DST], &addr, rti_info[RTAX_DST]->sa_len);
303 bzero(&mask, sizeof(mask));
304 if ((rtm->rtm_addrs & RTA_NETMASK))
305 bcopy(rti_info[RTAX_NETMASK], &mask, rti_info[RTAX_NETMASK]->sa_len);
306 p_sockaddr(&addr.u_sa, &mask.u_sa, rtm->rtm_flags,
307 WID_DST(addr.u_sa.sa_family));
308
309 p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST,
310 WID_GW(addr.u_sa.sa_family));
311
312 p_flags(rtm->rtm_flags, "%-10.10s ");
313
314 if (addr.u_sa.sa_family == AF_INET || lflag) {
315 printf("%6u %8u ", rtm->rtm_refcnt, (unsigned int)rtm->rtm_use);
316 if (lflag) {
317 if (rtm->rtm_rmx.rmx_mtu != 0)
318 printf("%6u ", rtm->rtm_rmx.rmx_mtu);
319 else
320 printf("%6s ", "");
321 }
322 }
323 if (rtm->rtm_index != lastindex) {
324 if_indextoname(rtm->rtm_index, ifname);
325 lastindex = rtm->rtm_index;
326 }
327 printf("%*.*s", WID_IF(addr.u_sa.sa_family),
328 WID_IF(addr.u_sa.sa_family), ifname);
329
330 if (rtm->rtm_rmx.rmx_expire) {
331 time_t expire_time;
332
333 if ((expire_time =
334 rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0)
335 printf(" %6d", (int)expire_time);
336 }
337 putchar('\n');
338 }
339
340 static void
341 p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width)
342 {
343 char workbuf[128], *cplim;
344 char *cp = workbuf;
345
346 switch(sa->sa_family) {
347 case AF_INET: {
348 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
349
350 if ((sin->sin_addr.s_addr == INADDR_ANY) &&
351 mask &&
352 (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L || mask->sa_len == 0))
353 cp = "default" ;
354 else if (flags & RTF_HOST)
355 cp = routename(sin->sin_addr.s_addr);
356 else if (mask)
357 cp = netname(sin->sin_addr.s_addr,
358 ntohl(((struct sockaddr_in *)mask)->
359 sin_addr.s_addr));
360 else
361 cp = netname(sin->sin_addr.s_addr, 0L);
362 break;
363 }
364
365 #ifdef INET6
366 case AF_INET6: {
367 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
368 struct in6_addr *in6 = &sa6->sin6_addr;
369
370 /*
371 * XXX: This is a special workaround for KAME kernels.
372 * sin6_scope_id field of SA should be set in the future.
373 */
374 if (IN6_IS_ADDR_LINKLOCAL(in6) ||
375 IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
376 /* XXX: override is ok? */
377 sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
378 *(u_short *)&in6->s6_addr[2] = 0;
379 }
380
381 if (flags & RTF_HOST)
382 cp = routename6(sa6);
383 else if (mask)
384 cp = netname6(sa6, mask);
385 else
386 cp = netname6(sa6, NULL);
387 break;
388 }
389 #endif /*INET6*/
390
391 case AF_LINK: {
392 struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
393
394 if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
395 sdl->sdl_slen == 0) {
396 (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
397 } else {
398 switch (sdl->sdl_type) {
399
400 case IFT_ETHER: {
401 int i;
402 u_char *lla = (u_char *)sdl->sdl_data +
403 sdl->sdl_nlen;
404
405 cplim = "";
406 for (i = 0; i < sdl->sdl_alen; i++, lla++) {
407 cp += sprintf(cp, "%s%x", cplim, *lla);
408 cplim = ":";
409 }
410 cp = workbuf;
411 break;
412 }
413
414 default:
415 cp = link_ntoa(sdl);
416 break;
417 }
418 }
419 break;
420 }
421
422 default: {
423 u_char *s = (u_char *)sa->sa_data, *slim;
424
425 slim = sa->sa_len + (u_char *) sa;
426 cplim = cp + sizeof(workbuf) - 6;
427 cp += sprintf(cp, "(%d)", sa->sa_family);
428 while (s < slim && cp < cplim) {
429 cp += sprintf(cp, " %02x", *s++);
430 if (s < slim)
431 cp += sprintf(cp, "%02x", *s++);
432 }
433 cp = workbuf;
434 }
435 }
436 if (width < 0 ) {
437 printf("%s ", cp);
438 } else {
439 if (nflag)
440 printf("%-*s ", width, cp);
441 else
442 printf("%-*.*s ", width, width, cp);
443 }
444 }
445
446 static void
447 p_flags(int f, char *format)
448 {
449 char name[33], *flags;
450 struct bits *p = bits;
451
452 for (flags = name; p->b_mask; p++)
453 if (p->b_mask & f)
454 *flags++ = p->b_val;
455 *flags = '\0';
456 printf(format, name);
457 }
458
459 char *
460 routename(uint32_t in)
461 {
462 char *cp;
463 static char line[MAXHOSTNAMELEN];
464 struct hostent *hp;
465
466 cp = 0;
467 if (!nflag) {
468 hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
469 AF_INET);
470 if (hp) {
471 cp = hp->h_name;
472 //### trimdomain(cp, strlen(cp));
473 }
474 }
475 if (cp) {
476 strncpy(line, cp, sizeof(line) - 1);
477 line[sizeof(line) - 1] = '\0';
478 } else {
479 #define C(x) ((x) & 0xff)
480 in = ntohl(in);
481 sprintf(line, "%u.%u.%u.%u",
482 C(in >> 24), C(in >> 16), C(in >> 8), C(in));
483 }
484 return (line);
485 }
486
487 static uint32_t
488 forgemask(uint32_t a)
489 {
490 uint32_t m;
491
492 if (IN_CLASSA(a))
493 m = IN_CLASSA_NET;
494 else if (IN_CLASSB(a))
495 m = IN_CLASSB_NET;
496 else
497 m = IN_CLASSC_NET;
498 return (m);
499 }
500
501 static void
502 domask(char *dst, uint32_t addr, uint32_t mask)
503 {
504 int b, i;
505
506 if (!mask || (forgemask(addr) == mask)) {
507 *dst = '\0';
508 return;
509 }
510 i = 0;
511 for (b = 0; b < 32; b++)
512 if (mask & (1 << b)) {
513 int bb;
514
515 i = b;
516 for (bb = b+1; bb < 32; bb++)
517 if (!(mask & (1 << bb))) {
518 i = -1; /* noncontig */
519 break;
520 }
521 break;
522 }
523 if (i == -1)
524 sprintf(dst, "&0x%x", mask);
525 else
526 sprintf(dst, "/%d", 32-i);
527 }
528
529 /*
530 * Return the name of the network whose address is given.
531 * The address is assumed to be that of a net or subnet, not a host.
532 */
533 char *
534 netname(uint32_t in, uint32_t mask)
535 {
536 char *cp = 0;
537 static char line[MAXHOSTNAMELEN];
538 struct netent *np = 0;
539 uint32_t net, omask, dmask;
540 uint32_t i;
541
542 i = ntohl(in);
543 dmask = forgemask(i);
544 omask = mask;
545 if (!nflag && i) {
546 net = i & dmask;
547 if (!(np = getnetbyaddr(i, AF_INET)) && net != i)
548 np = getnetbyaddr(net, AF_INET);
549 if (np) {
550 cp = np->n_name;
551 //### trimdomain(cp, strlen(cp));
552 }
553 }
554 if (cp)
555 strncpy(line, cp, sizeof(line) - 1);
556 else {
557 switch (dmask) {
558 case IN_CLASSA_NET:
559 if ((i & IN_CLASSA_HOST) == 0) {
560 sprintf(line, "%u", C(i >> 24));
561 break;
562 }
563 /* FALLTHROUGH */
564 case IN_CLASSB_NET:
565 if ((i & IN_CLASSB_HOST) == 0) {
566 sprintf(line, "%u.%u",
567 C(i >> 24), C(i >> 16));
568 break;
569 }
570 /* FALLTHROUGH */
571 case IN_CLASSC_NET:
572 if ((i & IN_CLASSC_HOST) == 0) {
573 sprintf(line, "%u.%u.%u",
574 C(i >> 24), C(i >> 16), C(i >> 8));
575 break;
576 }
577 /* FALLTHROUGH */
578 default:
579 sprintf(line, "%u.%u.%u.%u",
580 C(i >> 24), C(i >> 16), C(i >> 8), C(i));
581 break;
582 }
583 }
584 domask(line+strlen(line), i, omask);
585 return (line);
586 }
587
588 #ifdef INET6
589 char *
590 netname6(struct sockaddr_in6 *sa6, struct sockaddr *sam)
591 {
592 static char line[MAXHOSTNAMELEN];
593 u_char *lim;
594 int masklen, illegal = 0, flag = NI_WITHSCOPEID;
595 struct in6_addr *mask = sam ? &((struct sockaddr_in6 *)sam)->sin6_addr : 0;
596
597 if (sam && sam->sa_len == 0) {
598 masklen = 0;
599 } else if (mask) {
600 u_char *p = (u_char *)mask;
601 for (masklen = 0, lim = p + 16; p < lim; p++) {
602 switch (*p) {
603 case 0xff:
604 masklen += 8;
605 break;
606 case 0xfe:
607 masklen += 7;
608 break;
609 case 0xfc:
610 masklen += 6;
611 break;
612 case 0xf8:
613 masklen += 5;
614 break;
615 case 0xf0:
616 masklen += 4;
617 break;
618 case 0xe0:
619 masklen += 3;
620 break;
621 case 0xc0:
622 masklen += 2;
623 break;
624 case 0x80:
625 masklen += 1;
626 break;
627 case 0x00:
628 break;
629 default:
630 illegal ++;
631 break;
632 }
633 }
634 if (illegal)
635 fprintf(stderr, "illegal prefixlen\n");
636 } else {
637 masklen = 128;
638 }
639 if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
640 return("default");
641
642 if (nflag)
643 flag |= NI_NUMERICHOST;
644 getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
645 NULL, 0, flag);
646
647 if (nflag)
648 sprintf(&line[strlen(line)], "/%d", masklen);
649
650 return line;
651 }
652
653 char *
654 routename6(struct sockaddr_in6 *sa6)
655 {
656 static char line[MAXHOSTNAMELEN];
657 int flag = NI_WITHSCOPEID;
658 /* use local variable for safety */
659 struct sockaddr_in6 sa6_local = {sizeof(sa6_local), AF_INET6, };
660
661 sa6_local.sin6_addr = sa6->sin6_addr;
662 sa6_local.sin6_scope_id = sa6->sin6_scope_id;
663
664 if (nflag)
665 flag |= NI_NUMERICHOST;
666
667 getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
668 line, sizeof(line), NULL, 0, flag);
669
670 return line;
671 }
672 #endif /*INET6*/
673
674 /*
675 * Print routing statistics
676 */
677 void
678 rt_stats(void)
679 {
680 struct rtstat rtstat;
681 int rttrash;
682 int mib[6];
683 size_t len;
684
685 mib[0] = CTL_NET;
686 mib[1] = AF_ROUTE;
687 mib[2] = 0;
688 mib[3] = 0;
689 mib[4] = NET_RT_STAT;
690 mib[5] = 0;
691 len = sizeof(struct rtstat);
692 if (sysctl(mib, 6, &rtstat, &len, 0, 0) == -1)
693 return;
694
695 mib[0] = CTL_NET;
696 mib[1] = AF_ROUTE;
697 mib[2] = 0;
698 mib[3] = 0;
699 mib[4] = NET_RT_TRASH;
700 mib[5] = 0;
701 len = sizeof(rttrash);
702 if (sysctl(mib, 6, &rttrash, &len, 0, 0) == -1)
703 return;
704
705 printf("routing:\n");
706
707 #define p(f, m) if (rtstat.f || sflag <= 1) \
708 printf(m, rtstat.f, plural(rtstat.f))
709
710 p(rts_badredirect, "\t%u bad routing redirect%s\n");
711 p(rts_dynamic, "\t%u dynamically created route%s\n");
712 p(rts_newgateway, "\t%u new gateway%s due to redirects\n");
713 p(rts_unreach, "\t%u destination%s found unreachable\n");
714 p(rts_wildcard, "\t%u use%s of a wildcard route\n");
715 #undef p
716
717 if (rttrash || sflag <= 1)
718 printf("\t%u route%s not in table but not freed\n",
719 rttrash, plural(rttrash));
720 }
721
722 void
723 upHex(char *p0)
724 {
725 char *p = p0;
726
727 for (; *p; p++)
728 switch (*p) {
729
730 case 'a':
731 case 'b':
732 case 'c':
733 case 'd':
734 case 'e':
735 case 'f':
736 *p += ('A' - 'a');
737 break;
738 }
739 }