< prev index next > src/java.base/windows/native/libnet/Inet6AddressImpl.c
Print this page
/*
! * Copyright (c) 2000, 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
#include "net_util.h"
#include "java_net_InetAddress.h"
#include "java_net_Inet4AddressImpl.h"
#include "java_net_Inet6AddressImpl.h"
+ #include "java_net_spi_InetAddressResolver_LookupPolicy.h"
/*
* Inet6AddressImpl
*/
* Method: lookupAllHostAddr
* Signature: (Ljava/lang/String;)[[B
*/
JNIEXPORT jobjectArray JNICALL
Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
! jstring host) {
jobjectArray ret = NULL;
const char *hostname;
int error = 0;
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
* Method: lookupAllHostAddr
* Signature: (Ljava/lang/String;)[[B
*/
JNIEXPORT jobjectArray JNICALL
Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
! jstring host, jint characteristics) {
jobjectArray ret = NULL;
const char *hostname;
int error = 0;
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
CHECK_NULL_RETURN(hostname, NULL);
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
! hints.ai_family = AF_UNSPEC;
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error) {
// report error
CHECK_NULL_RETURN(hostname, NULL);
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
! hints.ai_family = lookupCharacteristicsToAddressFamily(characteristics);
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error) {
// report error
hostname);
goto cleanupAndReturn;
} 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
int skip = 0;
struct addrinfo *iteratorNew = resNew;
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
! if (addressPreference == java_net_InetAddress_PREFER_IPV6_VALUE) {
inetIndex = inet6Count;
inet6Index = 0;
! } else if (addressPreference == java_net_InetAddress_PREFER_IPV4_VALUE) {
inetIndex = 0;
inet6Index = inetCount;
! } else if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
inetIndex = inet6Index = originalIndex = 0;
}
iterator = resNew;
while (iterator != NULL) {
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
! if ((characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV6_FIRST) != 0) {
inetIndex = inet6Count;
inet6Index = 0;
! } else if ((characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV4_FIRST) != 0) {
inetIndex = 0;
inet6Index = inetCount;
! } else {
inetIndex = inet6Index = originalIndex = 0;
}
iterator = resNew;
while (iterator != NULL) {
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index++;
}
! if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
originalIndex++;
inetIndex = inet6Index = 0;
}
iterator = iterator->ai_next;
}
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index++;
}
! // Check if addresses are requested to be returned in SYSTEM order
+ if (addressesInSystemOrder(characteristics)) {
originalIndex++;
inetIndex = inet6Index = 0;
}
iterator = iterator->ai_next;
}
< prev index next >