112 } |
112 } |
113 |
113 |
114 static jclass ni_iacls; |
114 static jclass ni_iacls; |
115 static jclass ni_ia4cls; |
115 static jclass ni_ia4cls; |
116 static jmethodID ni_ia4ctrID; |
116 static jmethodID ni_ia4ctrID; |
117 static jfieldID ni_iaaddressID; |
|
118 static jfieldID ni_iahostID; |
|
119 static jfieldID ni_iafamilyID; |
|
120 static int initialized = 0; |
117 static int initialized = 0; |
121 |
118 |
122 /* |
119 /* |
123 * Find an internet address for a given hostname. Not this this |
120 * Find an internet address for a given hostname. Not this this |
124 * code only works for addresses of type INET. The translation |
121 * code only works for addresses of type INET. The translation |
147 ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); |
144 ni_iacls = (*env)->FindClass(env, "java/net/InetAddress"); |
148 ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); |
145 ni_iacls = (*env)->NewGlobalRef(env, ni_iacls); |
149 ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); |
146 ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address"); |
150 ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); |
147 ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls); |
151 ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); |
148 ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V"); |
152 ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I"); |
|
153 ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I"); |
|
154 ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;"); |
|
155 initialized = 1; |
149 initialized = 1; |
156 } |
150 } |
157 |
151 |
158 if (IS_NULL(host)) { |
152 if (IS_NULL(host)) { |
159 JNU_ThrowNullPointerException(env, "host argument"); |
153 JNU_ThrowNullPointerException(env, "host argument"); |
206 iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); |
200 iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); |
207 if (IS_NULL(iaObj)) { |
201 if (IS_NULL(iaObj)) { |
208 ret = NULL; |
202 ret = NULL; |
209 goto cleanupAndReturn; |
203 goto cleanupAndReturn; |
210 } |
204 } |
211 (*env)->SetIntField(env, iaObj, ni_iaaddressID, |
205 setInetAddress_addr(env, iaObj, ntohl(address)); |
212 ntohl(address)); |
|
213 (*env)->SetObjectArrayElement(env, ret, 0, iaObj); |
206 (*env)->SetObjectArrayElement(env, ret, 0, iaObj); |
214 JNU_ReleaseStringPlatformChars(env, host, hostname); |
207 JNU_ReleaseStringPlatformChars(env, host, hostname); |
215 return ret; |
208 return ret; |
216 } |
209 } |
217 |
210 |
240 jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); |
233 jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); |
241 if (IS_NULL(iaObj)) { |
234 if (IS_NULL(iaObj)) { |
242 ret = NULL; |
235 ret = NULL; |
243 goto cleanupAndReturn; |
236 goto cleanupAndReturn; |
244 } |
237 } |
245 (*env)->SetIntField(env, iaObj, ni_iaaddressID, |
238 setInetAddress_addr(env, iaObj, ntohl((*addrp)->s_addr)); |
246 ntohl((*addrp)->s_addr)); |
239 setInetAddress_hostName(env, iaObj, host); |
247 (*env)->SetObjectField(env, iaObj, ni_iahostID, host); |
|
248 (*env)->SetObjectArrayElement(env, ret, i, iaObj); |
240 (*env)->SetObjectArrayElement(env, ret, i, iaObj); |
249 addrp++; |
241 addrp++; |
250 i++; |
242 i++; |
251 } |
243 } |
252 } else { |
244 } else { |