Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8339414

Fix JDK-8202369 incorrect backport

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 8u192
    • core-libs

      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);
      }
      ```

            zxie Zhaokun Xie
            zxie Zhaokun Xie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: