comparison src/solaris/native/sun/nio/ch/Net.c @ 2320:a11b4063024f

Merge
author alanb
date Mon, 01 Feb 2010 13:13:46 +0000
parents daac7df87419 8df0ffac7f4d
children
comparison
equal deleted inserted replaced
11:1ec041db91ff 13:4a696ecf711e
122 122
123 /* 123 /*
124 * Copy IPv6 group, interface index, and IPv6 source address 124 * Copy IPv6 group, interface index, and IPv6 source address
125 * into group_source_req structure. 125 * into group_source_req structure.
126 */ 126 */
127 #ifdef AF_INET6
127 static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index, 128 static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index,
128 jbyteArray source, struct my_group_source_req* req) 129 jbyteArray source, struct my_group_source_req* req)
129 { 130 {
130 struct sockaddr_in6* sin6; 131 struct sockaddr_in6* sin6;
131 132
137 138
138 sin6 = (struct sockaddr_in6*)&(req->gsr_source); 139 sin6 = (struct sockaddr_in6*)&(req->gsr_source);
139 sin6->sin6_family = AF_INET6; 140 sin6->sin6_family = AF_INET6;
140 COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr)); 141 COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr));
141 } 142 }
142 143 #endif
143 144
144 JNIEXPORT void JNICALL 145 JNIEXPORT void JNICALL
145 Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz) 146 Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz)
146 { 147 {
147 /* Here because Windows native code does need to init IDs */ 148 /* Here because Windows native code does need to init IDs */
157 Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, 158 Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
158 jboolean stream, jboolean reuse) 159 jboolean stream, jboolean reuse)
159 { 160 {
160 int fd; 161 int fd;
161 int type = (stream ? SOCK_STREAM : SOCK_DGRAM); 162 int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
163 #ifdef AF_INET6
162 int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; 164 int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET;
165 #else
166 int domain = AF_INET;
167 #endif
163 168
164 fd = socket(domain, type, 0); 169 fd = socket(domain, type, 0);
165 if (fd < 0) { 170 if (fd < 0) {
166 return handleSocketError(env, errno); 171 return handleSocketError(env, errno);
167 } 172 }
174 "sun.nio.ch.Net.setIntOption"); 179 "sun.nio.ch.Net.setIntOption");
175 close(fd); 180 close(fd);
176 return -1; 181 return -1;
177 } 182 }
178 } 183 }
179 #ifdef __linux__ 184 #if defined(__linux__) && defined(AF_INET6)
180 /* By default, Linux uses the route default */ 185 /* By default, Linux uses the route default */
181 if (domain == AF_INET6 && type == SOCK_DGRAM) { 186 if (domain == AF_INET6 && type == SOCK_DGRAM) {
182 int arg = 1; 187 int arg = 1;
183 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg, 188 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg,
184 sizeof(arg)) < 0) { 189 sizeof(arg)) < 0) {
422 427
423 JNIEXPORT jint JNICALL 428 JNIEXPORT jint JNICALL
424 Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo, 429 Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo,
425 jbyteArray group, jint index, jbyteArray source) 430 jbyteArray group, jint index, jbyteArray source)
426 { 431 {
432 #ifdef AF_INET6
427 struct ipv6_mreq mreq6; 433 struct ipv6_mreq mreq6;
428 struct my_group_source_req req; 434 struct my_group_source_req req;
429 int opt, n, optlen; 435 int opt, n, optlen;
430 void* optval; 436 void* optval;
431 437
452 if (join && (errno == ENOPROTOOPT)) 458 if (join && (errno == ENOPROTOOPT))
453 return IOS_UNAVAILABLE; 459 return IOS_UNAVAILABLE;
454 handleSocketError(env, errno); 460 handleSocketError(env, errno);
455 } 461 }
456 return 0; 462 return 0;
463 #else
464 JNU_ThrowInternalError(env, "Should not get here");
465 return IOS_THROWN;
466 #endif /* AF_INET6 */
457 } 467 }
458 468
459 JNIEXPORT jint JNICALL 469 JNIEXPORT jint JNICALL
460 Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo, 470 Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo,
461 jbyteArray group, jint index, jbyteArray source) 471 jbyteArray group, jint index, jbyteArray source)
462 { 472 {
473 #ifdef AF_INET6
463 struct my_group_source_req req; 474 struct my_group_source_req req;
464 int n; 475 int n;
465 int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE; 476 int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE;
466 477
467 initGroupSourceReq(env, group, index, source, &req); 478 initGroupSourceReq(env, group, index, source, &req);
472 if (block && (errno == ENOPROTOOPT)) 483 if (block && (errno == ENOPROTOOPT))
473 return IOS_UNAVAILABLE; 484 return IOS_UNAVAILABLE;
474 handleSocketError(env, errno); 485 handleSocketError(env, errno);
475 } 486 }
476 return 0; 487 return 0;
488 #else
489 JNU_ThrowInternalError(env, "Should not get here");
490 return IOS_THROWN;
491 #endif
477 } 492 }
478 493
479 JNIEXPORT void JNICALL 494 JNIEXPORT void JNICALL
480 Java_sun_nio_ch_Net_setInterface4(JNIEnv* env, jobject this, jobject fdo, jint interf) 495 Java_sun_nio_ch_Net_setInterface4(JNIEnv* env, jobject this, jobject fdo, jint interf)
481 { 496 {