src/windows/native/java/net/Inet4AddressImpl.c
Print this page
@@ -109,18 +109,10 @@
strcpy(hostname, "localhost");
}
return JNU_NewStringPlatform(env, hostname);
}
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jmethodID ni_ia4ctrID;
-static jfieldID ni_iaaddressID;
-static jfieldID ni_iahostID;
-static jfieldID ni_iafamilyID;
-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 be a %d.%d.%d.%d string. The only
@@ -141,21 +133,11 @@
struct hostent *hp;
unsigned int addr[4];
jobjectArray ret = NULL;
- 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_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<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;");
- initialized = 1;
- }
+ init(env);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host argument");
return NULL;
}
@@ -195,22 +177,22 @@
address = (addr[3]<<24) & 0xff000000;
address |= (addr[2]<<16) & 0xff0000;
address |= (addr[1]<<8) & 0xff00;
address |= addr[0];
- ret = (*env)->NewObjectArray(env, 1, ni_iacls, NULL);
+ ret = (*env)->NewObjectArray(env, 1, ia_class, NULL);
if (IS_NULL(ret)) {
goto cleanupAndReturn;
}
- iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+ 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(address));
(*env)->SetObjectArrayElement(env, ret, 0, iaObj);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return ret;
}
@@ -226,27 +208,27 @@
while (*addrp != (struct in_addr *) 0) {
i++;
addrp++;
}
- ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL);
+ ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
if (IS_NULL(ret)) {
goto cleanupAndReturn;
}
addrp = (struct in_addr **) hp->h_addr_list;
i = 0;
while (*addrp != (struct in_addr *) 0) {
- 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((*addrp)->s_addr));
- (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
+ (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
(*env)->SetObjectArrayElement(env, ret, i, iaObj);
addrp++;
i++;
}
} else {