Skip to content

Commit

Permalink
More bullet-proof way of detecting if ipv6 is supported or not when u…
Browse files Browse the repository at this point in the history
…sing native transport

Motivation:

We should try to bind to an ipv6 only socket before we enable ipv6 support in the native transport as it may not work due setup of the platform.

Modifications:

Try to bind to ::1 use IPV6 later on if this works

Result:

Fixes [netty#7021].
  • Loading branch information
normanmaurer committed Aug 23, 2017
1 parent b18a201 commit 7290cbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion transport-native-unix-common/src/main/c/netty_unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,16 @@ static int socket_type(JNIEnv* env) {
}
return AF_INET6;
} else {
// Explicitly try to bind to ::1 to ensure IPV6 can really be used.
// See https://github.com/netty/netty/issues/7021.
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */
int res = bind(fd, (struct sockaddr *)&addr, sizeof(addr));

close(fd);
return AF_INET6;
return res == 0 ? AF_INET6 : AF_INET;
}
}

Expand Down

0 comments on commit 7290cbc

Please sign in to comment.