mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
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:
parent
c29cab8ab4
commit
2ca4ff87b7
56 changed files with 2986 additions and 293 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
|
@ -29,6 +29,7 @@
|
|||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "java_net_Inet6AddressImpl.h"
|
||||
#include "java_net_spi_InetAddressResolver_LookupPolicy.h"
|
||||
|
||||
/*
|
||||
* Inet6AddressImpl
|
||||
|
@ -56,7 +57,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
|
|||
*/
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
jstring host) {
|
||||
jstring host, jint characteristics) {
|
||||
jobjectArray ret = NULL;
|
||||
const char *hostname;
|
||||
int error = 0;
|
||||
|
@ -76,7 +77,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
|||
// try once, with our static buffer
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_family = lookupCharacteristicsToAddressFamily(characteristics);
|
||||
|
||||
error = getaddrinfo(hostname, NULL, &hints, &res);
|
||||
|
||||
|
@ -88,8 +89,6 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
|||
} else {
|
||||
int i = 0, inetCount = 0, inet6Count = 0, inetIndex = 0,
|
||||
inet6Index = 0, originalIndex = 0;
|
||||
int addressPreference =
|
||||
(*env)->GetStaticIntField(env, ia_class, ia_preferIPv6AddressID);
|
||||
iterator = res;
|
||||
while (iterator != NULL) {
|
||||
// skip duplicates
|
||||
|
@ -168,13 +167,13 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
|||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
if (addressPreference == java_net_InetAddress_PREFER_IPV6_VALUE) {
|
||||
if ((characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV6_FIRST) != 0) {
|
||||
inetIndex = inet6Count;
|
||||
inet6Index = 0;
|
||||
} else if (addressPreference == java_net_InetAddress_PREFER_IPV4_VALUE) {
|
||||
} else if ((characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV4_FIRST) != 0) {
|
||||
inetIndex = 0;
|
||||
inet6Index = inetCount;
|
||||
} else if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
|
||||
} else {
|
||||
inetIndex = inet6Index = originalIndex = 0;
|
||||
}
|
||||
|
||||
|
@ -217,7 +216,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
|||
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
|
||||
inet6Index++;
|
||||
}
|
||||
if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
|
||||
// Check if addresses are requested to be returned in SYSTEM order
|
||||
if (addressesInSystemOrder(characteristics)) {
|
||||
originalIndex++;
|
||||
inetIndex = inet6Index = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue