* Dump the entire neighbor cache */
| 639 | * Dump the entire neighbor cache |
| 640 | */ |
| 641 | static void |
| 642 | dump(struct sockaddr_in6 *addr, int cflag) |
| 643 | { |
| 644 | int mib[6]; |
| 645 | size_t needed; |
| 646 | char *lim, *buf, *next; |
| 647 | struct rt_msghdr *rtm; |
| 648 | struct sockaddr_in6 *sin; |
| 649 | struct sockaddr_dl *sdl; |
| 650 | struct timeval now; |
| 651 | time_t expire; |
| 652 | int addrwidth; |
| 653 | int llwidth; |
| 654 | int ifwidth; |
| 655 | char flgbuf[8]; |
| 656 | char *ifname; |
| 657 | |
| 658 | /* Print header */ |
| 659 | if (!tflag && !cflag) |
| 660 | printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n", |
| 661 | W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address", |
| 662 | W_IF, W_IF, "Netif", "Expire", "S", "Flags"); |
| 663 | |
| 664 | again:; |
| 665 | mib[0] = CTL_NET; |
| 666 | mib[1] = PF_ROUTE; |
| 667 | mib[2] = 0; |
| 668 | mib[3] = AF_INET6; |
| 669 | mib[4] = NET_RT_FLAGS; |
| 670 | #ifdef RTF_LLINFO |
| 671 | mib[5] = RTF_LLINFO; |
| 672 | #else |
| 673 | mib[5] = 0; |
| 674 | #endif |
| 675 | if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) |
| 676 | err(1, "sysctl(PF_ROUTE estimate)"); |
| 677 | if (needed > 0) { |
| 678 | if ((buf = malloc(needed)) == NULL) |
| 679 | err(1, "malloc"); |
| 680 | if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) |
| 681 | err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)"); |
| 682 | lim = buf + needed; |
| 683 | } else |
| 684 | buf = lim = NULL; |
| 685 | |
| 686 | for (next = buf; next && next < lim; next += rtm->rtm_msglen) { |
| 687 | int isrouter = 0, prbs = 0; |
| 688 | |
| 689 | rtm = (struct rt_msghdr *)next; |
| 690 | sin = (struct sockaddr_in6 *)(rtm + 1); |
| 691 | sdl = (struct sockaddr_dl *)((char *)sin + |
| 692 | ALIGN(sin->sin6_len)); |
| 693 | |
| 694 | /* |
| 695 | * Some OSes can produce a route that has the LINK flag but |
| 696 | * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD |
| 697 | * and BSD/OS, where xx is not the interface identifier on |
| 698 | * lo0). Such routes entry would annoy getnbrinfo() below, |
no test coverage detected