MCPcopy Index your code
hub / github.com/F-Stack/f-stack / dump

Function dump

tools/ndp/ndp.c:641–848  ·  view source on GitHub ↗

* Dump the entire neighbor cache */

Source from the content-addressed store, hash-verified

639 * Dump the entire neighbor cache
640 */
641static void
642dump(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
664again:;
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,

Callers 2

mainFunction · 0.70
getFunction · 0.70

Calls 12

sysctlFunction · 0.85
mallocFunction · 0.85
inet_ntopFunction · 0.85
ts_printFunction · 0.85
ether_strFunction · 0.85
if_indextonameFunction · 0.85
snprintfFunction · 0.85
deleteFunction · 0.70
sec2strFunction · 0.70
printfFunction · 0.50
strlcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected