8244202: Implementation of JEP 418: Internet-Address Resolution SPI

Co-authored-by: Chris Hegarty <chegar@openjdk.org>
Co-authored-by: Daniel Fuchs <dfuchs@openjdk.org>
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Reviewed-by: dfuchs, alanb, michaelm, chegar
This commit is contained in:
Aleksei Efimov 2021-11-11 14:33:58 +00:00
parent c29cab8ab4
commit 2ca4ff87b7
56 changed files with 2986 additions and 293 deletions

View file

@ -25,10 +25,9 @@
package java.net;
import java.io.IOException;
import java.net.spi.InetAddressResolver.LookupPolicy;
import static java.net.InetAddress.IPv6;
import static java.net.InetAddress.PREFER_IPV6_VALUE;
import static java.net.InetAddress.PREFER_SYSTEM_VALUE;
import static java.net.InetAddress.PLATFORM_LOOKUP_POLICY;
/*
* Package private implementation of InetAddressImpl for dual
@ -48,8 +47,13 @@ final class Inet6AddressImpl implements InetAddressImpl {
public native String getLocalHostName() throws UnknownHostException;
public native InetAddress[] lookupAllHostAddr(String hostname)
throws UnknownHostException;
public InetAddress[] lookupAllHostAddr(String hostname, LookupPolicy lookupPolicy)
throws UnknownHostException {
return lookupAllHostAddr(hostname, lookupPolicy.characteristics());
}
private native InetAddress[] lookupAllHostAddr(String hostname, int characteristics)
throws UnknownHostException;
public native String getHostByAddr(byte[] addr) throws UnknownHostException;
@ -96,8 +100,9 @@ final class Inet6AddressImpl implements InetAddressImpl {
public synchronized InetAddress anyLocalAddress() {
if (anyLocalAddress == null) {
if (InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE) {
int flags = PLATFORM_LOOKUP_POLICY.characteristics();
if (InetAddress.ipv6AddressesFirst(flags) ||
InetAddress.systemAddressesOrder(flags)) {
anyLocalAddress = new Inet6Address();
anyLocalAddress.holder().hostName = "::";
} else {
@ -109,9 +114,9 @@ final class Inet6AddressImpl implements InetAddressImpl {
public synchronized InetAddress loopbackAddress() {
if (loopbackAddress == null) {
boolean preferIPv6Address =
InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE;
int flags = PLATFORM_LOOKUP_POLICY.characteristics();
boolean preferIPv6Address = InetAddress.ipv6AddressesFirst(flags) ||
InetAddress.systemAddressesOrder(flags);
for (int i = 0; i < 2; i++) {
InetAddress address;