Print this page


Split Close
Expand all
Collapse all
          --- old/src/solaris/native/java/net/Inet4AddressImpl.c
          +++ new/src/solaris/native/java/net/Inet4AddressImpl.c
↓ open down ↓ 103 lines elided ↑ open up ↑
 104  104                  if ((strlen(hp->h_name) > strlen(hostname))
 105  105                      && (strncmp(hostname, hp->h_name, strlen(hostname)) == 0)
 106  106                      && (*(p + strlen(hostname)) == '.'))
 107  107                      strcpy(hostname, hp->h_name);
 108  108              }
 109  109          }
 110  110      }
 111  111      return (*env)->NewStringUTF(env, hostname);
 112  112  }
 113  113  
 114      -static jclass ni_iacls;
 115      -static jclass ni_ia4cls;
 116      -static jmethodID ni_ia4ctrID;
 117      -static jfieldID ni_iaaddressID;
 118      -static jfieldID ni_iahostID;
 119      -static jfieldID ni_iafamilyID;
 120      -static int initialized = 0;
 121      -
 122  114  /*
 123  115   * Find an internet address for a given hostname.  Note that this
 124  116   * code only works for addresses of type INET. The translation
 125  117   * of %d.%d.%d.%d to an address (int) occurs in java now, so the
 126  118   * String "host" shouldn't *ever* be a %d.%d.%d.%d string
 127  119   *
 128  120   * Class:     java_net_Inet4AddressImpl
 129  121   * Method:    lookupAllHostAddr
 130  122   * Signature: (Ljava/lang/String;)[[B
 131  123   */
↓ open down ↓ 3 lines elided ↑ open up ↑
 135  127                                                  jstring host) {
 136  128      const char *hostname;
 137  129      jobjectArray ret = 0;
 138  130      struct hostent res, *hp = 0;
 139  131      char buf[HENT_BUF_SIZE];
 140  132  
 141  133      /* temporary buffer, on the off chance we need to expand */
 142  134      char *tmp = NULL;
 143  135      int h_error=0;
 144  136  
 145      -    if (!initialized) {
 146      -      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
 147      -      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
 148      -      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
 149      -      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
 150      -      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
 151      -      ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
 152      -      ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
 153      -      ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;");
 154      -      initialized = 1;
 155      -    }
      137 +    init(env);
 156  138  
 157  139      if (IS_NULL(host)) {
 158  140          JNU_ThrowNullPointerException(env, "host is null");
 159  141          return 0;
 160  142      }
 161  143      hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
 162  144      CHECK_NULL_RETURN(hostname, NULL);
 163  145  
 164  146  #ifdef __solaris__
 165  147      /*
↓ open down ↓ 33 lines elided ↑ open up ↑
 199  181      }
 200  182      if (hp != NULL) {
 201  183          struct in_addr **addrp = (struct in_addr **) hp->h_addr_list;
 202  184          int i = 0;
 203  185  
 204  186          while (*addrp != (struct in_addr *) 0) {
 205  187              i++;
 206  188              addrp++;
 207  189          }
 208  190  
 209      -        ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL);
      191 +        ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
 210  192          if (IS_NULL(ret)) {
 211  193              /* we may have memory to free at the end of this */
 212  194              goto cleanupAndReturn;
 213  195          }
 214  196          addrp = (struct in_addr **) hp->h_addr_list;
 215  197          i = 0;
 216  198          while (*addrp) {
 217      -          jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
      199 +          jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
 218  200            if (IS_NULL(iaObj)) {
 219  201              ret = NULL;
 220  202              goto cleanupAndReturn;
 221  203            }
 222      -          (*env)->SetIntField(env, iaObj, ni_iaaddressID,
      204 +          (*env)->SetIntField(env, iaObj, ia_addressID,
 223  205                                ntohl((*addrp)->s_addr));
 224      -          (*env)->SetObjectField(env, iaObj, ni_iahostID, host);
      206 +          (*env)->SetObjectField(env, iaObj, ia_hostNameID, host);
 225  207            (*env)->SetObjectArrayElement(env, ret, i, iaObj);
 226  208            addrp++;
 227  209            i++;
 228  210          }
 229  211      } else {
 230  212          JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
 231  213                          (char *)hostname);
 232  214          ret = NULL;
 233  215      }
 234  216  
↓ open down ↓ 334 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX