14 #include <sys/types.h>
15 #include <netinet/ip.h>
16 #include <netinet/ip6.h>
17 #include <arpa/inet.h>
18 #include <sys/socket.h>
39 struct ifaddrs *ifap = NULL;
40 int status = getifaddrs(&ifap);
44 if ((status != 0) || (ifap == NULL))
50 for (
struct ifaddrs *iter = ifap; iter != NULL; iter = iter->ifa_next, i++)
66 std::list<vaddress> ret;
68 struct ifaddrs *ifap = NULL;
69 int status = getifaddrs(&ifap);
72 if ((status != 0) || (ifap == NULL))
78 for (
struct ifaddrs *iter = ifap; iter != NULL; iter = iter->ifa_next, i++)
80 if (iter->ifa_addr == NULL)
continue;
81 if ((iter->ifa_flags & IFF_UP) == 0)
continue;
87 if (interface != iface)
continue;
90 sockaddr *ifaceaddr = iter->ifa_addr;
92 if (scope.length() > 0) {
94 if (ifaceaddr->sa_family == AF_INET6) {
96 sockaddr_in6 *addr6 = (sockaddr_in6*)ifaceaddr;
99 if (addr6->sin6_scope_id == 0) {
108 if (::getnameinfo((
struct sockaddr *) ifaceaddr,
sizeof (
struct sockaddr_storage), address, sizeof address, 0, 0, NI_NUMERICHOST) == 0) {
109 ret.push_back(
vaddress(std::string(address),
"", ifaceaddr->sa_family) );