< prev index next >

src/java.base/unix/native/libnet/Inet6AddressImpl.c

Print this page




 686         return JNI_FALSE;
 687     }
 688 
 689     // If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
 690     // therefore, let's delegate to the Inet4Address method.
 691     sz = (*env)->GetArrayLength(env, addrArray);
 692     if (sz == 4) {
 693         return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
 694                                                            addrArray, timeout,
 695                                                            ifArray, ttl);
 696     }
 697 
 698     // load address to SOCKETADDRESS
 699     memset((char *)caddr, 0, 16);
 700     (*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
 701     memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
 702     memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
 703     sa.sa6.sin6_family = AF_INET6;
 704     if (scope > 0) {
 705         sa.sa6.sin6_scope_id = scope;




 706     }
 707 
 708     // load network interface address to SOCKETADDRESS, if specified
 709     if (!(IS_NULL(ifArray))) {
 710         memset((char *)caddr, 0, 16);
 711         (*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
 712         memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
 713         memcpy((void *)&inf.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
 714         inf.sa6.sin6_family = AF_INET6;
 715         inf.sa6.sin6_scope_id = if_scope;
 716         netif = &inf;
 717     }
 718 
 719     // Let's try to create a RAW socket to send ICMP packets.
 720     // This usually requires "root" privileges, so it's likely to fail.
 721     fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 722     if (fd == -1) {
 723         return tcp_ping6(env, &sa, netif, timeout, ttl);
 724     } else {
 725         // It didn't fail, so we can use ICMP_ECHO requests.


 686         return JNI_FALSE;
 687     }
 688 
 689     // If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
 690     // therefore, let's delegate to the Inet4Address method.
 691     sz = (*env)->GetArrayLength(env, addrArray);
 692     if (sz == 4) {
 693         return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
 694                                                            addrArray, timeout,
 695                                                            ifArray, ttl);
 696     }
 697 
 698     // load address to SOCKETADDRESS
 699     memset((char *)caddr, 0, 16);
 700     (*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
 701     memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
 702     memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
 703     sa.sa6.sin6_family = AF_INET6;
 704     if (scope > 0) {
 705         sa.sa6.sin6_scope_id = scope;
 706 #if defined(__linux__)
 707     } else {
 708         sa.sa6.sin6_scope_id = getDefaultIPv6Interface(&sa.sa6.sin6_addr);
 709 #endif
 710     }
 711 
 712     // load network interface address to SOCKETADDRESS, if specified
 713     if (!(IS_NULL(ifArray))) {
 714         memset((char *)caddr, 0, 16);
 715         (*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
 716         memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
 717         memcpy((void *)&inf.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
 718         inf.sa6.sin6_family = AF_INET6;
 719         inf.sa6.sin6_scope_id = if_scope;
 720         netif = &inf;
 721     }
 722 
 723     // Let's try to create a RAW socket to send ICMP packets.
 724     // This usually requires "root" privileges, so it's likely to fail.
 725     fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 726     if (fd == -1) {
 727         return tcp_ping6(env, &sa, netif, timeout, ttl);
 728     } else {
 729         // It didn't fail, so we can use ICMP_ECHO requests.
< prev index next >