#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
-#ifdef HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h>
-#endif
-#ifdef HAVE_NET_IF_VAR_H
-#include <net/if_var.h>
-#endif
-#ifdef HAVE_NETINET_IN_VAR_H
-#include <netinet/in_var.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
-#endif
#include <corosync/totem/totemip.h>
#include <corosync/swab.h>
return ret;
}
-#if defined(HAVE_GETIFADDRS)
int totemip_getifaddrs(struct list_head *addrs)
{
struct ifaddrs *ifap, *ifa;
freeifaddrs(ifap);
return (-1);
}
-#elif defined(SOLARIS)
-/*
- * On Solaris, man if_tcp describes this method
- */
-int totemip_getifaddrs(struct list_head *addrs)
-{
- int id_fd;
- int numreqs;
- int res;
- struct lifconf lifconf;
- struct lifreq *lifreq;
- int i, j;
- struct totem_ip_if_address *if_addr;
- short family;
-
- list_init(addrs);
-
- for (family = 0; family < 2; family++) {
- numreqs = 0;
- res = -1;
-
- lifconf.lifc_family = (family == 0 ? AF_INET : AF_INET6);
- id_fd = socket (lifconf.lifc_family, SOCK_STREAM, 0);
- lifconf.lifc_flags = 0;
- lifconf.lifc_buf = NULL;
- lifconf.lifc_len = 0;
- do {
- numreqs += 32;
- lifconf.lifc_len = sizeof (struct lifreq) * numreqs;
- lifconf.lifc_buf = (void *)realloc(lifconf.lifc_buf, lifconf.lifc_len);
- res = ioctl (id_fd, SIOCGLIFCONF, &lifconf);
- if (res < 0) {
- close (id_fd);
- }
- } while (res >= 0 && lifconf.lifc_len == sizeof (struct lifconf) * numreqs);
-
- if (res < 0)
- continue ;
-
- lifreq = (struct lifreq *)lifconf.lifc_buf;
- for (i = 0; i < lifconf.lifc_len / sizeof (struct lifreq); i++) {
- if (ioctl(id_fd, SIOCGLIFADDR, &lifreq[i]) < 0)
- continue ;
-
- if (lifreq[i].lifr_addr.ss_family != AF_INET && lifreq[i].lifr_addr.ss_family != AF_INET6)
- continue ;
-
- if_addr = malloc(sizeof(struct totem_ip_if_address));
- if (if_addr == NULL) {
- goto error_free_ifaddrs;
- }
-
- memset(if_addr, 0, sizeof(struct totem_ip_if_address));
-
- if_addr->name = strdup(lifreq[i].lifr_name);
- if (if_addr->name == NULL) {
- goto error_free_addr;
- }
-
- if (totemip_sockaddr_to_totemip_convert(&lifreq[i].lifr_addr, &if_addr->ip_addr) == -1) {
- goto error_free_addr_name;
- }
-
- if (ioctl(id_fd, SIOCGLIFSUBNET, &lifreq[i]) < 0)
- continue ;
-
- /*
- * lifreq doesn't contain mask address. But It length of prefix in bits,
- * so we can generate mask.
- */
- memset(&if_addr->mask_addr, 0, sizeof(if_addr->mask_addr));
- if_addr->mask_addr.family = if_addr->ip_addr.family;
- for (j = 0; j < lifreq[i].lifr_addrlen; j++) {
- if_addr->mask_addr.addr[j / 8] |= 1 << (7 - (j % 8));
- }
- if (ioctl(id_fd, SIOCGLIFFLAGS, &lifreq[i]) >= 0) {
- if_addr->interface_up = lifreq[i].lifr_flags & IFF_UP;
- }
- if (ioctl(id_fd, SIOCGLIFINDEX, &lifreq[i]) >= 0) {
- if_addr->interface_num = lifreq[i].lifr_index;
- }
-
- list_add_tail(&if_addr->list, addrs);
- }
-
- free (lifconf.lifc_buf);
- close (id_fd);
- }
-
- return (0);
-
-error_free_addr_name:
- free(if_addr->name);
-
-error_free_addr:
- free(if_addr);
-
-error_free_ifaddrs:
- totemip_freeifaddrs(addrs);
- free (lifconf.lifc_buf);
- close (id_fd);
-
- return (-1);
-}
-#endif /* HAVE_GETIFADDRS */
void totemip_freeifaddrs(struct list_head *addrs)
{