From 4db1bdacb904f8b7a0fade09827be87fd516be98 Mon Sep 17 00:00:00 2001 From: Konrad Beckmann Date: Wed, 5 Feb 2020 15:40:51 +0100 Subject: [PATCH] Copy IPV6-mapped-IPV4 addresses correctly in native code (#9996) Motivation: 8dc6ad5 introduced IPV6-mapped-IPV4 address support but copied the addresses incorrectly. It copied the first 4 bytes of the ipv6 address to the address byte array at offset 12, instead of the other way around. 7a547aa implemented this correctly in netty_unix_socket.c but it seems the change should've been applied to netty_epoll_native.c as well. The current behaviour will always set the address to `0.0.0.0`. Modifications: Copy the correct bytes from the ipv6 mapped ipv4 address. I.e. copy 4 bytes at offset 12 from the native address to the byte array `addr` at offset 0. Result: When using recvmmsg with IPV6-mapped-IPV4 addresses, the address will be correctly copied to the byte array `addr` in the NativeDatagramPacket instance. --- transport-native-epoll/src/main/c/netty_epoll_native.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transport-native-epoll/src/main/c/netty_epoll_native.c b/transport-native-epoll/src/main/c/netty_epoll_native.c index a480d90d08..738b324e04 100644 --- a/transport-native-epoll/src/main/c/netty_epoll_native.c +++ b/transport-native-epoll/src/main/c/netty_epoll_native.c @@ -394,7 +394,8 @@ static jint netty_epoll_native_recvmmsg0(JNIEnv* env, jclass clazz, jint fd, jbo if (addrLen == 4) { // IPV4 mapped IPV6 address - (*env)->SetByteArrayRegion(env, address, 12, 4, (jbyte*) &ip6addr->sin6_addr.s6_addr); + jbyte* addr = (jbyte*) &ip6addr->sin6_addr.s6_addr; + (*env)->SetByteArrayRegion(env, address, 0, 4, addr + 12); } else { (*env)->SetByteArrayRegion(env, address, 0, 16, (jbyte*) &ip6addr->sin6_addr.s6_addr); }