diff -r -u dhcp-4.1.1-P1/common/discover.c dhcp-4.1.1-P1.getifaddrs/common/discover.c --- dhcp-4.1.1-P1/common/discover.c 2009-09-29 12:44:49.000000000 -0700 +++ dhcp-4.1.1-P1.getifaddrs/common/discover.c 2011-03-15 18:34:51.176707274 -0700 @@ -377,7 +377,7 @@ * * Linux low level access is documented in the netdevice man page. */ - +#include /* * Structure holding state about the scan. */ @@ -983,59 +983,79 @@ (*dhcp_interface_discovery_hook)(tmp); } - if ((info.addr.ss_family == AF_INET) && - (local_family == AF_INET)) { - struct sockaddr_in *a = (struct sockaddr_in*)&info.addr; - struct iaddr addr; - + { + struct ifaddrs *ifaddr, *ifa; + getifaddrs(&ifaddr); + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if ( (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) && + (local_family == AF_INET)) { + struct sockaddr_in *a = (struct sockaddr_in *)ifa->ifa_addr; + struct iaddr addr; + char *s=NULL; + + s = strchr(ifa->ifa_name, ':'); + if (s != NULL) { + *s = '\0'; + } + if (!strcmp(ifa->ifa_name, info.name)) { /* We don't want the loopback interface. */ if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) && ((tmp->flags & INTERFACE_AUTOMATIC) && state == DISCOVER_SERVER)) - continue; - + continue; + /* If the only address we have is 0.0.0.0, we shouldn't consider the interface configured. */ if (a->sin_addr.s_addr != htonl(INADDR_ANY)) - tmp->configured = 1; - + tmp->configured = 1; + add_ipv4_addr_to_interface(tmp, &a->sin_addr); - + /* invoke the setup hook */ addr.len = 4; memcpy(addr.iabuf, &a->sin_addr.s_addr, addr.len); if (dhcp_interface_setup_hook) { - (*dhcp_interface_setup_hook)(tmp, &addr); + (*dhcp_interface_setup_hook)(tmp, &addr); } - } + } + } #ifdef DHCPv6 - else if ((info.addr.ss_family == AF_INET6) && - (local_family == AF_INET6)) { - struct sockaddr_in6 *a = - (struct sockaddr_in6*)&info.addr; - struct iaddr addr; - + else if ( (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) && + (local_family == AF_INET6)) { + struct sockaddr_in6 *a = + (struct sockaddr_in6*)ifa->ifa_addr; + struct iaddr addr; + char *s=NULL; + + s = strchr(ifa->ifa_name, ':'); + if (s != NULL) { + *s = '\0'; + } + if (!strcmp(ifa->ifa_name, info.name)) { /* We don't want the loopback interface. */ if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) && ((tmp->flags & INTERFACE_AUTOMATIC) && state == DISCOVER_SERVER)) - continue; - + continue; + /* If the only address we have is 0.0.0.0, we shouldn't consider the interface configured. */ if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr)) - tmp->configured = 1; - + tmp->configured = 1; + add_ipv6_addr_to_interface(tmp, &a->sin6_addr); - + /* invoke the setup hook */ addr.len = 16; memcpy(addr.iabuf, &a->sin6_addr, addr.len); if (dhcp_interface_setup_hook) { - (*dhcp_interface_setup_hook)(tmp, &addr); + (*dhcp_interface_setup_hook)(tmp, &addr); } - } + } + } #endif /* DHCPv6 */ + } + } } if (err) {