On 2017/01/15 05:36, Nick wrote: > I trying to have a ServerSocket bind to [::1]:8080 but I can't get it > working. I have OpenBSD 6.0-RELEASE and the JDK I use is jdk-1.8.0.72. > > My code is pretty simple, I create a ServerSocket in this way: > > ... = new ServerSocket(8080, 0, Inet6Address.getByName("::1")); > > But then I get the following exception: > > java.net.SocketException: Protocol family unavailable > > After many trials (I am new to OpenBSD :)), I managed to compile the > port using the with_ipv6 flavor. (I also used the native_bootstrap > flavor because I didn't manage to compile the port without it...) > > The same code gives me a new error which is: > > Exception in thread "main" java.net.SocketException: Invalid argument > at java.net.ServerSocket.createImpl(ServerSocket.java:307) > > This was already discussed here but it offered no solution, see: "java > and IPv6: java.net.SocketException: Protocol family unavailable" > > I've also tried with -Djava.net.preferIPv[4|6][Stack|Addresses] but to > no avail. There is no problem with my code as it works on other OSes > with different JDKs.
I don't think Java's v6 support has been tested much on OpenBSD, in general it's rather awkward because Java expects support for v6 sockets to work with mapped v4 addresses, which is not the case on OpenBSD. IPv6_supported() in jdk/src/solaris/native/java/net/net_util_md.c has a couple of checks to decide whether to use v6 or not; I suspect one of these may be failing. Does this help at all? Index: patches/patch-jdk_src_solaris_native_java_net_net_util_md_c =================================================================== RCS file: patches/patch-jdk_src_solaris_native_java_net_net_util_md_c diff -N patches/patch-jdk_src_solaris_native_java_net_net_util_md_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-jdk_src_solaris_native_java_net_net_util_md_c 16 Jan 2017 10:36:51 -0000 @@ -0,0 +1,30 @@ +$OpenBSD$ +--- jdk/src/solaris/native/java/net/net_util_md.c.orig Sun Jan 15 14:33:22 2017 ++++ jdk/src/solaris/native/java/net/net_util_md.c Mon Jan 16 10:36:17 2017 +@@ -316,7 +316,6 @@ jint IPv6_supported() + + #ifdef AF_INET6 + int fd; +- void *ipv6_fn; + SOCKADDR sa; + socklen_t sa_len = sizeof(sa); + +@@ -408,17 +407,8 @@ jint IPv6_supported() + + #endif /* __solaris */ + +- /* +- * OK we may have the stack available in the kernel, +- * we should also check if the APIs are available. +- */ +- ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton"); + close(fd); +- if (ipv6_fn == NULL ) { +- return JNI_FALSE; +- } else { +- return JNI_TRUE; +- } ++ return JNI_TRUE; + #endif /* AF_INET6 */ + } + #endif /* DONT_ENABLE_IPV6 */