summaryrefslogtreecommitdiff
path: root/source4/lib/replace/getifaddrs.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/replace/getifaddrs.c')
-rw-r--r--source4/lib/replace/getifaddrs.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/source4/lib/replace/getifaddrs.c b/source4/lib/replace/getifaddrs.c
index a4f16ddb76..e04c023209 100644
--- a/source4/lib/replace/getifaddrs.c
+++ b/source4/lib/replace/getifaddrs.c
@@ -360,20 +360,25 @@ int getifaddrs(struct ifaddrs **ifap)
int main()
{
- struct ifaddrs *ifs;
- int total = get_interfaces(ifaces, MAX_INTERFACES);
- int i;
-
- int ret = getifaddrs(&ifs);
+ struct ifaddrs *ifs = NULL;
+ int ret;
+
+ ret = getifaddrs(&ifs);
if (ret != 0) {
perror("getifaddrs() failed");
return 1;
}
while (ifs) {
- printf("%-10s ", ifs->ifr_name);
- printf("IP=%s ", inet_ntoa(((struct sockaddr_in *)ifs->ifr_addr)->sin_addr));
- printf("NETMASK=%s\n", inet_ntoa(((struct sockaddr_in *)ifs->ifr_netmask)->sin_addr));
+ printf("%-10s ", ifs->ifa_name);
+ if (ifs->ifa_addr != NULL &&
+ ifs->ifa_addr->sa_family == AF_INET) {
+ printf("IP=%s ", inet_ntoa(((struct sockaddr_in *)ifs->ifa_addr)->sin_addr));
+ if (ifs->ifa_netmask != NULL)
+ printf("NETMASK=%s", inet_ntoa(((struct sockaddr_in *)ifs->ifa_netmask)->sin_addr));
+ }
+ printf("\n");
+ ifs = ifs->ifa_next;
}
return 0;
}