1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
Index: java/net/NetworkInterface.java
===================================================================
--- java/net/NetworkInterface.java.orig 2006-12-18 22:37:39.000000000 +0100
+++ java/net/NetworkInterface.java 2008-06-06 14:00:44.000000000 +0200
@@ -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
===================================================================
--- vm/reference/java/net/VMNetworkInterface.java.orig 2006-12-18 22:37:39.000000000 +0100
+++ vm/reference/java/net/VMNetworkInterface.java 2008-06-06 14:00:44.000000000 +0200
@@ -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
===================================================================
--- native/jni/java-net/java_net_VMNetworkInterface.c.orig 2007-04-05 14:34:19.000000000 +0200
+++ native/jni/java-net/java_net_VMNetworkInterface.c 2008-06-06 14:00:44.000000000 +0200
@@ -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 <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 @@
#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 */
Index: include/java_net_VMNetworkInterface.h
===================================================================
--- include/java_net_VMNetworkInterface.h.orig 2008-06-06 14:21:27.000000000 +0200
+++ include/java_net_VMNetworkInterface.h 2008-06-06 14:22:12.000000000 +0200
@@ -12,6 +12,10 @@
JNIEXPORT void JNICALL Java_java_net_VMNetworkInterface_initIds (JNIEnv *env, jclass);
JNIEXPORT jobjectArray JNICALL Java_java_net_VMNetworkInterface_getVMInterfaces (JNIEnv *env, jclass);
+JNIEXPORT jboolean JNICALL Java_java_net_VMNetworkInterface_isUp (JNIEnv *env, jclass, jstring);
+JNIEXPORT jboolean JNICALL Java_java_net_VMNetworkInterface_isLoopback (JNIEnv *env, jclass, jstring);
+JNIEXPORT jboolean JNICALL Java_java_net_VMNetworkInterface_isPointToPoint (JNIEnv *env, jclass, jstring);
+JNIEXPORT jboolean JNICALL Java_java_net_VMNetworkInterface_supportsMulticast (JNIEnv *env, jclass, jstring);
#ifdef __cplusplus
}
|