本来はCプログラムで書く 最近のJavaでは、FFMでシステムプログラミングが可能 #include <sys/socket.h> ... struct msghdr msg = {0}; msg.msg_iov = &io; if (recvmsg(socfd, &msg, 0) < 0) printf("Failed to receive message¥n"); private static final MemoryLayout MSGHDR_LAYOUT = MemoryLayout.structLayout( ValueLayout.ADDRESS.withName("msg_name"), ValueLayout.JAVA_INT.withName("msg_namelen"), MemoryLayout.paddingLayout(4), ValueLayout.ADDRESS.withName("msg_iov"), ... MemorySegment msg = Arena.global().allocate(MSGHDR_LAYOUT); msg.fill((byte)0); msg.set(ADDRESS, MSGHDR_LAYOUT.byteOffset(PathElement.groupElement("msg_iov")), io); if ( recvmsgHandle.invokeExact(sockfd, msg, 0) < 0) { throw new Exception("Failed to receive message"); Cプログラム pure Javaプログラム https://gist.github.com/kazumura/aae857e754cfbc30283aa688d52f1ac7 39