mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
6914801: IPv6 unavailable if stdin is a socket
Reviewed-by: michaelm
This commit is contained in:
parent
d03a5d9580
commit
8d17d1ee6f
7 changed files with 177 additions and 38 deletions
|
@ -123,18 +123,7 @@ jint IPv6_supported()
|
|||
*/
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* If fd 0 is a socket it means we may have been launched from inetd or
|
||||
* xinetd. If it's a socket then check the family - if it's an
|
||||
* IPv4 socket then we need to disable IPv6.
|
||||
*/
|
||||
if (getsockname(0, &sa.sa, &sa_len) == 0) {
|
||||
if (sa.sa.sa_family == AF_INET) {
|
||||
close(fd);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
|
||||
/**
|
||||
* Linux - check if any interface has an IPv6 address.
|
||||
|
@ -147,13 +136,11 @@ jint IPv6_supported()
|
|||
char *bufP;
|
||||
|
||||
if (fP == NULL) {
|
||||
close(fd);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
bufP = fgets(buf, sizeof(buf), fP);
|
||||
fclose(fP);
|
||||
if (bufP == NULL) {
|
||||
close(fd);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +151,6 @@ jint IPv6_supported()
|
|||
* we should also check if the APIs are available.
|
||||
*/
|
||||
ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton");
|
||||
close(fd);
|
||||
if (ipv6_fn == NULL ) {
|
||||
return JNI_FALSE;
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -38,10 +38,6 @@
|
|||
|
||||
#include "sun_nio_ch_InheritedChannel.h"
|
||||
|
||||
static int toInetFamily(SOCKETADDRESS *sa) {
|
||||
return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla)
|
||||
{
|
||||
|
@ -58,9 +54,7 @@ Java_sun_nio_ch_InheritedChannel_inetPeerAddress0(JNIEnv *env, jclass cla, jint
|
|||
jint remote_port;
|
||||
|
||||
if (getpeername(fd, &sa.sa, &len) == 0) {
|
||||
if (toInetFamily(&sa)) {
|
||||
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
|
||||
}
|
||||
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
|
||||
}
|
||||
|
||||
return remote_ia;
|
||||
|
@ -89,9 +83,7 @@ Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
|
|||
jint remote_port = -1;
|
||||
|
||||
if (getpeername(fd, (struct sockaddr *)&sa.sa, &len) == 0) {
|
||||
if (toInetFamily(&sa)) {
|
||||
NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
|
||||
}
|
||||
NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
|
||||
}
|
||||
|
||||
return remote_port;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue