src/windows/native/java/net/Inet4AddressImpl.c

Print this page




 125  * we fallback to a lookup.
 126  *
 127  * Class:     java_net_Inet4AddressImpl
 128  * Method:    lookupAllHostAddr
 129  * Signature: (Ljava/lang/String;)[[B
 130  *
 131  * This is almost shared code
 132  */
 133 
 134 JNIEXPORT jobjectArray JNICALL
 135 Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
 136                                                 jstring host) {
 137     const char *hostname;
 138     struct hostent *hp;
 139     unsigned int addr[4];
 140 
 141     jobjectArray ret = NULL;
 142 
 143     if (!initialized) {
 144       ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");

 145       ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);

 146       ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");

 147       ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);

 148       ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");

 149       initialized = 1;
 150     }
 151 
 152     if (IS_NULL(host)) {
 153         JNU_ThrowNullPointerException(env, "host argument");
 154         return NULL;
 155     }
 156     hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
 157     CHECK_NULL_RETURN(hostname, NULL);
 158 
 159     /*
 160      * The NT/2000 resolver tolerates a space in front of localhost. This
 161      * is not consistent with other implementations of gethostbyname.
 162      * In addition we must do a white space check on Solaris to avoid a
 163      * bug whereby 0.0.0.0 is returned if any host name has a white space.
 164      */
 165     if (isspace(hostname[0])) {
 166         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
 167         goto cleanupAndReturn;
 168     }




 125  * we fallback to a lookup.
 126  *
 127  * Class:     java_net_Inet4AddressImpl
 128  * Method:    lookupAllHostAddr
 129  * Signature: (Ljava/lang/String;)[[B
 130  *
 131  * This is almost shared code
 132  */
 133 
 134 JNIEXPORT jobjectArray JNICALL
 135 Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
 136                                                 jstring host) {
 137     const char *hostname;
 138     struct hostent *hp;
 139     unsigned int addr[4];
 140 
 141     jobjectArray ret = NULL;
 142 
 143     if (!initialized) {
 144       ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
 145       CHECK_NULL_RETURN(ni_iacls, NULL);
 146       ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
 147       CHECK_NULL_RETURN(ni_iacls, NULL);
 148       ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
 149       CHECK_NULL_RETURN(ni_ia4cls, NULL);
 150       ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
 151       CHECK_NULL_RETURN(ni_ia4cls, NULL);
 152       ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
 153       CHECK_NULL_RETURN(ni_ia4ctrID, NULL);
 154       initialized = 1;
 155     }
 156 
 157     if (IS_NULL(host)) {
 158         JNU_ThrowNullPointerException(env, "host argument");
 159         return NULL;
 160     }
 161     hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
 162     CHECK_NULL_RETURN(hostname, NULL);
 163 
 164     /*
 165      * The NT/2000 resolver tolerates a space in front of localhost. This
 166      * is not consistent with other implementations of gethostbyname.
 167      * In addition we must do a white space check on Solaris to avoid a
 168      * bug whereby 0.0.0.0 is returned if any host name has a white space.
 169      */
 170     if (isspace(hostname[0])) {
 171         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
 172         goto cleanupAndReturn;
 173     }