libreplace: try and fix rep_getifaddrs() for Tru64.
authorMichael Adam <obnox@samba.org>
Thu, 28 Feb 2008 23:06:55 +0000 (00:06 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 29 Feb 2008 08:31:19 +0000 (09:31 +0100)
Don't fail when there is no address assigned to the interface.
Put NULL into the ifaddrs structure instead.

Michael
(cherry picked from commit ee170c85e0e76411bd752de5fe51db6940dab929)
(This used to be commit 650cc1da4b4404880389c583dbb07ce86df48576)

source3/lib/replace/getifaddrs.c

index 551ff863df20a061fb5e16a883cde79b72aee2f1..f66bf800eb8a03525e32c46e180b544df880a1dd 100644 (file)
@@ -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;
        }