-
-static int wild_dump_interfaces(AvahiInterfaceMonitor *m)
-{
- size_t needed;
- int mib[6];
- char *buf, *lim, *next, count = 0;
- struct rt_msghdr *rtm;
-
- retry2:
- mib[0] = CTL_NET;
- mib[1] = PF_ROUTE;
- mib[2] = 0; /* protocol */
- mib[3] = 0; /* wildcard address family */
- mib[4] = NET_RT_IFLIST;
- mib[5] = 0; /* no flags */
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
- err(EX_OSERR, "route-sysctl-estimate");
- if ((buf = malloc(needed)) == NULL)
- errx(EX_OSERR, "malloc failed");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
- if (errno == ENOMEM && count++ < 10) {
- warnx("Routing table grew, retrying");
- sleep(1);
- free(buf);
- goto retry2;
- }
- err(EX_OSERR, "actual retrieval of interface table");
- }
- lim = buf + needed;
- for (next = buf; next < lim; next += rtm->rtm_msglen) {
- rtm = (struct rt_msghdr *)next;
- parse_rtmsg(rtm, rtm->rtm_msglen, m);
- }
- return 0;
-}
-