From 53654f5caf701a32b615bed784d78765f351cb73 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 29 Feb 2008 00:06:55 +0100 Subject: libreplace: try and fix rep_getifaddrs() for Tru64. Don't fail when there is no address assigned to the interface. Put NULL into the ifaddrs structure instead. Michael (This used to be commit ee170c85e0e76411bd752de5fe51db6940dab929) --- source4/lib/replace/getifaddrs.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/source4/lib/replace/getifaddrs.c b/source4/lib/replace/getifaddrs.c index 551ff863df..f66bf800eb 100644 --- a/source4/lib/replace/getifaddrs.c +++ b/source4/lib/replace/getifaddrs.c @@ -109,38 +109,33 @@ int rep_getifaddrs(struct ifaddrs **ifap) /* Loop through interfaces, looking for given IP address */ for (i=n-1; i>=0; i--) { - if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { + if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) == -1) { freeifaddrs(*ifap); + return -1; } curif = calloc(1, sizeof(struct ifaddrs)); - if (lastif == NULL) { - *ifap = curif; - } else { - lastif->ifa_next = curif; - } - curif->ifa_name = strdup(ifr[i].ifr_name); - curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr); + curif->ifa_flags = ifr[i].ifr_flags; curif->ifa_dstaddr = NULL; curif->ifa_data = NULL; curif->ifa_next = NULL; - curif->ifa_netmask = NULL; - - if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) { - freeifaddrs(*ifap); - return -1; - } - curif->ifa_flags = ifr[i].ifr_flags; - - if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { - freeifaddrs(*ifap); - return -1; - } + curif->ifa_addr = NULL + if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) { + curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr); + } - curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr); + curif->ifa_netmask = NULL; + if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != -1) { + curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr); + } + if (lastif == NULL) { + *ifap = curif; + } else { + lastif->ifa_next = curif; + } lastif = curif; } -- cgit