From: <n-...@us...> - 2011-04-19 13:17:53
|
Revision: 5325 http://gfarm.svn.sourceforge.net/gfarm/?rev=5325&view=rev Author: n-soda Date: 2011-04-19 13:17:47 +0000 (Tue, 19 Apr 2011) Log Message: ----------- fix #208 (gfsd doesn't work on NetBSD-5) by using getifaddrs() instead of SIOCGIFCONF Modified Paths: -------------- gfarm_v2/trunk/configure.ac gfarm_v2/trunk/lib/libgfarm/gfarm/host.c Modified: gfarm_v2/trunk/configure.ac =================================================================== --- gfarm_v2/trunk/configure.ac 2011-04-19 09:34:18 UTC (rev 5324) +++ gfarm_v2/trunk/configure.ac 2011-04-19 13:17:47 UTC (rev 5325) @@ -1104,7 +1104,7 @@ ###### Checks for library functions. ###### -AC_CHECK_FUNCS(getdents fdatasync fdopendir poll pread pwrite snprintf getpassphrase mkdtemp setlogin strtoll strtoq setrlimit daemon getloadavg statvfs statfs random) +AC_CHECK_FUNCS(getdents fdatasync fdopendir poll pread pwrite snprintf getpassphrase mkdtemp setlogin strtoll strtoq setrlimit daemon getloadavg statvfs statfs random getifaddrs) ### Check epoll_create really implemented Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/host.c =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/host.c 2011-04-19 09:34:18 UTC (rev 5324) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/host.c 2011-04-19 13:17:47 UTC (rev 5325) @@ -2,6 +2,8 @@ * $Id$ */ +#include <gfarm/gfarm_config.h> + #include <assert.h> #include <stddef.h> #include <string.h> @@ -19,6 +21,9 @@ #include <net/if.h> #include <netinet/in.h> #include <sys/un.h> /* for SUN_LEN */ +#ifdef HAVE_GETIFADDRS +#include <ifaddrs.h> +#endif #include <errno.h> #include <unistd.h> @@ -338,6 +343,46 @@ return (is_local); } +#ifdef HAVE_GETIFADDRS + +gfarm_error_t +gfarm_get_ip_addresses(int *countp, struct in_addr **ip_addressesp) +{ + struct ifaddrs *ifa_head, *ifa; + int i, n; + struct in_addr *addresses; + + if (getifaddrs(&ifa_head) == -1) + return (gfarm_errno_to_error(errno)); + + for (n = 0, ifa = ifa_head; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family == AF_INET && + (ifa->ifa_flags & IFF_UP) != 0) { + n++; + } + } + GFARM_MALLOC_ARRAY(addresses, n); + if (addresses == NULL) { + gflog_debug(GFARM_MSG_UNFIXED, + "gfarm_get_ip_addresses: no memory for %d IPs", n); + freeifaddrs(ifa_head); + return (GFARM_ERR_NO_MEMORY); + } + for (i = 0, ifa = ifa_head; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family == AF_INET && + (ifa->ifa_flags & IFF_UP) != 0) { + addresses[i++] = + ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; + } + } + freeifaddrs(ifa_head); + *ip_addressesp = addresses; + *countp = n; + return (GFARM_ERR_NO_ERROR); +} + +#else /* HAVE_GETIFADDRS */ + #ifdef SUN_LEN # ifndef linux # define NEW_SOCKADDR /* 4.3BSD-Reno or later */ @@ -467,6 +512,8 @@ return (e); } +#endif /* HAVE_GETIFADDRS */ + #if 0 /* "address_use" directive is disabled for now */ struct gfarm_host_address_use_config { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |