< prev index next >

src/java.base/windows/native/libnet/Inet4AddressImpl.c

Print this page
rev 14618 : 8158023: SocketExceptions contain too little information sometimes
   1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 216 
 217         if (IS_NULL(ret)) {
 218             goto cleanupAndReturn;
 219         }
 220 
 221         addrp = (struct in_addr **) hp->h_addr_list;
 222         i = 0;
 223         while (*addrp != (struct in_addr *) 0) {
 224           jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
 225           if (IS_NULL(iaObj)) {
 226             ret = NULL;
 227             goto cleanupAndReturn;
 228           }
 229           setInetAddress_addr(env, iaObj, ntohl((*addrp)->s_addr));
 230           setInetAddress_hostName(env, iaObj, host);
 231           (*env)->SetObjectArrayElement(env, ret, i, iaObj);
 232           addrp++;
 233           i++;
 234         }
 235     } else if (WSAGetLastError() == WSATRY_AGAIN) {
 236         NET_ThrowByNameWithLastError(env,
 237                                      JNU_JAVANETPKG "UnknownHostException",
 238                                      hostname);
 239     } else {
 240         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
 241     }
 242 
 243 cleanupAndReturn:
 244     JNU_ReleaseStringPlatformChars(env, host, hostname);
 245     return ret;
 246 }
 247 
 248 /*
 249  * Class:     java_net_Inet4AddressImpl
 250  * Method:    getHostByAddr
 251  * Signature: (I)Ljava/lang/String;
 252  */
 253 JNIEXPORT jstring JNICALL
 254 Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
 255                                             jbyteArray addrArray) {
 256     struct hostent *hp;


   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 216 
 217         if (IS_NULL(ret)) {
 218             goto cleanupAndReturn;
 219         }
 220 
 221         addrp = (struct in_addr **) hp->h_addr_list;
 222         i = 0;
 223         while (*addrp != (struct in_addr *) 0) {
 224           jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
 225           if (IS_NULL(iaObj)) {
 226             ret = NULL;
 227             goto cleanupAndReturn;
 228           }
 229           setInetAddress_addr(env, iaObj, ntohl((*addrp)->s_addr));
 230           setInetAddress_hostName(env, iaObj, host);
 231           (*env)->SetObjectArrayElement(env, ret, i, iaObj);
 232           addrp++;
 233           i++;
 234         }
 235     } else if (WSAGetLastError() == WSATRY_AGAIN) {
 236         JNU_ThrowByNameWithLastError(env,
 237                                      JNU_JAVANETPKG "UnknownHostException",
 238                                      hostname);
 239     } else {
 240         JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
 241     }
 242 
 243 cleanupAndReturn:
 244     JNU_ReleaseStringPlatformChars(env, host, hostname);
 245     return ret;
 246 }
 247 
 248 /*
 249  * Class:     java_net_Inet4AddressImpl
 250  * Method:    getHostByAddr
 251  * Signature: (I)Ljava/lang/String;
 252  */
 253 JNIEXPORT jstring JNICALL
 254 Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
 255                                             jbyteArray addrArray) {
 256     struct hostent *hp;


< prev index next >