summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/replace/getifaddrs.c33
-rw-r--r--source4/lib/replace/test/testsuite.c20
2 files changed, 31 insertions, 22 deletions
diff --git a/source4/lib/replace/getifaddrs.c b/source4/lib/replace/getifaddrs.c
index 3969535a0b..a4f16ddb76 100644
--- a/source4/lib/replace/getifaddrs.c
+++ b/source4/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/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c
index 5b95ae395c..c9f3301005 100644
--- a/source4/lib/replace/test/testsuite.c
+++ b/source4/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;
}