< prev index next >

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

Print this page




 288 
 289 #else /* !DONT_ENABLE_IPV6 */
 290 
 291 jint  IPv6_supported()
 292 {
 293     int fd;
 294     void *ipv6_fn;
 295     SOCKETADDRESS sa;
 296     socklen_t sa_len = sizeof(SOCKETADDRESS);
 297 
 298     fd = socket(AF_INET6, SOCK_STREAM, 0) ;
 299     if (fd < 0) {
 300         /*
 301          *  TODO: We really cant tell since it may be an unrelated error
 302          *  for now we will assume that AF_INET6 is not available
 303          */
 304         return JNI_FALSE;
 305     }
 306 
 307     /*
 308      * If fd 0 is a socket it means we've been launched from inetd or
 309      * xinetd. If it's a socket then check the family - if it's an
 310      * IPv4 socket then we need to disable IPv6.
 311      */
 312     if (getsockname(0, &sa.sa, &sa_len) == 0) {
 313         if (sa.sa.sa_family != AF_INET6) {
 314             close(fd);
 315             return JNI_FALSE;
 316         }
 317     }
 318 
 319     /**
 320      * Linux - check if any interface has an IPv6 address.
 321      * Don't need to parse the line - we just need an indication.
 322      */
 323 #ifdef __linux__
 324     {
 325         FILE *fP = fopen("/proc/net/if_inet6", "r");
 326         char buf[255];
 327         char *bufP;
 328 
 329         if (fP == NULL) {
 330             close(fd);
 331             return JNI_FALSE;
 332         }
 333         bufP = fgets(buf, sizeof(buf), fP);




 288 
 289 #else /* !DONT_ENABLE_IPV6 */
 290 
 291 jint  IPv6_supported()
 292 {
 293     int fd;
 294     void *ipv6_fn;
 295     SOCKETADDRESS sa;
 296     socklen_t sa_len = sizeof(SOCKETADDRESS);
 297 
 298     fd = socket(AF_INET6, SOCK_STREAM, 0) ;
 299     if (fd < 0) {
 300         /*
 301          *  TODO: We really cant tell since it may be an unrelated error
 302          *  for now we will assume that AF_INET6 is not available
 303          */
 304         return JNI_FALSE;
 305     }
 306 
 307     /*
 308      * If fd 0 is a socket it means we may have been launched from inetd or
 309      * xinetd. If it's a socket then check the family - if it's an
 310      * IPv4 socket then we need to disable IPv6.
 311      */
 312     if (getsockname(0, &sa.sa, &sa_len) == 0) {
 313         if (sa.sa.sa_family == AF_INET) {
 314             close(fd);
 315             return JNI_FALSE;
 316         }
 317     }
 318 
 319     /**
 320      * Linux - check if any interface has an IPv6 address.
 321      * Don't need to parse the line - we just need an indication.
 322      */
 323 #ifdef __linux__
 324     {
 325         FILE *fP = fopen("/proc/net/if_inet6", "r");
 326         char buf[255];
 327         char *bufP;
 328 
 329         if (fP == NULL) {
 330             close(fd);
 331             return JNI_FALSE;
 332         }
 333         bufP = fgets(buf, sizeof(buf), fP);


< prev index next >