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>
51 struct ifaddrs *ifap = NULL;
52 int status = getifaddrs(&ifap);
56 if ((status != 0) || (ifap == NULL))
62 for (
struct ifaddrs *iter = ifap; iter != NULL; iter = iter->ifa_next, i++)
78 std::list<vaddress> ret;
80 struct ifaddrs *ifap = NULL;
81 int status = getifaddrs(&ifap);
84 if ((status != 0) || (ifap == NULL))
90 for (
struct ifaddrs *iter = ifap; iter != NULL; iter = iter->ifa_next, i++)
92 if (iter->ifa_addr == NULL)
continue;
93 if ((iter->ifa_flags & IFF_UP) == 0)
continue;
99 if (interface != iface)
continue;
102 sockaddr *ifaceaddr = iter->ifa_addr;
104 if (scope.length() > 0) {
106 if (ifaceaddr->sa_family == AF_INET6) {
108 sockaddr_in6 *addr6 = (sockaddr_in6*)ifaceaddr;
111 if (addr6->sin6_scope_id == 0) {
120 if (::getnameinfo((
struct sockaddr *) ifaceaddr,
sizeof (
struct sockaddr_storage), address, sizeof address, 0, 0, NI_NUMERICHOST) == 0) {
121 ret.push_back(
vaddress(std::string(address),
"", ifaceaddr->sa_family) );