Fix JDK-8202369 incorrect backport for 8u

XMLWordPrintable

    • b01

        JDK-8202369 backport does not modify the Java_java_net_Inet4AddressImpl_getLocalHostName method of non-BSD systems.

        ```
        /************************************************************************
         * Inet4AddressImpl
         */

        /*
         * Class: java_net_Inet4AddressImpl
         * Method: getLocalHostName
         * Signature: ()Ljava/lang/String;
         */
        JNIEXPORT jstring JNICALL
        Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
            char hostname[NI_MAXHOST+1];

            hostname[0] = '\0';
            if (JVM_GetHostName(hostname, sizeof(hostname))) {
                /* Something went wrong, maybe networking is not setup? */
                strcpy(hostname, "localhost");
            } else {
                struct addrinfo hints, *res;
                int error;

                hostname[NI_MAXHOST] = '\0';
                memset(&hints, 0, sizeof(hints));
                hints.ai_flags = AI_CANONNAME;
                hints.ai_family = AF_INET;

                error = getaddrinfo(hostname, NULL, &hints, &res);

                if (error == 0) {/* host is known to name service */
                    getnameinfo(res->ai_addr,
                                res->ai_addrlen,
                                hostname,
                                NI_MAXHOST,
                                NULL,
                                0,
                                NI_NAMEREQD);

                    /* if getnameinfo fails hostname is still the value
                       from gethostname */

                    freeaddrinfo(res);
                }
            }
            return (*env)->NewStringUTF(env, hostname);
        }
        ```

              Assignee:
              Thomas Fitzsimmons
              Reporter:
              Zhaokun Xie
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: