diff options
| author | itojun <itojun@NetBSD.org> | 2002-08-01 14:04:50 +0000 |
|---|---|---|
| committer | itojun <itojun@NetBSD.org> | 2002-08-01 14:04:50 +0000 |
| commit | 43cad3fc3f901237c1db0392c984dca40a5095de (patch) | |
| tree | 7ff06bb7f79210dbd90cc2f75c68464b5ec18f14 /usr.sbin/mrouted | |
| parent | 5868a9832ab0b8b9e2fc4e7df13c0547fe4bcfc1 (diff) | |
use getifaddrs, not SIOCGIFCONF. should fix PR12578
Diffstat (limited to 'usr.sbin/mrouted')
| -rw-r--r-- | usr.sbin/mrouted/config.c | 67 |
1 files changed, 21 insertions, 46 deletions
diff --git a/usr.sbin/mrouted/config.c b/usr.sbin/mrouted/config.c index 55e0b24a410..ff446e40100 100644 --- a/usr.sbin/mrouted/config.c +++ b/usr.sbin/mrouted/config.c @@ -1,4 +1,4 @@ -/* $NetBSD: config.c,v 1.7 2002/07/14 16:30:42 wiz Exp $ */ +/* $NetBSD: config.c,v 1.8 2002/08/01 14:04:50 itojun Exp $ */ /* * The mrouted program is covered by the license in the accompanying file @@ -9,8 +9,9 @@ * Leland Stanford Junior University. */ - #include "defs.h" +#include <net/if.h> +#include <ifaddrs.h> /* @@ -20,74 +21,45 @@ void config_vifs_from_kernel(void) { - struct ifreq ifbuf[32]; - struct ifreq *ifrp, *ifend; - struct ifconf ifc; + struct ifaddrs *ifa, *ifap; struct uvif *v; vifi_t vifi; - int n; u_int32_t addr, mask, subnet; short flags; - ifc.ifc_buf = (char *)ifbuf; - ifc.ifc_len = sizeof(ifbuf); - if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0) - log(LOG_ERR, errno, "ioctl SIOCGIFCONF"); + if (getifaddrs(&ifap) < 0) + log(LOG_ERR, errno, "getifaddrs"); - ifrp = (struct ifreq *)ifbuf; - ifend = (struct ifreq *)((char *)ifbuf + ifc.ifc_len); - /* - * Loop through all of the interfaces. - */ - for (; ifrp < ifend; ifrp = (struct ifreq *)((char *)ifrp + n)) { - struct ifreq ifr; -#if BSD >= 199006 - n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); - if (n < sizeof(*ifrp)) - n = sizeof(*ifrp); -#else - n = sizeof(*ifrp); -#endif + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { /* * Ignore any interface for an address family other than IP. */ - if (ifrp->ifr_addr.sa_family != AF_INET) + if (ifa->ifa_addr->sa_family != AF_INET) continue; - addr = ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr; - - /* - * Need a template to preserve address info that is - * used below to locate the next entry. (Otherwise, - * SIOCGIFFLAGS stomps over it because the requests - * are returned in a union.) - */ - bcopy(ifrp->ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); + addr = ((struct sockaddr_in *)&ifa->ifa_addr)->sin_addr.s_addr; /* * Ignore loopback interfaces and interfaces that do not support * multicast. */ - if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0) - log(LOG_ERR, errno, "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name); - flags = ifr.ifr_flags; - if ((flags & (IFF_LOOPBACK|IFF_MULTICAST)) != IFF_MULTICAST) continue; + flags = ifa->ifa_flags; + if ((flags & (IFF_LOOPBACK|IFF_MULTICAST)) != IFF_MULTICAST) + continue; /* * Ignore any interface whose address and mask do not define a * valid subnet number, or whose address is of the form {subnet,0} * or {subnet,-1}. */ - if (ioctl(udp_socket, SIOCGIFNETMASK, (char *)&ifr) < 0) - log(LOG_ERR, errno, "ioctl SIOCGIFNETMASK for %s", ifr.ifr_name); - mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + mask = ((struct sockaddr_in *)&ifa->ifa_netmask)->sin_addr.s_addr; subnet = addr & mask; if (!inet_valid_subnet(subnet, mask) || addr == subnet || addr == (subnet | ~mask)) { log(LOG_WARNING, 0, "ignoring %s, has invalid address (%s) and/or mask (%s)", - ifr.ifr_name, inet_fmt(addr, s1), inet_fmt(mask, s2)); + ifa->ifa_name, inet_fmt(addr, s1), inet_fmt(mask, s2)); continue; } @@ -99,17 +71,18 @@ config_vifs_from_kernel(void) if ((addr & v->uv_subnetmask) == v->uv_subnet || (v->uv_subnet & mask) == subnet) { log(LOG_WARNING, 0, "ignoring %s, same subnet as %s", - ifr.ifr_name, v->uv_name); + ifa->ifa_name, v->uv_name); break; } } - if (vifi != numvifs) continue; + if (vifi != numvifs) + continue; /* * If there is room in the uvifs array, install this interface. */ if (numvifs == MAXVIFS) { - log(LOG_WARNING, 0, "too many vifs, ignoring %s", ifr.ifr_name); + log(LOG_WARNING, 0, "too many vifs, ignoring %s", ifa->ifa_name); continue; } v = &uvifs[numvifs]; @@ -122,7 +95,7 @@ config_vifs_from_kernel(void) v->uv_subnet = subnet; v->uv_subnetmask = mask; v->uv_subnetbcast = subnet | ~mask; - strncpy(v->uv_name, ifr.ifr_name, IFNAMSIZ); + strlcpy(v->uv_name, ifa->ifa_name, sizeof(v->uv_name)); v->uv_groups = NULL; v->uv_neighbors = NULL; v->uv_acl = NULL; @@ -143,4 +116,6 @@ config_vifs_from_kernel(void) vifs_down = TRUE; } } + + freeifaddrs(ifap); } |
