Print this page


Split Close
Expand all
Collapse all
          --- old/src/solaris/native/java/net/Inet6AddressImpl.c
          +++ new/src/solaris/native/java/net/Inet6AddressImpl.c
↓ open down ↓ 104 lines elided ↑ open up ↑
 105  105  
 106  106                  (*freeaddrinfo_ptr)(res);
 107  107              }
 108  108          }
 109  109  #endif /* AF_INET6 */
 110  110  #endif /* __linux__ */
 111  111      }
 112  112      return (*env)->NewStringUTF(env, hostname);
 113  113  }
 114  114  
 115      -static jclass ni_iacls;
 116      -static jclass ni_ia4cls;
 117      -static jclass ni_ia6cls;
 118      -static jmethodID ni_ia4ctrID;
 119      -static jmethodID ni_ia6ctrID;
 120      -static jfieldID ni_iaaddressID;
 121      -static jfieldID ni_iahostID;
 122      -static jfieldID ni_iafamilyID;
 123      -static jfieldID ni_ia6ipaddressID;
 124      -static int initialized = 0;
 125      -
 126  115  /*
 127  116   * Find an internet address for a given hostname.  Not this this
 128  117   * code only works for addresses of type INET. The translation
 129  118   * of %d.%d.%d.%d to an address (int) occurs in java now, so the
 130  119   * String "host" shouldn't *ever* be a %d.%d.%d.%d string
 131  120   *
 132  121   * Class:     java_net_Inet6AddressImpl
 133  122   * Method:    lookupAllHostAddr
 134  123   * Signature: (Ljava/lang/String;)[[B
 135  124   */
↓ open down ↓ 4 lines elided ↑ open up ↑
 140  129      const char *hostname;
 141  130      jobjectArray ret = 0;
 142  131      int retLen = 0;
 143  132      jboolean preferIPv6Address;
 144  133  
 145  134      int error=0;
 146  135  #ifdef AF_INET6
 147  136      struct addrinfo hints, *res, *resNew = NULL;
 148  137  #endif /* AF_INET6 */
 149  138  
 150      -    if (!initialized) {
 151      -      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
 152      -      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
 153      -      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
 154      -      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
 155      -      ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
 156      -      ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
 157      -      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
 158      -      ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
 159      -      ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
 160      -      ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
 161      -      ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;");
 162      -      ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
 163      -      initialized = 1;
 164      -    }
      139 +    init(env);
 165  140  
 166  141      if (IS_NULL(host)) {
 167  142          JNU_ThrowNullPointerException(env, "host is null");
 168  143          return 0;
 169  144      }
 170  145      hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
 171  146      CHECK_NULL_RETURN(hostname, NULL);
 172  147  
 173  148  #ifdef AF_INET6
 174  149      if (NET_addrtransAvailable()) {
 175      -        static jfieldID ia_preferIPv6AddressID;
 176      -        if (ia_preferIPv6AddressID == NULL) {
 177      -            jclass c = (*env)->FindClass(env,"java/net/InetAddress");
 178      -            if (c)  {
 179      -                ia_preferIPv6AddressID =
 180      -                    (*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z");
 181      -            }
 182      -            if (ia_preferIPv6AddressID == NULL) {
 183      -                JNU_ReleaseStringPlatformChars(env, host, hostname);
 184      -                return NULL;
 185      -            }
 186      -        }
 187  150          /* get the address preference */
 188  151          preferIPv6Address
 189  152              = (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
 190  153  
 191  154          /* Try once, with our static buffer. */
 192  155          bzero(&hints, sizeof(hints));
 193  156          hints.ai_flags = AI_CANONNAME;
 194  157          hints.ai_family = AF_UNSPEC;
 195  158  
 196  159  #ifdef __solaris__
↓ open down ↓ 86 lines elided ↑ open up ↑
 283  246                          inetCount ++;
 284  247                      } else if (iterator->ai_family == AF_INET6) {
 285  248                          inet6Count ++;
 286  249                      }
 287  250                  }
 288  251                  iterator = iterator->ai_next;
 289  252              }
 290  253              retLen = i;
 291  254              iterator = resNew;
 292  255  
 293      -            ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
      256 +            ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
 294  257  
 295  258              if (IS_NULL(ret)) {
 296  259                  /* we may have memory to free at the end of this */
 297  260                  goto cleanupAndReturn;
 298  261              }
 299  262  
 300  263              if (preferIPv6Address) {
 301  264                  /* AF_INET addresses will be offset by inet6Count */
 302  265                  inetIndex = inet6Count;
 303  266                  inet6Index = 0;
 304  267              } else {
 305  268                  /* AF_INET6 addresses will be offset by inetCount */
 306  269                  inetIndex = 0;
 307  270                  inet6Index = inetCount;
 308  271              }
 309  272  
 310  273              while (iterator != NULL) {
 311  274                if (iterator->ai_family == AF_INET) {
 312      -                jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
      275 +                jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
 313  276                  if (IS_NULL(iaObj)) {
 314  277                    ret = NULL;
 315  278                    goto cleanupAndReturn;
 316  279                  }
 317      -                (*env)->SetIntField(env, iaObj, ni_iaaddressID,
      280 +                (*env)->SetIntField(env, iaObj, ia_addressID,
 318  281                                      ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
 319      -                (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
      282 +                (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
 320  283                  (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
 321  284                  inetIndex++;
 322  285                } else if (iterator->ai_family == AF_INET6) {
 323  286                  jint scope = 0;
 324  287                  jbyteArray ipaddress;
 325  288  
 326      -                jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
      289 +                jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
 327  290                  if (IS_NULL(iaObj)) {
 328  291                    ret = NULL;
 329  292                    goto cleanupAndReturn;
 330  293                  }
 331  294                  ipaddress = (*env)->NewByteArray(env, 16);
 332  295                  if (IS_NULL(ipaddress)) {
 333  296                    ret = NULL;
 334  297                    goto cleanupAndReturn;
 335  298                  }
 336  299                  (*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
↓ open down ↓ 2 lines elided ↑ open up ↑
 339  302                  if (!kernelIsV22()) {
 340  303                    scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
 341  304                  }
 342  305  #else
 343  306                  scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
 344  307  #endif
 345  308                  if (scope != 0) { /* zero is default value, no need to set */
 346  309                    (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
 347  310                    (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
 348  311                  }
 349      -                (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
 350      -                (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
      312 +                (*env)->SetObjectField(env, iaObj, ia6_ipaddressID, ipaddress);
      313 +                (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
 351  314                  (*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
 352  315                  inet6Index++;
 353  316                }
 354  317                iterator = iterator->ai_next;
 355  318              }
 356  319          }
 357  320      }
 358  321  
 359  322  cleanupAndReturn:
 360  323      {
↓ open down ↓ 347 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX