diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2009-09-17 09:48:04 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-09-17 09:48:04 -0700 |
commit | ac00580c6651b27366d6e6962971e936d417dae3 (patch) | |
tree | c47d5b3245c650f38217eb76c7272eed0c9e2e6e /luni | |
parent | 35a3f0960b74cf78fc4956e32935f8b1015fac65 (diff) | |
parent | 34ae18788b2fec693d383510a468c8197eab7f64 (diff) | |
download | libcore-ac00580c6651b27366d6e6962971e936d417dae3.zip libcore-ac00580c6651b27366d6e6962971e936d417dae3.tar.gz libcore-ac00580c6651b27366d6e6962971e936d417dae3.tar.bz2 |
am a28e7d1a: am 1cf3dbce: Merge change 25160 into eclair
Merge commit 'a28e7d1a32d3883b5b279f5ddc8473e6bcbf6760'
* commit 'a28e7d1a32d3883b5b279f5ddc8473e6bcbf6760':
Make getHostByAddr and getHostByName return the proper object type.
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java | 29 | ||||
-rw-r--r-- | luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp | 84 |
2 files changed, 21 insertions, 92 deletions
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java index 1ec6240..70432a6 100644 --- a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java +++ b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java @@ -207,20 +207,33 @@ final class OSNetworkSystem implements INetworkSystem { static native void disconnectDatagramImpl(FileDescriptor aFD) throws SocketException; - public InetAddress getHostByAddr(byte[] addr) + public InetAddress getHostByAddr(byte[] ipAddress) throws UnknownHostException { - return getHostByAddrImpl(addr); + // BEGIN android-changed + // Wallpaper fix for http://b/1851257. This is a layering violation, + // but at least the method has the right return type. + // TODO: Fix the socket code to remove this method altogether. + return InetAddress.getByAddress(ipAddress); + // END android-changed } - static native InetAddress getHostByAddrImpl(byte[] addr) - throws UnknownHostException; + // BEGIN android-removed + // static native InetAddress getHostByAddrImpl(byte[] addr) + // throws UnknownHostException; + // END android-removed - public InetAddress getHostByName(String addr, + // BEGIN android-removed + public InetAddress getHostByName(String hostName, boolean preferIPv6Addresses) throws UnknownHostException { - return getHostByNameImpl(addr, preferIPv6Addresses); + // BEGIN android-changed + // Wallpaper fix for http://b/1851257. + return InetAddress.getByName(hostName); + // END android-changed } - static native InetAddress getHostByNameImpl(String addr, - boolean preferIPv6Addresses) throws UnknownHostException; + // BEGIN android-removed + // static native InetAddress getHostByNameImpl(String addr, + // boolean preferIPv6Addresses) throws UnknownHostException; + // END android-removed public int getSocketFlags() { return getSocketFlagsImpl(); diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp index a32f068..1b42a45 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp @@ -3278,88 +3278,6 @@ static void osNetworkSystem_socketCloseImpl(JNIEnv* env, jclass clazz, close(handle); } -static jobject osNetworkSystem_getHostByAddrImpl(JNIEnv* env, jclass clazz, - jbyteArray addrStr) { - // LOGD("ENTER getHostByAddrImpl"); - - if (addrStr == NULL) { - throwNullPointerException(env); - return JNI_FALSE; - } - - jstring address = (jstring)newJavaLangString(env, addrStr); - jstring result; - const char* addr = env->GetStringUTFChars(address, NULL); - - struct hostent* ent = gethostbyaddr(addr, strlen(addr), AF_INET); - - if (ent != NULL && ent->h_name != NULL) { - result = env->NewStringUTF(ent->h_name); - } else { - result = NULL; - } - - env->ReleaseStringUTFChars(address, addr); - - return result; -} - -static jobject osNetworkSystem_getHostByNameImpl(JNIEnv* env, jclass clazz, - jstring nameStr, jboolean preferIPv6Addresses) { - // LOGD("ENTER getHostByNameImpl"); - - if (nameStr == NULL) { - throwNullPointerException(env); - return NULL; - } - - const char* name = env->GetStringUTFChars(nameStr, NULL); - - if (useAdbNetworking) { - - union { - struct in_addr a; - jbyte j[4]; - } outaddr; - - // LOGD("ADB networking: +gethostbyname '%s'", name); - int err; - err = adb_networking_gethostbyname(name, &(outaddr.a)); - - env->ReleaseStringUTFChars(nameStr, name); -#if 0 - LOGD("ADB networking: -gethostbyname err %d addr 0x%08x %u.%u.%u.%u", - err, (unsigned int)outaddr.a.s_addr, - outaddr.j[0],outaddr.j[1], - outaddr.j[2],outaddr.j[3]); -#endif - - if (err < 0) { - return NULL; - } else { - jbyteArray addr = env->NewByteArray(4); - env->SetByteArrayRegion(addr, 0, 4, outaddr.j); - return addr; - } - } else { - - // normal case...no adb networking - struct hostent* ent = gethostbyname(name); - - env->ReleaseStringUTFChars(nameStr, name); - - if (ent != NULL && ent->h_length > 0) { - jbyteArray addr = env->NewByteArray(4); - jbyte v[4]; - memcpy(v, ent->h_addr, 4); - env->SetByteArrayRegion(addr, 0, 4, v); - return addr; - } else { - return NULL; - } - } -} - static void osNetworkSystem_setInetAddressImpl(JNIEnv* env, jobject obj, jobject sender, jbyteArray address) { // LOGD("ENTER setInetAddressImpl"); @@ -3675,8 +3593,6 @@ static JNINativeMethod gMethods[] = { { "setSocketOptionImpl", "(Ljava/io/FileDescriptor;ILjava/lang/Object;)V", (void*) osNetworkSystem_setSocketOptionImpl }, { "getSocketFlagsImpl", "()I", (void*) osNetworkSystem_getSocketFlagsImpl }, { "socketCloseImpl", "(Ljava/io/FileDescriptor;)V", (void*) osNetworkSystem_socketCloseImpl }, - { "getHostByAddrImpl", "([B)Ljava/net/InetAddress;", (void*) osNetworkSystem_getHostByAddrImpl }, - { "getHostByNameImpl", "(Ljava/lang/String;Z)Ljava/net/InetAddress;", (void*) osNetworkSystem_getHostByNameImpl }, { "setInetAddressImpl", "(Ljava/net/InetAddress;[B)V", (void*) osNetworkSystem_setInetAddressImpl }, { "inheritedChannelImpl", "()Ljava/nio/channels/Channel;", (void*) osNetworkSystem_inheritedChannelImpl }, }; |