Hi,
A bit old, but still relevant.
On Mon, 2006-10-09 at 10:40 -0600, Tom Tromey wrote:
> >>>>> "Michael" == Michael Koch <[EMAIL PROTECTED]> writes:
>
> Michael> The question is now: Do we want to support glibc (and
> Michael> probably other libc's for embedded targets) that lack this
> Michael> method? Perhaps we can just throw some exception on these
> Michael> systems.
>
> Yeah. Try this patch.
>
> Index: ChangeLog
> from Tom Tromey <[EMAIL PROTECTED]>
>
> * native/jni/java-net/java_net_VMNetworkInterface.c: Conditionally
> include ifaddrs.h.
> (Java_java_net_VMNetworkInterface_getVMInterfaces): Updated
> conditional.
> * native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c:
> Conditionally include ifaddrs.h.
> (getif_address): Updated conditional.
> (getif_index): Likewise.
> * configure.ac: Check for ifaddrs.h.
I am including this with 2 small changes. It works fine for me, but I do
have the relevant headers and libraries in my libc implementation.
Hopefully a next run by Michael will let us know if it improves the
situation on his setup.
> +++ native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c 9 Oct 2006 16:47:32
> -0000
> [...]
> -#ifdef HAVE_GETIFADDRS
> +#if defined (HAVE_GETIFADDRS) && defined (HAVE_GETIFADDRS)
> struct ifaddrs *ifaddrs, *i;
> char *lastname = NULL;
> int index = 1;
Should be #if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS)
> +++ native/jni/java-net/java_net_VMNetworkInterface.c 9 Oct 2006 16:47:32
> -0000
> @@ -41,7 +41,9 @@
>
> #include <sys/types.h>
> #include <sys/socket.h>
> +#ifde HAVE_IFADDRS_H
> #include <ifaddrs.h>
> +#endif
Should be #ifdef.
Committed as attached.
Cheers,
Mark
Index: native/jni/java-net/java_net_VMNetworkInterface.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-net/java_net_VMNetworkInterface.c,v
retrieving revision 1.4
diff -u -r1.4 java_net_VMNetworkInterface.c
--- native/jni/java-net/java_net_VMNetworkInterface.c 17 Sep 2006 07:31:43 -0000 1.4
+++ native/jni/java-net/java_net_VMNetworkInterface.c 26 Nov 2006 13:30:58 -0000
@@ -41,7 +41,9 @@
#include <sys/types.h>
#include <sys/socket.h>
+#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
+#endif
#include <netinet/in.h>
#include <errno.h>
#include <stdlib.h>
@@ -111,7 +113,7 @@
JNIEXPORT jobjectArray JNICALL
Java_java_net_VMNetworkInterface_getVMInterfaces (JNIEnv * env, jclass clazz)
{
-#ifdef HAVE_GETIFADDRS
+#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS)
struct ifaddrs *ifaddrs, *i;
struct netif_entry *iflist = NULL, *e;
jobjectArray netifs;
Index: native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c,v
retrieving revision 1.13
diff -u -r1.13 gnu_java_net_VMPlainSocketImpl.c
--- native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c 25 Oct 2006 00:33:26 -0000 1.13
+++ native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c 26 Nov 2006 13:30:58 -0000
@@ -46,7 +46,9 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
+#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
+#endif
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <net/if.h>
@@ -877,7 +879,7 @@
static uint32_t
getif_address (JNIEnv *env, const char *ifname)
{
-#ifdef HAVE_GETIFADDRS
+#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS)
struct ifaddrs *ifaddrs, *i;
uint32_t addr = 0;
int foundaddr = 0;
@@ -913,13 +915,13 @@
JCL_ThrowException (env, "java/lang/InternalError",
"getifaddrs not available");
return 0;
-#endif /* HAVE_GETIFADDRS */
+#endif /* HAVE_IFADDRS_H && HAVE_GETIFADDRS */
}
static int
getif_index (JNIEnv *env, const char *ifname)
{
-#ifdef HAVE_GETIFADDRS
+#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS)
struct ifaddrs *ifaddrs, *i;
char *lastname = NULL;
int index = 1;
Index: configure.ac
===================================================================
RCS file: /cvsroot/classpath/classpath/configure.ac,v
retrieving revision 1.188
diff -u -r1.188 configure.ac
--- configure.ac 27 Sep 2006 17:02:24 -0000 1.188
+++ configure.ac 26 Nov 2006 13:30:58 -0000
@@ -357,7 +357,8 @@
fcntl.h \
sys/mman.h \
magic.h \
- sys/event.h sys/epoll.h])
+ sys/event.h sys/epoll.h \
+ ifaddrs.h])
AC_EGREP_HEADER(uint32_t, stdint.h, AC_DEFINE(HAVE_INT32_DEFINED, 1, [Define to 1 if you have uint32_t]))
AC_EGREP_HEADER(uint32_t, inttypes.h, AC_DEFINE(HAVE_INT32_DEFINED, 1, [Define to 1 if you have uint32_t]))