This is somewhat a continuation of my previous question about max
interfaces. I wanted to know how much space I needed for a buffer using
ioctl(). Then I discovered getifaddrs()
I'm not sure if I'm doing something wrong or this is the correct
output. I have this sample code:
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <ifaddrs.h>
int
main(int argc, char *argv[])
{
struct ifaddrs *ifaddr, *ifa;
int i;
if (getifaddrs(&ifaddr) < 0)
{
printf("\ngetifaddr failed\n");
exit(1);
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
printf("%s\n", ifa->ifa_name);
}
freeifaddrs(ifaddr);
return 0;
}
When compiled and ran I get this:
$ ./test
lo0
lo0
lo0
lo0
em0
iwn0
iwn0
enc0
pflog0
But ifconfig only shows one of each interface. Why is getifaddrs()
giving me 4 lo0 and 2 iwn0?
Thanks in advance.