diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-16 02:49:52 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2008-02-19 21:56:41 +0100 |
commit | d0d4fc5f5412bcf2977afc01edee92107e995c80 (patch) | |
tree | 37f69aa5ab21e799134fe8e51e0429b595d954dc | |
parent | 2235ffe2f754da543b796446377b1419bf046204 (diff) | |
download | samba-d0d4fc5f5412bcf2977afc01edee92107e995c80.tar.gz samba-d0d4fc5f5412bcf2977afc01edee92107e995c80.tar.bz2 samba-d0d4fc5f5412bcf2977afc01edee92107e995c80.zip |
r26468: Match getifaddrs more closely, add trivial test.
(cherry picked from commit 92898c043b5a2649a2e423d02bcdaea78ae55737)
(This used to be commit 3f9c0c210022905c7811b2e07b3b655929daf930)
-rw-r--r-- | source3/lib/replace/getifaddrs.c | 33 | ||||
-rw-r--r-- | source3/lib/replace/test/testsuite.c | 20 |
2 files changed, 31 insertions, 22 deletions
diff --git a/source3/lib/replace/getifaddrs.c b/source3/lib/replace/getifaddrs.c index 3969535a0b..a4f16ddb76 100644 --- a/source3/lib/replace/getifaddrs.c +++ b/source3/lib/replace/getifaddrs.c @@ -112,7 +112,6 @@ int getifaddrs(struct ifaddrs **ifap) } curif->ifa_name = strdup(ifr[i].ifr_name); - curif->ifa_flags = ifreq.ifr_flags; curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr); curif->ifa_dstaddr = NULL; curif->ifa_data = NULL; @@ -124,10 +123,7 @@ int getifaddrs(struct ifaddrs **ifap) return -1; } - if (!(ifr[i].ifr_flags & IFF_UP)) { - freeifaddrs(curif); - continue; - } + curif->ifa_flags = ifr[i].ifr_flags; if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { freeifaddrs(*ifap); @@ -201,6 +197,13 @@ int getifaddrs(struct ifaddrs **ifap) for (i = 0; i<n && total < max_interfaces; i++) { ifreq = ifr[i]; + curif = calloc(1, sizeof(struct ifaddrs)); + if (lastif == NULL) { + *ifap = curif; + } else { + lastif->ifa_next = (*ifap); + } + strioctl.ic_cmd = SIOCGIFFLAGS; strioctl.ic_dp = (char *)&ifreq; strioctl.ic_len = sizeof(struct ifreq); @@ -208,11 +211,9 @@ int getifaddrs(struct ifaddrs **ifap) freeifaddrs(*ifap); return -1; } - - if (!(ifreq.ifr_flags & IFF_UP)) { - continue; - } + curif->ifa_flags = ifreq.ifr_flags; + strioctl.ic_cmd = SIOCGIFADDR; strioctl.ic_dp = (char *)&ifreq; strioctl.ic_len = sizeof(struct ifreq); @@ -221,15 +222,7 @@ int getifaddrs(struct ifaddrs **ifap) return -1; } - curif = calloc(1, sizeof(struct ifaddrs)); - if (lastif == NULL) { - *ifap = curif; - } else { - lastif->ifa_next = (*ifap); - } - curif->ifa_name = strdup(ifreq.ifr_name); - curif->ifa_flags = ifreq.ifr_flags; curif->ifa_addr = sockaddr_dup(&ifreq.ifr_addr); curif->ifa_dstaddr = NULL; curif->ifa_data = NULL; @@ -310,7 +303,6 @@ int getifaddrs(struct ifaddrs **ifap) } curif->ifa_name = strdup(ifr->ifr_name); - curif->ifa_flags = ifr->ifr_flags; curif->ifa_addr = sockaddr_dup(&ifr->ifr_addr); curif->ifa_dstaddr = NULL; curif->ifa_data = NULL; @@ -322,10 +314,7 @@ int getifaddrs(struct ifaddrs **ifap) return -1; } - if (!(ifr->ifr_flags & IFF_UP)) { - freeaddrinfo(curif); - continue; - } + curif->ifa_flags = ifr->ifr_flags; if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { freeaddrinfo(*ifap); diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 5b95ae395c..c9f3301005 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -856,6 +856,25 @@ static int test_strptime(void) return libreplace_test_strptime(); } +static int test_getifaddrs(void) +{ + struct ifaddrs *ifa; + int ret; + + printf("test: getifaddrs\n"); + + ret = getifaddrs(&ifa); + if (ret != 0) { + printf("failure: getifaddrs\n"); + return false; + } + + freeifaddrs(ifa); + + printf("success: getifaddrs\n"); + return true; +} + struct torture_context; bool torture_local_replace(struct torture_context *ctx) { @@ -903,6 +922,7 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_MAX(); ret &= test_socketpair(); ret &= test_strptime(); + ret &= test_getifaddrs(); return ret; } |