mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +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) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
|
@ -39,7 +39,6 @@ jfieldID iac_addressID;
|
|||
jfieldID iac_familyID;
|
||||
jfieldID iac_hostNameID;
|
||||
jfieldID iac_origHostNameID;
|
||||
jfieldID ia_preferIPv6AddressID;
|
||||
|
||||
static int ia_initialized = 0;
|
||||
|
||||
|
@ -61,8 +60,6 @@ Java_java_net_InetAddress_init(JNIEnv *env, jclass cls) {
|
|||
CHECK_NULL(iac_class);
|
||||
ia_holderID = (*env)->GetFieldID(env, ia_class, "holder", "Ljava/net/InetAddress$InetAddressHolder;");
|
||||
CHECK_NULL(ia_holderID);
|
||||
ia_preferIPv6AddressID = (*env)->GetStaticFieldID(env, ia_class, "preferIPv6Address", "I");
|
||||
CHECK_NULL(ia_preferIPv6AddressID);
|
||||
|
||||
iac_addressID = (*env)->GetFieldID(env, iac_class, "address", "I");
|
||||
CHECK_NULL(iac_addressID);
|
||||
|
@ -75,3 +72,12 @@ Java_java_net_InetAddress_init(JNIEnv *env, jclass cls) {
|
|||
ia_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: java_net_InetAddress
|
||||
* Method: isIPv4Available
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_net_InetAddress_isIPv4Available(JNIEnv *env, jclass clazz) {
|
||||
return ipv4_available();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_spi_InetAddressResolver_LookupPolicy.h"
|
||||
|
||||
int IPv4_supported();
|
||||
int IPv6_supported();
|
||||
|
@ -332,3 +333,23 @@ in_cksum(unsigned short *addr, int len) {
|
|||
answer = ~sum;
|
||||
return (answer);
|
||||
}
|
||||
|
||||
int lookupCharacteristicsToAddressFamily(int characteristics) {
|
||||
int ipv4 = characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV4;
|
||||
int ipv6 = characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV6;
|
||||
|
||||
if (ipv4 != 0 && ipv6 == 0) {
|
||||
return AF_INET;
|
||||
}
|
||||
|
||||
if (ipv4 == 0 && ipv6 != 0) {
|
||||
return AF_INET6;
|
||||
}
|
||||
return AF_UNSPEC;
|
||||
}
|
||||
|
||||
int addressesInSystemOrder(int characteristics) {
|
||||
return (characteristics &
|
||||
(java_net_spi_InetAddressResolver_LookupPolicy_IPV4_FIRST |
|
||||
java_net_spi_InetAddressResolver_LookupPolicy_IPV6_FIRST)) == 0;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@ extern jfieldID iac_addressID;
|
|||
extern jfieldID iac_familyID;
|
||||
extern jfieldID iac_hostNameID;
|
||||
extern jfieldID iac_origHostNameID;
|
||||
extern jfieldID ia_preferIPv6AddressID;
|
||||
|
||||
JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env);
|
||||
|
||||
|
@ -192,4 +191,8 @@ unsigned short in_cksum(unsigned short *addr, int len);
|
|||
|
||||
jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
|
||||
|
||||
int lookupCharacteristicsToAddressFamily(int characteristics);
|
||||
|
||||
int addressesInSystemOrder(int characteristics);
|
||||
|
||||
#endif /* NET_UTILS_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue