Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-05-16 Thread Andrew John Hughes
2008/5/15 Robert Schuster <[EMAIL PROTECTED]>:
> Hi,
>  I committed this today.
>
>  2008-05-15  Robert Schuster  <[EMAIL PROTECTED]>
>
>
>   * java/net/NetworkInterface.java:
>   (isUp): New method.
>   (isPointToPoint): Dito.
>   (isLoopback): Dito.
>   (supportsMulticast): Dito.
>   * vm/reference/java/net/VMNetworkInterface.java:
>   (isUp): New method.
>   (isPointToPoint): Dito.
>   (isLoopback): Dito.
>   (supportsMulticast): Dito.
>   * native/jni/java-net/java_net_VMNetworkInterface.c:
>   (isUp): New method.
>   (isPointToPoint): Dito.
>   (isLoopback): Dito.
>   (supportsMulticast): Dito.
>
>  Regards
>  Robert
>
>  Robert Schuster schrieb:
>
>
> > Hi.
>  >
>  > Robert Schuster schrieb:
>  >> Hi,
>  >> I fixed the copy and paste error and another flaw. Casting to jboolean
>  >> did not alway returned the correct result. I made the if-flag-set then
>  >> JNI_TRUE otherwise JNI_FALSE explicit. Now it works correctly.
>  > If no one objects I would like to commit this patch.
>  >
>  > Regards
>  > Robert
>  >
>
>
>


FWIW, this made us regress on building on Solaris 9:


if /bin/bash ../../../libtool --tag=CC --mode=compile gcc
-DHAVE_CONFIG_H -I.
-I/share/nlp/projects/cashew/sources/classpath/native/jni/java-net
-I../../../include
-I/share/nlp/projects/cashew/sources/classpath/include
-I/share/nlp/projects/cashew/sources/classpath/native/jni/classpath
-I/share/nlp/projects/cashew/sources/classpath/native/jni/native-lib
-W -Wall -Wmissing-declarations -Wwrite-strings -Wmissing-prototypes
-Wno-long-long -Wstrict-prototypes -pedantic -Werror -g -O2 -MT
java_net_VMNetworkInterface.lo -MD -MP -MF
".deps/java_net_VMNetworkInterface.Tpo" -c -o
java_net_VMNetworkInterface.lo
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c;
\
then mv -f ".deps/java_net_VMNetworkInterface.Tpo"
".deps/java_net_VMNetworkInterface.Plo"; else rm -f
".deps/java_net_VMNetworkInterface.Tpo"; exit 1; fi
 gcc -DHAVE_CONFIG_H -I.
-I/share/nlp/projects/cashew/sources/classpath/native/jni/java-net
-I../../../include
-I/share/nlp/projects/cashew/sources/classpath/include
-I/share/nlp/projects/cashew/sources/classpath/native/jni/classpath
-I/share/nlp/projects/cashew/sources/classpath/native/jni/native-lib
-W -Wall -Wmissing-declarations -Wwrite-strings -Wmissing-prototypes
-Wno-long-long -Wstrict-prototypes -pedantic -Werror -g -O2 -MT
java_net_VMNetworkInterface.lo -MD -MP -MF
.deps/java_net_VMNetworkInterface.Tpo -c
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c
 -fPIC -DPIC -o .libs/java_net_VMNetworkInterface.o
