diff options
author | Robert Schuster <theBohemian@gmx.net> | 2008-05-15 18:44:28 +0000 |
---|---|---|
committer | Robert Schuster <theBohemian@gmx.net> | 2008-05-15 18:44:28 +0000 |
commit | d988b0c8a3a5f0b792cc025e7ae57cbc0dd2838d (patch) | |
tree | 3113449d427d692286ef3f3f3a3fccfff6aa9c40 | |
parent | 02921b01621bc91bc1c1b9729e33515fea757e59 (diff) | |
download | classpath-d988b0c8a3a5f0b792cc025e7ae57cbc0dd2838d.tar.gz |
2008-05-15 Robert Schuster <robertschuster@fsfe.org>
* 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.
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | java/net/NetworkInterface.java | 48 | ||||
-rw-r--r-- | native/jni/java-net/java_net_VMNetworkInterface.c | 141 | ||||
-rw-r--r-- | vm/reference/java/net/VMNetworkInterface.java | 11 |
4 files changed, 215 insertions, 3 deletions
@@ -1,3 +1,21 @@ +2008-05-15 Robert Schuster <robertschuster@fsfe.org> + + * 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. + 2008-05-11 Andrew John Hughes <gnu_andrew@member.fsf.org> Reported by Nicolas Geoffray <nicolas.geoffray@menlina.com> diff --git a/java/net/NetworkInterface.java b/java/net/NetworkInterface.java index f7ea553ce..5ec64ff16 100644 --- a/java/net/NetworkInterface.java +++ b/java/net/NetworkInterface.java @@ -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. @@ -267,4 +267,50 @@ public final class NetworkInterface 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); + } + } diff --git a/native/jni/java-net/java_net_VMNetworkInterface.c b/native/jni/java-net/java_net_VMNetworkInterface.c index 73da5ee24..31e020509 100644 --- a/native/jni/java-net/java_net_VMNetworkInterface.c +++ b/native/jni/java-net/java_net_VMNetworkInterface.c @@ -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 @@ exception statement from your version. */ #include <stdio.h> #include <string.h> +#include <net/if.h> +#include <sys/ioctl.h> + #include <jni.h> #include <jcl.h> +#include <cpnative.h> +#include <cpnet.h> + #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 @@ Java_java_net_VMNetworkInterface_getVMInterfaces (JNIEnv * env, #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_flags; + + retval = 0; + } + else + { + retval = errno; + } + + cpnet_close(env, socket); + + JCL_free_cstring(env, name, iff_name); + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isUp (JNIEnv *env, jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & (IFF_UP | IFF_RUNNING)) + ? JNI_TRUE + : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isPointToPoint (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_POINTOPOINT) ? JNI_TRUE + : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isLoopback (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_LOOPBACK) ? JNI_TRUE : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_supportsMulticast (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_MULTICAST) ? JNI_TRUE : JNI_FALSE; + } + + return retval; +} + /* end of file */ diff --git a/vm/reference/java/net/VMNetworkInterface.java b/vm/reference/java/net/VMNetworkInterface.java index 34db6b626..63a29b16b 100644 --- a/vm/reference/java/net/VMNetworkInterface.java +++ b/vm/reference/java/net/VMNetworkInterface.java @@ -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 @@ final class VMNetworkInterface 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; + } |