src/solaris/native/java/net/Inet6AddressImpl.c
Print this page
@@ -110,21 +110,10 @@
#endif /* __linux__ */
}
return (*env)->NewStringUTF(env, hostname);
}
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jclass ni_ia6cls;
-static jmethodID ni_ia4ctrID;
-static jmethodID ni_ia6ctrID;
-static jfieldID ni_iaaddressID;
-static jfieldID ni_iahostID;
-static jfieldID ni_iafamilyID;
-static jfieldID ni_ia6ipaddressID;
-static int initialized = 0;
-
/*
* Find an internet address for a given hostname. Not this this
* code only works for addresses of type INET. The translation
* of %d.%d.%d.%d to an address (int) occurs in java now, so the
* String "host" shouldn't *ever* be a %d.%d.%d.%d string
@@ -145,25 +134,11 @@
int error=0;
#ifdef AF_INET6
struct addrinfo hints, *res, *resNew = NULL;
#endif /* AF_INET6 */
- if (!initialized) {
- ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
- ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
- ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
- ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
- ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
- ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
- ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
- ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
- ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
- ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
- ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;");
- ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
- initialized = 1;
- }
+ init(env);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
}
@@ -170,22 +145,10 @@
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
#ifdef AF_INET6
if (NET_addrtransAvailable()) {
- static jfieldID ia_preferIPv6AddressID;
- if (ia_preferIPv6AddressID == NULL) {
- jclass c = (*env)->FindClass(env,"java/net/InetAddress");
- if (c) {
- ia_preferIPv6AddressID =
- (*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z");
- }
- if (ia_preferIPv6AddressID == NULL) {
- JNU_ReleaseStringPlatformChars(env, host, hostname);
- return NULL;
- }
- }
/* get the address preference */
preferIPv6Address
= (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
/* Try once, with our static buffer. */
@@ -288,11 +251,11 @@
iterator = iterator->ai_next;
}
retLen = i;
iterator = resNew;
- ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+ ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
@@ -307,25 +270,25 @@
inet6Index = inetCount;
}
while (iterator != NULL) {
if (iterator->ai_family == AF_INET) {
- jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+ jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
- (*env)->SetIntField(env, iaObj, ni_iaaddressID,
+ (*env)->SetIntField(env, iaObj, ia_addressID,
ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
- (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
+ (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
inetIndex++;
} else if (iterator->ai_family == AF_INET6) {
jint scope = 0;
jbyteArray ipaddress;
- jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+ jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
ipaddress = (*env)->NewByteArray(env, 16);
@@ -344,12 +307,12 @@
#endif
if (scope != 0) { /* zero is default value, no need to set */
(*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
(*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
}
- (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
- (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
+ (*env)->SetObjectField(env, iaObj, ia6_ipaddressID, ipaddress);
+ (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
(*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
inet6Index++;
}
iterator = iterator->ai_next;
}