cc1: warnings being treated as errors
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c:
In function 'iff_flags':
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c:277:
warning: implicit declaration of function 'ioctl'
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c:277:
error: 'SIOCGIFFLAGS' undeclared (first use in this function)
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c:277:
error: (Each undeclared identifier is reported only once
/share/nlp/projects/cashew/sources/classpath/native/jni/java-net/java_net_VMNetworkInterface.c:277:
error: for each function it appears in.)
make[3]: *** [java_net_VMNetworkInterface.lo] Error 1
make[3]: Leaving directory
`/share/nlp/projects/cashew/build/sparc-sun-solaris2.9/classpath/native/jni/java-net'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory
`/share/nlp/projects/cashew/build/sparc-sun-solaris2.9/classpath/native/jni'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory
`/share/nlp/projects/cashew/build/sparc-sun-solaris2.9/classpath/native'
make: *** [all-recursive] Error 1

-- 
Andrew :-)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net

PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8



Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-05-15 Thread Robert Schuster
Hi,
I committed this today.

2008-05-15  Robert Schuster  <[EMAIL PROTECTED]>

  * java/net/NetworkInterface.java:
  (isUp): New method.
  (isPointToPoint): Dito.
  (isLoopback): Dito.
  (supportsMulticast): Dito.
  * vm/reference/java/net/VMNetworkInterface.java:
  (isUp): New method.
  (isPointToPoint): Dito.
  (isLoopback): Dito.
  (supportsMulticast): Dito.
  * native/jni/java-net/java_net_VMNetworkInterface.c:
  (isUp): New method.
  (isPointToPoint): Dito.
  (isLoopback): Dito.
  (supportsMulticast): Dito.

Regards
Robert

Robert Schuster schrieb:
> Hi.
> 
> Robert Schuster schrieb:
>> Hi,
>> I fixed the copy and paste error and another flaw. Casting to jboolean
>> did not alway returned the correct result. I made the if-flag-set then
>> JNI_TRUE otherwise JNI_FALSE explicit. Now it works correctly.
> If no one objects I would like to commit this patch.
> 
> Regards
> Robert
> 




signature.asc
Description: OpenPGP digital signature


Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-04-22 Thread Robert Schuster
Hi.

Robert Schuster schrieb:
> Hi,
> I fixed the copy and paste error and another flaw. Casting to jboolean
> did not alway returned the correct result. I made the if-flag-set then
> JNI_TRUE otherwise JNI_FALSE explicit. Now it works correctly.
If no one objects I would like to commit this patch.

Regards
Robert



signature.asc
Description: OpenPGP digital signature


Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-04-21 Thread Robert Schuster
Hi,
I fixed the copy and paste error and another flaw. Casting to jboolean
did not alway returned the correct result. I made the if-flag-set then
JNI_TRUE otherwise JNI_FALSE explicit. Now it works correctly.

Christian Thalinger schrieb:
> I wonder if it would be simpler to only have one native method,
> returning the socket flags, and mapping the IFF_ defines in
> java/net/VMNetworkInterface so you could implement it in Java.  But I
> don't know if the flags are consistent between different OS or even libc
> versions.
I would like this, too. I think our POSIX gurus should comment. :)

Regards
Robert

Index: java/net/NetworkInterface.java
===
RCS file: /sources/classpath/classpath/java/net/NetworkInterface.java,v
retrieving revision 1.23
diff -u -r1.23 NetworkInterface.java
--- java/net/NetworkInterface.java	18 Dec 2006 21:37:39 -	1.23
+++ java/net/NetworkInterface.java	21 Apr 2008 10:38:25 -
@@ -1,5 +1,5 @@
 /* NetworkInterface.java --
-   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -265,4 +265,50 @@
 
 return result.toString();
   }
+
+  /**
+   * Determines whether this interface is ready to transfer data.
+   *
+   * @return whether the interface is up
+  */
+  public boolean isUp()
+throws SocketException
+  {
+return VMNetworkInterface.isUp(netif.name);
+  }
+
+  /**
+   * Determines whether this interface does point to point
+   * transmission.
+   *
+   * @return whether the interface does point to point transmission
+  */
+  public boolean isPointToPoint()
+throws SocketException
+  {
+return VMNetworkInterface.isPointToPoint(netif.name);
+  }
+
+  /**
+   * Determines whether this interface is the loopback interface.
+   *
+   * @return whether the interface is the loopback interface
+  */
+  public boolean isLoopback()
+throws SocketException
+  {
+return VMNetworkInterface.isLoopback(netif.name);
+  }
+
+  /**
+   * Determines whether this interface supports multicast transmission.
+   *
+   * @return whether the interface supports multicast transmission.
+  */
+  public boolean supportsMulticast()
+throws SocketException
+  {
+return VMNetworkInterface.supportsMulticast(netif.name);
+  }
+
 }
Index: vm/reference/java/net/VMNetworkInterface.java
===
RCS file: /sources/classpath/classpath/vm/reference/java/net/VMNetworkInterface.java,v
retrieving revision 1.7
diff -u -r1.7 VMNetworkInterface.java
--- vm/reference/java/net/VMNetworkInterface.java	18 Dec 2006 21:37:39 -	1.7
+++ vm/reference/java/net/VMNetworkInterface.java	21 Apr 2008 10:38:25 -
@@ -1,5 +1,5 @@
 /* VMNetworkInterface.java --
-   Copyright (C) 2005  Free Software Foundation, Inc.
+   Copyright (C) 2005, 2008  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -119,4 +119,13 @@
 else
   throw new SocketException("invalid interface address");
   }
+
+  static native boolean isUp(String name) throws SocketException;
+
+  static native boolean isLoopback(String name) throws SocketException;
+
+  static native boolean isPointToPoint(String name) throws SocketException;
+
+  static native boolean supportsMulticast(String name) throws SocketException;
+
 }
Index: native/jni/java-net/java_net_VMNetworkInterface.c
===
RCS file: /sources/classpath/classpath/native/jni/java-net/java_net_VMNetworkInterface.c,v
retrieving revision 1.6
diff -u -r1.6 java_net_VMNetworkInterface.c
--- native/jni/java-net/java_net_VMNetworkInterface.c	5 Apr 2007 12:34:19 -	1.6
+++ native/jni/java-net/java_net_VMNetworkInterface.c	21 Apr 2008 10:38:25 -
@@ -1,5 +1,5 @@
 /* VMNetworkInterface.c - Native methods for NetworkInterface class
-   Copyright (C) 2003, 2005, 2006  Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005, 2006, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -50,11 +50,18 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include 
 #include 
 
+#include 
+#include 
+
 #include "java_net_VMNetworkInterface.h"
 
+int iff_flags(JNIEnv *, jstring, jint *);
 
 static jmethodID java_net_VMNetworkInterface_init;
 static jmethodID java_net_VMNetworkInterface_addAddress;
@@ -251,4 +258,136 @@
 #endif /* HAVE_IFADDRS_H && HAVE_GETIFADDRS */
 }
 
+int iff_flags(JNIEnv *env, jstring name, jint *flags)
+{
+  struct ifreq iff;
+  const char *iff_name;
+  jint socket;
+  int error, retval;
+
+  if ((error = cpnet_openSocketDatagram(env, &socket, AF_INET)))
+  {
+return error;
+  }
+
+  iff_name = JCL_jstring_to_cstring(env, name);
+  memset(&iff, 0, sizeof(iff));
+  strcpy(iff.ifr_name, iff_name);
+ 
+  if (ioctl(socket, SIOCGIFFLAGS, &iff) >= 0)
+  {
+*flags = (jint) iff.ifr_fl

Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-04-21 Thread Christian Thalinger
On Mon, 2008-04-21 at 09:03 +0200, Robert Schuster wrote:
> Hi,
> people using Jalimo asked for those methods and I found them simple to
> implement.
> 
> Since I am lousy non-Java hacker I appreciate comments on the code in
> java_net_VMNetworkInterface.c.

I wonder if it would be simpler to only have one native method,
returning the socket flags, and mapping the IFF_ defines in
java/net/VMNetworkInterface so you could implement it in Java.  But I
don't know if the flags are consistent between different OS or even libc
versions.

- twisti




Re: [cp-patches] RFC: NetworkInterface - implement some 1.6 methods

2008-04-21 Thread Christian Thalinger
On Mon, 2008-04-21 at 09:03 +0200, Robert Schuster wrote:
> +  public boolean isUp()
> +throws SocketException
> +  {
> +return VMNetworkInterface.isUp(netif.name);
> +  }

> +  public boolean isPointToPoint()
> +throws SocketException
> +  {
> +return VMNetworkInterface.isUp(netif.name);
> +  }

> +  public boolean isLoopback()
> +throws SocketException
> +  {
> +return VMNetworkInterface.isUp(netif.name);
> +  }

> +  public boolean supportsMulticast()
> +throws SocketException
> +  {
> +return VMNetworkInterface.isUp(netif.name);
> +  }

Seems like a copy-paste bug.

- twisti