Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

FreeBSD/socket: user cookie socket option support. #38

Open
wants to merge 2 commits into
base: bsd-port
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/jdk.net/bsd/classes/jdk/net/BsdSocketOptions.java
Expand Up @@ -76,6 +76,7 @@ int getTcpKeepAliveIntvl(int fd) throws SocketException {
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;
private static native boolean keepAliveOptionsSupported0();
public static native void setUserCookie(int fd, int cookie) throws SocketException;
static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("extnet");
Expand Down
14 changes: 14 additions & 0 deletions src/jdk.net/bsd/native/libextnet/BsdSocketOptions.c
Expand Up @@ -182,3 +182,17 @@ JNIEXPORT jint JNICALL Java_jdk_net_BsdSocketOptions_getTcpKeepAliveIntvl0
return optval;
#endif
}

JNIEXPORT void JNICALL Java_jdk_net_BsdSocketOptions_setUserCookie
(JNIEnv *env, jobject unused, jint fd, jint cookie) {
#ifndef __FreeBSD__
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
"unsupported socket option");
#else
jint rv;
const uint32_t optval = (const uint32_t)cookie;
socklen_t sz = sizeof (optval);
rv = setsockopt(fd, IPPROTO_TCP, SO_USER_COOKIE, &optval, sz);
handleError(env, rv, "set option SO_USER_COOKIE failed");
#endif
}