1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 07:25:07 +00:00

Kernel+LibC+UserspaceEmulator: Add SO_TIMESTAMP, and cmsg definitions

When SO_TIMESTAMP is set as an option on a SOCK_DGRAM socket, then
recvmsg() will return a SCM_TIMESTAMP control message that
contains a struct timeval with the system time that was current
when the socket was received.
This commit is contained in:
Nico Weber 2020-09-16 12:32:45 -04:00 committed by Andreas Kling
parent ae5ba4074d
commit 47b3e98af8
6 changed files with 94 additions and 2 deletions

View file

@ -264,6 +264,23 @@ ssize_t Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user_msg, int
msg_flags |= MSG_TRUNC;
}
if (socket.wants_timestamp()) {
struct {
cmsghdr cmsg;
timeval timestamp;
} cmsg_timestamp;
socklen_t control_length = sizeof(cmsg_timestamp);
if (msg.msg_controllen < control_length) {
msg_flags |= MSG_CTRUNC;
} else {
cmsg_timestamp = { { control_length, SOL_SOCKET, SCM_TIMESTAMP }, timestamp };
if (!copy_to_user(msg.msg_control, &cmsg_timestamp, control_length))
return -EFAULT;
}
if (!copy_to_user(&user_msg.unsafe_userspace_ptr()->msg_controllen, &control_length))
return -EFAULT;
}
if (!copy_to_user(&user_msg.unsafe_userspace_ptr()->msg_flags, &msg_flags))
return -EFAULT;