jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c
changeset 31059 0ec777e00e2e
parent 25859 3317bb8137f4
child 41380 c27cf95dd7e6
equal deleted inserted replaced
31058:fbe6df60e104 31059:0ec777e00e2e
   119     const char *hostname;
   119     const char *hostname;
   120     jobject name;
   120     jobject name;
   121     jobjectArray ret = 0;
   121     jobjectArray ret = 0;
   122     int retLen = 0;
   122     int retLen = 0;
   123 
   123 
   124     int error=0;
   124     int getaddrinfo_error=0;
   125     struct addrinfo hints, *res, *resNew = NULL;
   125     struct addrinfo hints, *res, *resNew = NULL;
   126 
   126 
   127     initInetAddressIDs(env);
   127     initInetAddressIDs(env);
   128     JNU_CHECK_EXCEPTION_RETURN(env, NULL);
   128     JNU_CHECK_EXCEPTION_RETURN(env, NULL);
   129 
   129 
   147                         (char *)hostname);
   147                         (char *)hostname);
   148         JNU_ReleaseStringPlatformChars(env, host, hostname);
   148         JNU_ReleaseStringPlatformChars(env, host, hostname);
   149         return NULL;
   149         return NULL;
   150     }
   150     }
   151 
   151 
       
   152 
       
   153     getaddrinfo_error = getaddrinfo(hostname, NULL, &hints, &res);
       
   154 
   152 #ifdef MACOSX
   155 #ifdef MACOSX
   153     /* If we're looking up the local machine, bypass DNS lookups and get
   156     if (getaddrinfo_error) {
   154      * address from getifaddrs.
   157         // If getaddrinfo fails try getifaddrs.
   155      */
   158         ret = lookupIfLocalhost(env, hostname, JNI_FALSE);
   156     ret = lookupIfLocalhost(env, hostname, JNI_FALSE);
   159         if (ret != NULL || (*env)->ExceptionCheck(env)) {
   157     if (ret != NULL || (*env)->ExceptionCheck(env)) {
   160             JNU_ReleaseStringPlatformChars(env, host, hostname);
   158         JNU_ReleaseStringPlatformChars(env, host, hostname);
   161             return ret;
   159         return ret;
   162         }
   160     }
   163     }
   161 #endif
   164 #endif
   162 
   165 
   163     error = getaddrinfo(hostname, NULL, &hints, &res);
   166     if (getaddrinfo_error) {
   164 
       
   165     if (error) {
       
   166         /* report error */
   167         /* report error */
   167         NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
   168         NET_ThrowUnknownHostExceptionWithGaiError(
       
   169             env, hostname, getaddrinfo_error);
   168         JNU_ReleaseStringPlatformChars(env, host, hostname);
   170         JNU_ReleaseStringPlatformChars(env, host, hostname);
   169         return NULL;
   171         return NULL;
   170     } else {
   172     } else {
   171         int i = 0;
   173         int i = 0;
   172         struct addrinfo *itr, *last = NULL, *iterator = res;
   174         struct addrinfo *itr, *last = NULL, *iterator = res;