diff options
author | Elliott Hughes <enh@google.com> | 2011-05-26 15:11:52 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-05-26 15:11:52 -0700 |
commit | 8ecbb3f6a89983adb1a085469befc70488f4f04f (patch) | |
tree | 3948eb78ff0d4dea4dfb3b3c7c02c514d4c2e577 /luni | |
parent | 98879fb0ca920d752fce6177b6832293323e0944 (diff) | |
download | libcore-8ecbb3f6a89983adb1a085469befc70488f4f04f.zip libcore-8ecbb3f6a89983adb1a085469befc70488f4f04f.tar.gz libcore-8ecbb3f6a89983adb1a085469befc70488f4f04f.tar.bz2 |
Don't use mapped IPv4 addresses with MCAST_JOIN_GROUP.
This change is really a one-liner, but I did some cleanup too. This fixes most
of the Harmony multicast tests.
Change-Id: I37ff9c6ee6ee64de0500ef4b51638b3d3a6417ff
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/native/NetworkUtilities.cpp | 2 | ||||
-rw-r--r-- | luni/src/main/native/NetworkUtilities.h | 4 | ||||
-rw-r--r-- | luni/src/main/native/libcore_io_Posix.cpp | 19 |
3 files changed, 13 insertions, 12 deletions
diff --git a/luni/src/main/native/NetworkUtilities.cpp b/luni/src/main/native/NetworkUtilities.cpp index 1b2c11e..721ef7f 100644 --- a/luni/src/main/native/NetworkUtilities.cpp +++ b/luni/src/main/native/NetworkUtilities.cpp @@ -152,7 +152,7 @@ static bool inetAddressToSockaddr(JNIEnv* env, jobject inetAddress, int port, so return true; } -bool inetAddressToSockaddr_getnameinfo(JNIEnv* env, jobject inetAddress, int port, sockaddr_storage* ss) { +bool inetAddressToSockaddrVerbatim(JNIEnv* env, jobject inetAddress, int port, sockaddr_storage* ss) { return inetAddressToSockaddr(env, inetAddress, port, ss, false); } diff --git a/luni/src/main/native/NetworkUtilities.h b/luni/src/main/native/NetworkUtilities.h index 8b1b6f1..1ae6c53 100644 --- a/luni/src/main/native/NetworkUtilities.h +++ b/luni/src/main/native/NetworkUtilities.h @@ -29,8 +29,8 @@ bool inetAddressToSockaddr(JNIEnv* env, jobject inetAddress, int port, sockaddr_ // a sockaddr_in6 while an Inet4Address will be converted to a sockaddr_in. This is // probably only useful for getnameinfo(2), where we'll be presenting the result to // the user and the user may actually care whether the original address was pure IPv4 -// or an IPv4-mapped IPv6 address. -bool inetAddressToSockaddr_getnameinfo(JNIEnv* env, jobject inetAddress, int port, sockaddr_storage* ss); +// or an IPv4-mapped IPv6 address, and for the MCAST_JOIN_GROUP socket option. +bool inetAddressToSockaddrVerbatim(JNIEnv* env, jobject inetAddress, int port, sockaddr_storage* ss); diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp index 5b02862..28d01f1 100644 --- a/luni/src/main/native/libcore_io_Posix.cpp +++ b/luni/src/main/native/libcore_io_Posix.cpp @@ -622,7 +622,7 @@ static jstring Posix_getenv(JNIEnv* env, jobject, jstring javaName) { static jstring Posix_getnameinfo(JNIEnv* env, jobject, jobject javaAddress, jint flags) { sockaddr_storage ss; - if (!inetAddressToSockaddr_getnameinfo(env, javaAddress, 0, &ss)) { + if (!inetAddressToSockaddrVerbatim(env, javaAddress, 0, &ss)) { return NULL; } // TODO: bionic's getnameinfo(3) seems to want its length parameter to be exactly @@ -1052,19 +1052,20 @@ static void Posix_setsockoptIpMreqn(JNIEnv* env, jobject, jobject javaFd, jint l } static void Posix_setsockoptGroupReq(JNIEnv* env, jobject, jobject javaFd, jint level, jint option, jobject javaGroupReq) { - struct group_req value; + struct group_req req; + memset(&req, 0, sizeof(req)); static jfieldID grInterfaceFid = env->GetFieldID(JniConstants::structGroupReqClass, "gr_interface", "I"); - value.gr_interface = env->GetIntField(javaGroupReq, grInterfaceFid); + req.gr_interface = env->GetIntField(javaGroupReq, grInterfaceFid); // Get the IPv4 or IPv6 multicast address to join or leave. static jfieldID grGroupFid = env->GetFieldID(JniConstants::structGroupReqClass, "gr_group", "Ljava/net/InetAddress;"); ScopedLocalRef<jobject> javaGroup(env, env->GetObjectField(javaGroupReq, grGroupFid)); - if (!inetAddressToSockaddr(env, javaGroup.get(), 0, &value.gr_group)) { + if (!inetAddressToSockaddrVerbatim(env, javaGroup.get(), 0, &req.gr_group)) { return; } int fd = jniGetFDFromFileDescriptor(env, javaFd); - int rc = TEMP_FAILURE_RETRY(setsockopt(fd, level, option, &value, sizeof(value))); + int rc = TEMP_FAILURE_RETRY(setsockopt(fd, level, option, &req, sizeof(req))); if (rc == -1 && errno == EINVAL) { // Maybe we're a 32-bit binary talking to a 64-bit kernel? // glibc doesn't automatically handle this. @@ -1073,10 +1074,10 @@ static void Posix_setsockoptGroupReq(JNIEnv* env, jobject, jobject javaFd, jint uint32_t my_padding; sockaddr_storage gr_group; }; - group_req64 value64; - value64.gr_interface = value.gr_interface; - memcpy(&value64.gr_group, &value.gr_group, sizeof(value.gr_group)); - rc = TEMP_FAILURE_RETRY(setsockopt(fd, level, option, &value64, sizeof(value64))); + group_req64 req64; + req64.gr_interface = req.gr_interface; + memcpy(&req64.gr_group, &req.gr_group, sizeof(req.gr_group)); + rc = TEMP_FAILURE_RETRY(setsockopt(fd, level, option, &req64, sizeof(req64))); } throwIfMinusOne(env, "setsockopt", rc); } |