aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-08-06 22:43:05 +0000
committerTom Tromey <tromey@gcc.gnu.org>2006-08-06 22:43:05 +0000
commit9327c475dff65f2d2f906c098943910397aaf7e4 (patch)
treeda232522e2e183ad14c50a33158388c5e9df7f06
parentbc19f9eedaf172fce1117c0e5baee2d8f72e04d6 (diff)
downloadgcc-9327c475dff65f2d2f906c098943910397aaf7e4.zip
gcc-9327c475dff65f2d2f906c098943910397aaf7e4.tar.gz
gcc-9327c475dff65f2d2f906c098943910397aaf7e4.tar.bz2
re PR libgcj/28491 (NetworkInterface.getNetworkInterfaces() doesn't report ipv6 interfaces.)
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. From-SVN: r115977
-rw-r--r--libjava/ChangeLog8
-rwxr-xr-xlibjava/configure17
-rw-r--r--libjava/configure.ac5
-rw-r--r--libjava/include/config.h.in6
-rw-r--r--libjava/java/net/natVMNetworkInterfacePosix.cc62
5 files changed, 82 insertions, 16 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 39006c6..57044e8 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,5 +1,13 @@
2006-08-06 Tom Tromey <tromey@redhat.com>
+ 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 <tromey@redhat.com>
+
PR libgcj/28576:
* gnu/java/net/natPlainDatagramSocketImplPosix.cc (connect):
Implemented.
diff --git a/libjava/configure b/libjava/configure
index c2c5ddc..43b9920 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 <X11/Intrinsic.h>
+#include <X11/Xlib.h>
_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 <X11/Intrinsic.h>
+#include <X11/Xlib.h>
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 44340a4..e529593 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 <inttypes.h> is available])
AC_DEFINE(JV_HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
diff --git a/libjava/include/config.h.in b/libjava/include/config.h.in
index 2ef6171..e6ea394 100644
--- a/libjava/include/config.h.in
+++ b/libjava/include/config.h.in
@@ -115,6 +115,9 @@
/* Define if gethostname is declared in <unistd.h>. */
#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 <ifaddrs.h> 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 b840907..8238d9c 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 <net/if.h>
#endif
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif
#include <gcj/cni.h>
#include <jvm.h>
@@ -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<sockaddr_in *> (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<sockaddr_in6 *> (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;
}