From 07c32f7bfac9c3367e04947f7a6303be1f3c490d Mon Sep 17 00:00:00 2001 From: tromey Date: Sun, 6 Aug 2006 22:43:05 +0000 Subject: [PATCH] PR libgcj/28491: * configure, include/config.h.in: Rebuilt. * configure.ac: Look for ifaddrs.h, getifaddrs. * java/net/natVMNetworkInterfacePosix.cc (getInterfaces): Use getifaddrs if available. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115977 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 8 ++++ libjava/configure | 17 ++++--- libjava/configure.ac | 5 ++- libjava/include/config.h.in | 6 +++ libjava/java/net/natVMNetworkInterfacePosix.cc | 62 +++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 39006c65583..57044e81a89 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,13 @@ 2006-08-06 Tom Tromey + PR libgcj/28491: + * configure, include/config.h.in: Rebuilt. + * configure.ac: Look for ifaddrs.h, getifaddrs. + * java/net/natVMNetworkInterfacePosix.cc (getInterfaces): Use + getifaddrs if available. + +2006-08-06 Tom Tromey + PR libgcj/28576: * gnu/java/net/natPlainDatagramSocketImplPosix.cc (connect): Implemented. diff --git a/libjava/configure b/libjava/configure index c2c5ddc8e61..43b9920619c 100755 --- a/libjava/configure +++ b/libjava/configure @@ -7614,7 +7614,7 @@ ac_x_header_dirs=' /usr/openwin/share/include' if test "$ac_x_includes" = no; then - # Guess where to find include files, by looking for Intrinsic.h. + # Guess where to find include files, by looking for Xlib.h. # First, try using that file with no special directory specified. cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -7622,7 +7622,7 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include _ACEOF if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 @@ -7649,7 +7649,7 @@ else sed 's/^/| /' conftest.$ac_ext >&5 for ac_dir in $ac_x_header_dirs; do - if test -r "$ac_dir/X11/Intrinsic.h"; then + if test -r "$ac_dir/X11/Xlib.h"; then ac_x_includes=$ac_dir break fi @@ -7675,11 +7675,11 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include int main () { -XtMalloc (0) +XrmInitialize () ; return 0; } @@ -9373,12 +9373,14 @@ else + for ac_func in strerror ioctl select fstat open fsync sleep opendir \ gmtime_r localtime_r readdir_r getpwuid_r getcwd \ access stat lstat mkdir rename rmdir unlink utime chmod readlink \ nl_langinfo setlocale \ inet_pton uname inet_ntoa \ - fork execvp pipe sigaction ftruncate mmap + fork execvp pipe sigaction ftruncate mmap \ + getifaddrs do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -15095,11 +15097,12 @@ esac + for ac_header in unistd.h bstring.h sys/time.h sys/types.h fcntl.h \ sys/ioctl.h sys/filio.h sys/stat.h sys/select.h \ sys/socket.h netinet/in.h arpa/inet.h netdb.h net/if.h \ pwd.h sys/config.h stdint.h langinfo.h locale.h \ - dirent.h sys/rw_lock.h + dirent.h sys/rw_lock.h ifaddrs.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then diff --git a/libjava/configure.ac b/libjava/configure.ac index 44340a45a3f..e529593d1e6 100644 --- a/libjava/configure.ac +++ b/libjava/configure.ac @@ -913,7 +913,8 @@ else access stat lstat mkdir rename rmdir unlink utime chmod readlink \ nl_langinfo setlocale \ inet_pton uname inet_ntoa \ - fork execvp pipe sigaction ftruncate mmap]) + fork execvp pipe sigaction ftruncate mmap \ + getifaddrs]) AC_CHECK_FUNCS(inet_aton inet_addr, break) AC_CHECK_HEADERS(execinfo.h unistd.h dlfcn.h) # Do an additional check on dld, HP-UX for example has dladdr in libdld.sl @@ -1301,7 +1302,7 @@ AC_CHECK_HEADERS([unistd.h bstring.h sys/time.h sys/types.h fcntl.h \ sys/ioctl.h sys/filio.h sys/stat.h sys/select.h \ sys/socket.h netinet/in.h arpa/inet.h netdb.h net/if.h \ pwd.h sys/config.h stdint.h langinfo.h locale.h \ - dirent.h sys/rw_lock.h]) + dirent.h sys/rw_lock.h ifaddrs.h]) AC_CHECK_HEADERS(inttypes.h, [ AC_DEFINE(HAVE_INTTYPES_H, 1, [Define if is available]) AC_DEFINE(JV_HAVE_INTTYPES_H, 1, [Define if is available]) diff --git a/libjava/include/config.h.in b/libjava/include/config.h.in index 2ef617103b1..e6ea39495d1 100644 --- a/libjava/include/config.h.in +++ b/libjava/include/config.h.in @@ -115,6 +115,9 @@ /* Define if gethostname is declared in . */ #undef HAVE_GETHOSTNAME_DECL +/* Define to 1 if you have the `getifaddrs' function. */ +#undef HAVE_GETIFADDRS + /* Define to 1 if you have the `getpwuid_r' function. */ #undef HAVE_GETPWUID_R @@ -127,6 +130,9 @@ /* Define if you have the iconv() function. */ #undef HAVE_ICONV +/* Define to 1 if you have the header file. */ +#undef HAVE_IFADDRS_H + /* Define if inet6 structures are defined in netinet/in.h. */ #undef HAVE_INET6 diff --git a/libjava/java/net/natVMNetworkInterfacePosix.cc b/libjava/java/net/natVMNetworkInterfacePosix.cc index b840907ccab..8238d9c1fa6 100644 --- a/libjava/java/net/natVMNetworkInterfacePosix.cc +++ b/libjava/java/net/natVMNetworkInterfacePosix.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2005 Free Software Foundation +/* Copyright (C) 2003, 2005, 2006 Free Software Foundation This file is part of libgcj. @@ -34,6 +34,9 @@ details. */ #ifdef HAVE_NET_IF_H #include #endif +#ifdef HAVE_IFADDRS_H +#include +#endif #include #include @@ -46,11 +49,59 @@ details. */ ::java::util::Vector* java::net::VMNetworkInterface::getInterfaces () { + ::java::util::Vector* ht = new ::java::util::Vector (); + +#ifdef HAVE_GETIFADDRS + + struct ifaddrs *addrs; + if (::getifaddrs (&addrs) == -1) + throw new ::java::net::SocketException(JvNewStringUTF (strerror (errno))); + + for (struct ifaddrs *work = addrs; work != NULL; work = work->ifa_next) + { + // Sometimes the address can be NULL; I don't know why but + // there's nothing we can do with this. + if (! work->ifa_addr) + continue; + // We only return Inet4 or Inet6 addresses. + jbyteArray laddr; + if (work->ifa_addr->sa_family == AF_INET) + { + sockaddr_in *real = reinterpret_cast (work->ifa_addr); + laddr = JvNewByteArray(4); + memcpy (elements (laddr), &real->sin_addr, 4); + } +#ifdef HAVE_INET6 + else if (work->ifa_addr->sa_family == AF_INET6) + { + sockaddr_in6 *real + = reinterpret_cast (work->ifa_addr); + laddr = JvNewByteArray(16); + memcpy (elements (laddr), &real->sin6_addr, 16); + } +#endif + else + continue; + + ::java::net::InetAddress *inaddr + = ::java::net::InetAddress::getByAddress(laddr); + + // It is ok to make a new NetworkInterface for each struct; the + // java code will unify these as necessary; see + // NetworkInterface.condense(). + jstring name = JvNewStringUTF (work->ifa_name); + + ht->add (new NetworkInterface (name, inaddr)); + } + + freeifaddrs (addrs); + +#else /* ! HAVE_GETIFADDRS */ + int fd; int num_interfaces = 0; struct ifconf if_data; struct ifreq* if_record; - ::java::util::Vector* ht = new ::java::util::Vector (); if_data.ifc_len = 0; if_data.ifc_buf = NULL; @@ -103,14 +154,11 @@ java::net::VMNetworkInterface::getInterfaces () if_record++; } -#ifdef HAVE_INET6 - // FIXME: read /proc/net/if_inet6 (on Linux 2.4) -#endif - _Jv_Free (if_data.ifc_buf); if (fd >= 0) _Jv_close (fd); - +#endif /* HAVE_GETIFADDRS */ + return ht; } -- 2.11.0