35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
/* do not move; needed here because of some macro definitions */ |
39 |
|
#include <config.h> |
40 |
|
|
|
#include <stdio.h> |
|
41 |
#include <stdlib.h> |
#include <stdlib.h> |
42 |
|
#include <stdio.h> |
43 |
#include <string.h> |
#include <string.h> |
44 |
#include <errno.h> |
#include <assert.h> |
|
#include <sys/types.h> |
|
|
#include <sys/socket.h> |
|
|
#include <netinet/in.h> |
|
45 |
|
|
46 |
#include <jni.h> |
#include <jni.h> |
47 |
#include <jcl.h> |
#include <jcl.h> |
48 |
|
|
|
#include "java_net_PlainDatagramSocketImpl.h" |
|
|
|
|
49 |
#include "javanet.h" |
#include "javanet.h" |
50 |
|
|
51 |
|
#include "target_native.h" |
52 |
|
#ifndef WITHOUT_NETWORK |
53 |
|
#include "target_native_network.h" |
54 |
|
#endif /* WITHOUT_NETWORK */ |
55 |
|
|
56 |
|
#include "java_net_PlainDatagramSocketImpl.h" |
57 |
|
|
58 |
/* |
/* |
59 |
* Note that most of the functions in this module simply redirect to another |
* Note that most of the functions in this module simply redirect to another |
60 |
* internal function. Why? Because many of these functions are shared |
* internal function. Why? Because many of these functions are shared |
69 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
70 |
Java_java_net_PlainDatagramSocketImpl_create(JNIEnv *env, jobject this) |
Java_java_net_PlainDatagramSocketImpl_create(JNIEnv *env, jobject this) |
71 |
{ |
{ |
72 |
|
assert(env!=NULL); |
73 |
|
assert((*env)!=NULL); |
74 |
|
|
75 |
|
#ifndef WITHOUT_NETWORK |
76 |
_javanet_create(env, this, 0); |
_javanet_create(env, this, 0); |
77 |
|
#else /* not WITHOUT_NETWORK */ |
78 |
|
#endif /* not WITHOUT_NETWORK */ |
79 |
} |
} |
80 |
|
|
81 |
/*************************************************************************/ |
/*************************************************************************/ |
86 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
87 |
Java_java_net_PlainDatagramSocketImpl_close(JNIEnv *env, jobject this) |
Java_java_net_PlainDatagramSocketImpl_close(JNIEnv *env, jobject this) |
88 |
{ |
{ |
89 |
|
assert(env!=NULL); |
90 |
|
assert((*env)!=NULL); |
91 |
|
|
92 |
|
#ifndef WITHOUT_NETWORK |
93 |
_javanet_close(env, this, 0); |
_javanet_close(env, this, 0); |
94 |
|
#else /* not WITHOUT_NETWORK */ |
95 |
|
#endif /* not WITHOUT_NETWORK */ |
96 |
} |
} |
97 |
|
|
98 |
/*************************************************************************/ |
/*************************************************************************/ |
106 |
Java_java_net_PlainDatagramSocketImpl_bind(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_bind(JNIEnv *env, jobject this, |
107 |
jint port, jobject addr) |
jint port, jobject addr) |
108 |
{ |
{ |
109 |
|
assert(env!=NULL); |
110 |
|
assert((*env)!=NULL); |
111 |
|
|
112 |
|
#ifndef WITHOUT_NETWORK |
113 |
_javanet_bind(env, this, addr, port, 0); |
_javanet_bind(env, this, addr, port, 0); |
114 |
|
#else /* not WITHOUT_NETWORK */ |
115 |
|
#endif /* not WITHOUT_NETWORK */ |
116 |
} |
} |
117 |
|
|
118 |
/*************************************************************************/ |
/*************************************************************************/ |
124 |
Java_java_net_PlainDatagramSocketImpl_setOption(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_setOption(JNIEnv *env, jobject this, |
125 |
jint option_id, jobject val) |
jint option_id, jobject val) |
126 |
{ |
{ |
127 |
|
assert(env!=NULL); |
128 |
|
assert((*env)!=NULL); |
129 |
|
|
130 |
|
#ifndef WITHOUT_NETWORK |
131 |
_javanet_set_option(env, this, option_id, val); |
_javanet_set_option(env, this, option_id, val); |
132 |
|
#else /* not WITHOUT_NETWORK */ |
133 |
|
#endif /* not WITHOUT_NETWORK */ |
134 |
} |
} |
135 |
|
|
136 |
/*************************************************************************/ |
/*************************************************************************/ |
142 |
Java_java_net_PlainDatagramSocketImpl_getOption(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_getOption(JNIEnv *env, jobject this, |
143 |
jint option_id) |
jint option_id) |
144 |
{ |
{ |
145 |
|
assert(env!=NULL); |
146 |
|
assert((*env)!=NULL); |
147 |
|
|
148 |
|
#ifndef WITHOUT_NETWORK |
149 |
return(_javanet_get_option(env, this, option_id)); |
return(_javanet_get_option(env, this, option_id)); |
150 |
|
#else /* not WITHOUT_NETWORK */ |
151 |
|
#endif /* not WITHOUT_NETWORK */ |
152 |
} |
} |
153 |
|
|
154 |
/*************************************************************************/ |
/*************************************************************************/ |
160 |
Java_java_net_PlainDatagramSocketImpl_receive(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_receive(JNIEnv *env, jobject this, |
161 |
jobject packet) |
jobject packet) |
162 |
{ |
{ |
163 |
unsigned int addr = 0, port = 0, len = 0, bytes_read = 0; |
#ifndef WITHOUT_NETWORK |
164 |
jclass cls, addr_cls; |
unsigned int addr, port, len, bytes_read; |
165 |
jmethodID mid; |
jclass cls, addr_cls; |
166 |
jarray arr; |
jmethodID mid; |
167 |
jbyte *buf; |
jarray arr; |
168 |
char ip_str[16]; |
unsigned char octets[4]; |
169 |
jobject ip_str_obj, addr_obj; |
char ip_str[16]; |
170 |
|
jobject ip_str_obj, addr_obj; |
171 |
|
|
172 |
|
assert(env!=NULL); |
173 |
|
assert((*env)!=NULL); |
174 |
|
|
175 |
|
addr = 0; |
176 |
|
port = 0; |
177 |
|
len = 0; |
178 |
|
bytes_read = 0; |
179 |
|
|
180 |
if(packet == NULL) |
if(packet == NULL) |
181 |
{ JCL_ThrowException(env, "java/lang/NullPointerException", "Null datagram packet"); return; } |
{ |
182 |
|
JCL_ThrowException(env, "java/lang/NullPointerException", "Null datagram packet"); |
183 |
|
return; |
184 |
|
} |
185 |
|
|
186 |
/* Get the buffer from the packet */ |
/* Get the buffer from the packet */ |
187 |
cls = (*env)->GetObjectClass(env, packet); |
cls = (*env)->GetObjectClass(env, packet); |
188 |
if (cls == NULL) |
if (cls == NULL) |
189 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
190 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
191 |
|
return; |
192 |
|
} |
193 |
|
|
194 |
mid = (*env)->GetMethodID(env, cls, "getData", "()[B"); |
mid = (*env)->GetMethodID(env, cls, "getData", "()[B"); |
195 |
if (mid == NULL) |
if (mid == NULL) |
196 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
197 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getData"); |
198 |
|
return; |
199 |
|
} |
200 |
|
|
201 |
arr = (*env)->CallObjectMethod(env, packet, mid); |
arr = (*env)->CallObjectMethod(env, packet, mid); |
202 |
if ((arr == NULL) || (*env)->ExceptionOccurred(env)) |
if ((arr == NULL) || (*env)->ExceptionOccurred(env)) |
203 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
204 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getData"); |
205 |
|
return; |
206 |
|
} |
207 |
|
|
208 |
/* Now get the length from the packet */ |
/* Now get the length from the packet */ |
209 |
mid = (*env)->GetMethodID(env, cls, "getLength", "()I"); |
mid = (*env)->GetMethodID(env, cls, "getLength", "()I"); |
210 |
if (mid == NULL) |
if (mid == NULL) |
211 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
212 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getLength"); |
213 |
|
return; |
214 |
|
} |
215 |
|
|
216 |
len = (*env)->CallIntMethod(env, packet, mid); |
len = (*env)->CallIntMethod(env, packet, mid); |
217 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
218 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
219 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getLength"); |
220 |
|
return; |
221 |
|
} |
222 |
|
|
223 |
DBG("PlainDatagramSocketImpl.receive(): Got the length\n"); |
DBG("PlainDatagramSocketImpl.receive(): Got the length\n"); |
224 |
|
|
226 |
/* should we try some sort of validation on the length? */ |
/* should we try some sort of validation on the length? */ |
227 |
bytes_read = _javanet_recvfrom(env, this, arr, 0, len, &addr, &port); |
bytes_read = _javanet_recvfrom(env, this, arr, 0, len, &addr, &port); |
228 |
if ((bytes_read == -1) || (*env)->ExceptionOccurred(env)) |
if ((bytes_read == -1) || (*env)->ExceptionOccurred(env)) |
229 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
230 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: receive"); |
231 |
|
return; |
232 |
|
} |
233 |
|
|
234 |
DBG("PlainDatagramSocketImpl.receive(): Received packet\n"); |
DBG("PlainDatagramSocketImpl.receive(): Received packet\n"); |
235 |
|
|
236 |
/* Store the address */ |
/* Store the address */ |
237 |
addr = ntohl(addr); |
TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(addr, |
238 |
sprintf(ip_str, "%d.%d.%d.%d", (addr & 0xFF000000) >> 24, |
octets[0], |
239 |
(addr & 0x00FF0000) >> 16, (addr & 0x0000FF00) >> 8, |
octets[1], |
240 |
(addr & 0x000000FF)); |
octets[2], |
241 |
|
octets[3] |
242 |
|
); |
243 |
|
sprintf(ip_str, "%d.%d.%d.%d", |
244 |
|
octets[0], |
245 |
|
octets[1], |
246 |
|
octets[2], |
247 |
|
octets[3] |
248 |
|
); |
249 |
ip_str_obj = (*env)->NewStringUTF(env, ip_str); |
ip_str_obj = (*env)->NewStringUTF(env, ip_str); |
250 |
if (ip_str_obj == NULL) |
if (ip_str_obj == NULL) |
251 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
252 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: new string"); |
253 |
|
return; |
254 |
|
} |
255 |
|
|
256 |
addr_cls = (*env)->FindClass(env, "java/net/InetAddress"); |
addr_cls = (*env)->FindClass(env, "java/net/InetAddress"); |
257 |
if (addr_cls == NULL) |
if (addr_cls == NULL) |
258 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); return; } |
{ |
259 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: InetAddress class"); |
260 |
|
return; |
261 |
|
} |
262 |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress class\n"); |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress class\n"); |
263 |
|
|
264 |
mid = (*env)->GetStaticMethodID(env, addr_cls, "getByName", |
mid = (*env)->GetStaticMethodID(env, addr_cls, "getByName", |
265 |
"(Ljava/lang/String;)Ljava/net/InetAddress;"); |
"(Ljava/lang/String;)Ljava/net/InetAddress;"); |
266 |
if (mid == NULL) |
if (mid == NULL) |
267 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); return; } |
{ |
268 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); |
269 |
|
return; |
270 |
|
} |
271 |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n"); |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n"); |
272 |
|
|
273 |
addr_obj = (*env)->CallStaticObjectMethod(env, addr_cls, mid, ip_str_obj); |
addr_obj = (*env)->CallStaticObjectMethod(env, addr_cls, mid, ip_str_obj); |
274 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
275 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
276 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getByName"); |
277 |
|
return; |
278 |
|
} |
279 |
|
|
280 |
mid = (*env)->GetMethodID(env, cls, "setAddress", |
mid = (*env)->GetMethodID(env, cls, "setAddress", |
281 |
"(Ljava/net/InetAddress;)V"); |
"(Ljava/net/InetAddress;)V"); |
282 |
if (mid == NULL) |
if (mid == NULL) |
283 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); return; } |
{ |
284 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setAddress"); |
285 |
|
return; |
286 |
|
} |
287 |
|
|
288 |
(*env)->CallVoidMethod(env, packet, mid, addr_obj); |
(*env)->CallVoidMethod(env, packet, mid, addr_obj); |
289 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
290 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
291 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setAddress"); |
292 |
|
return; |
293 |
|
} |
294 |
|
|
295 |
DBG("PlainDatagramSocketImpl.receive(): Stored the address\n"); |
DBG("PlainDatagramSocketImpl.receive(): Stored the address\n"); |
296 |
|
|
299 |
|
|
300 |
mid = (*env)->GetMethodID(env, cls, "setPort", "(I)V"); |
mid = (*env)->GetMethodID(env, cls, "setPort", "(I)V"); |
301 |
if (mid == NULL) |
if (mid == NULL) |
302 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); return; } |
{ |
303 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setPort"); |
304 |
|
return; |
305 |
|
} |
306 |
|
|
307 |
(*env)->CallVoidMethod(env, packet, mid, port); |
(*env)->CallVoidMethod(env, packet, mid, port); |
308 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
309 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
310 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setPort"); |
311 |
|
return; |
312 |
|
} |
313 |
|
|
314 |
DBG("PlainDatagramSocketImpl.receive(): Stored the port\n"); |
DBG("PlainDatagramSocketImpl.receive(): Stored the port\n"); |
315 |
|
|
316 |
/* Store back the length */ |
/* Store back the length */ |
317 |
mid = (*env)->GetMethodID(env, cls, "setLength", "(I)V"); |
mid = (*env)->GetMethodID(env, cls, "setLength", "(I)V"); |
318 |
if (mid == NULL) |
if (mid == NULL) |
319 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); return; } |
{ |
320 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setLength"); |
321 |
|
return; |
322 |
|
} |
323 |
|
|
324 |
(*env)->CallVoidMethod(env, packet, mid, bytes_read); |
(*env)->CallVoidMethod(env, packet, mid, bytes_read); |
325 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
326 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
327 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setLength"); |
328 |
|
return; |
329 |
|
} |
330 |
|
|
331 |
DBG("PlainDatagramSocketImpl.receive(): Stored the length\n"); |
DBG("PlainDatagramSocketImpl.receive(): Stored the length\n"); |
332 |
|
#else /* not WITHOUT_NETWORK */ |
333 |
return; |
#endif /* not WITHOUT_NETWORK */ |
334 |
} |
} |
335 |
|
|
336 |
/*************************************************************************/ |
/*************************************************************************/ |
343 |
jobject addr, jint port, jarray buf, |
jobject addr, jint port, jarray buf, |
344 |
jint len) |
jint len) |
345 |
{ |
{ |
346 |
struct ip_mreq ipm; |
#ifndef WITHOUT_NETWORK |
347 |
memset(&ipm, 0, sizeof(ipm)); |
jint netAddress; |
348 |
ipm.imr_multiaddr.s_addr = _javanet_get_netaddr(env, addr); |
|
349 |
|
assert(env!=NULL); |
350 |
|
assert((*env)!=NULL); |
351 |
|
|
352 |
|
netAddress = _javanet_get_netaddr(env, addr); |
353 |
|
|
354 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
355 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
356 |
|
|
357 |
DBG("PlainDatagramSocketImpl.sendto(): have addr\n"); |
DBG("PlainDatagramSocketImpl.sendto(): have addr\n"); |
358 |
|
|
359 |
_javanet_sendto(env, this, buf, 0, len, ipm.imr_multiaddr.s_addr, |
_javanet_sendto(env, this, buf, 0, len, netAddress, port); |
|
htons(((unsigned short)port))); |
|
360 |
|
|
361 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
362 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
363 |
|
|
364 |
DBG("PlainDatagramSocketImpl.sendto(): finished\n"); |
DBG("PlainDatagramSocketImpl.sendto(): finished\n"); |
365 |
|
#else /* not WITHOUT_NETWORK */ |
366 |
|
#endif /* not WITHOUT_NETWORK */ |
367 |
} |
} |
368 |
|
|
369 |
/*************************************************************************/ |
/*************************************************************************/ |
375 |
Java_java_net_PlainDatagramSocketImpl_join(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_join(JNIEnv *env, jobject this, |
376 |
jobject addr) |
jobject addr) |
377 |
{ |
{ |
378 |
int rc, fd; |
#ifndef WITHOUT_NETWORK |
379 |
struct ip_mreq ipm; |
jint netAddress; |
380 |
|
int fd; |
381 |
memset(&ipm, 0, sizeof(ipm)); |
int result; |
382 |
ipm.imr_multiaddr.s_addr = _javanet_get_netaddr(env, addr); |
|
383 |
if ((*env)->ExceptionOccurred(env)) |
assert(env!=NULL); |
384 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
assert((*env)!=NULL); |
385 |
|
|
386 |
ipm.imr_interface.s_addr = INADDR_ANY; |
netAddress = _javanet_get_netaddr(env, addr); |
387 |
|
if ((*env)->ExceptionOccurred(env)) |
388 |
|
{ |
389 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
390 |
|
return; |
391 |
|
} |
392 |
|
|
393 |
fd = _javanet_get_int_field(env, this, "native_fd"); |
fd = _javanet_get_int_field(env, this, "native_fd"); |
394 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
395 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
396 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
397 |
|
return; |
398 |
|
} |
399 |
|
|
400 |
DBG("PlainDatagramSocketImpl.join(): have native fd\n"); |
DBG("PlainDatagramSocketImpl.join(): have native fd\n"); |
401 |
|
|
402 |
rc = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipm, sizeof(ipm)); |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP(fd,netAddress,result); |
403 |
|
|
404 |
if (rc == -1) |
if (result != TARGET_NATIVE_OK) |
405 |
JCL_ThrowException(env, IO_EXCEPTION, strerror(errno)); |
{ |
406 |
|
JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); |
407 |
|
return; |
408 |
|
} |
409 |
|
|
410 |
DBG("PlainDatagramSocketImpl.join(): finished\n"); |
DBG("PlainDatagramSocketImpl.join(): finished\n"); |
411 |
|
#else /* not WITHOUT_NETWORK */ |
412 |
|
#endif /* not WITHOUT_NETWORK */ |
413 |
} |
} |
414 |
|
|
415 |
/*************************************************************************/ |
/*************************************************************************/ |
421 |
Java_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this, |
Java_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this, |
422 |
jobject addr) |
jobject addr) |
423 |
{ |
{ |
424 |
int rc, fd; |
#ifndef WITHOUT_NETWORK |
425 |
struct ip_mreq ipm; |
jint netAddress; |
426 |
|
int fd; |
427 |
memset(&ipm, 0, sizeof(ipm)); |
int result; |
428 |
ipm.imr_multiaddr.s_addr = _javanet_get_netaddr(env, addr); |
|
429 |
if ((*env)->ExceptionOccurred(env)) |
assert(env!=NULL); |
430 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
assert((*env)!=NULL); |
431 |
|
|
432 |
ipm.imr_interface.s_addr = INADDR_ANY; |
netAddress = _javanet_get_netaddr(env, addr); |
433 |
|
if ((*env)->ExceptionOccurred(env)) |
434 |
|
{ |
435 |
|
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
436 |
|
return; |
437 |
|
} |
438 |
|
|
439 |
fd = _javanet_get_int_field(env, this, "native_fd"); |
fd = _javanet_get_int_field(env, this, "native_fd"); |
440 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred(env)) |
442 |
|
|
443 |
DBG("PlainDatagramSocketImpl.leave(): have native fd\n"); |
DBG("PlainDatagramSocketImpl.leave(): have native fd\n"); |
444 |
|
|
445 |
rc = setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &ipm, sizeof(ipm)); |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP(fd,netAddress,result); |
446 |
|
if (result!=TARGET_NATIVE_OK) |
447 |
if (rc == -1) |
{ |
448 |
JCL_ThrowException(env, IO_EXCEPTION, strerror(errno)); |
JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); |
449 |
|
return; |
450 |
|
} |
451 |
|
|
452 |
DBG("PlainDatagramSocketImpl.leave(): finished\n"); |
DBG("PlainDatagramSocketImpl.leave(): finished\n"); |
453 |
|
#else /* not WITHOUT_NETWORK */ |
454 |
|
#endif /* not WITHOUT_NETWORK */ |
455 |
} |
} |