- int n;
-
- ifc.ifc_len = sizeof (buf);
- ifc.ifc_buf = buf;
- if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
- syslog(LOG_ERR, "ioctl (get interface configuration)");
- return (0);
- }
- ifr = ifc.ifc_req;
- for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) {
- for (np = neighbors; np != NULL; np = np->n_next)
- if (np->n_name &&
- strcmp(ifr->ifr_name, np->n_name) == 0)
- break;
- if (np != NULL)
- continue;
- ifreq = *ifr;
- np = (struct neighbor *)malloc(sizeof (*np));
- if (np == NULL)
- continue;
- np->n_name = malloc(strlen(ifr->ifr_name) + 1);
- if (np->n_name == NULL) {
- free((char *)np);
+ register struct if_msghdr *ifm;
+ register struct ifa_msghdr *ifam;
+ struct sockaddr_dl *sdl;
+ size_t needed;
+ int mib[6], flags = 0, len;
+ char *buf, *lim, *next;
+ struct rt_addrinfo info;
+
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_INET;
+ mib[4] = NET_RT_IFLIST;
+ mib[5] = 0;
+ if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ quit("route-sysctl-estimate");
+ if ((buf = malloc(needed)) == NULL)
+ quit("malloc");
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ quit("actual retrieval of interface table");
+ lim = buf + needed;
+
+ sdl = NULL; /* XXX just to keep gcc -Wall happy */
+ for (next = buf; next < lim; next += ifm->ifm_msglen) {
+ ifm = (struct if_msghdr *)next;
+ if (ifm->ifm_type == RTM_IFINFO) {
+ sdl = (struct sockaddr_dl *)(ifm + 1);
+ flags = ifm->ifm_flags;