src/solaris/native/java/net/Inet4AddressImpl.c
Print this page
*** 109,126 ****
}
}
return (*env)->NewStringUTF(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. Note that 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
--- 109,118 ----
*** 140,160 ****
/* temporary buffer, on the off chance we need to expand */
char *tmp = NULL;
int h_error=0;
! 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;
! }
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
}
--- 132,142 ----
/* temporary buffer, on the off chance we need to expand */
char *tmp = NULL;
int h_error=0;
! init(env);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
}
*** 204,229 ****
while (*addrp != (struct in_addr *) 0) {
i++;
addrp++;
}
! ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
addrp = (struct in_addr **) hp->h_addr_list;
i = 0;
while (*addrp) {
! jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
! (*env)->SetIntField(env, iaObj, ni_iaaddressID,
ntohl((*addrp)->s_addr));
! (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
(*env)->SetObjectArrayElement(env, ret, i, iaObj);
addrp++;
i++;
}
} else {
--- 186,211 ----
while (*addrp != (struct in_addr *) 0) {
i++;
addrp++;
}
! ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
addrp = (struct in_addr **) hp->h_addr_list;
i = 0;
while (*addrp) {
! jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
! (*env)->SetIntField(env, iaObj, ia_addressID,
ntohl((*addrp)->s_addr));
! (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
(*env)->SetObjectArrayElement(env, ret, i, iaObj);
addrp++;
i++;
}
} else {