diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-12-02 00:52:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-05 12:53:29 +0100 |
commit | 641498954fd79772de365435ed24ef6c79cbee48 (patch) | |
tree | 224cf412e52cd7456729b50cac02a546f8dc2762 /Kernel | |
parent | a0e2fedc20da72930e68f4304d829594269b04f9 (diff) | |
download | serenity-641498954fd79772de365435ed24ef6c79cbee48.zip |
Kernel: Implement the SO_ACCEPTCONN SOL_SOCKET-level option
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/API/POSIX/sys/socket.h | 2 | ||||
-rw-r--r-- | Kernel/Net/Socket.cpp | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Kernel/API/POSIX/sys/socket.h b/Kernel/API/POSIX/sys/socket.h index ce0efe8a58..c32dc92c34 100644 --- a/Kernel/API/POSIX/sys/socket.h +++ b/Kernel/API/POSIX/sys/socket.h @@ -108,6 +108,7 @@ enum { SO_TIMESTAMP, SO_BROADCAST, SO_LINGER, + SO_ACCEPTCONN, }; #define SO_RCVTIMEO SO_RCVTIMEO #define SO_SNDTIMEO SO_SNDTIMEO @@ -123,6 +124,7 @@ enum { #define SO_SNDBUF SO_SNDBUF #define SO_RCVBUF SO_RCVBUF #define SO_LINGER SO_LINGER +#define SO_ACCEPTCONN SO_ACCEPTCONN enum { SCM_TIMESTAMP, diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 6b0f753ca1..da99bfd724 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -208,6 +208,14 @@ ErrorOr<void> Socket::getsockopt(OpenFileDescription&, int level, int option, Us TRY(memset_user(value.unsafe_userspace_ptr(), 0, sizeof(int))); size = sizeof(int); return copy_to_user(value_size, &size); + case SO_ACCEPTCONN: { + int accepting_connections = (m_role == Role::Listener) ? 1 : 0; + if (size < sizeof(accepting_connections)) + return EINVAL; + TRY(copy_to_user(static_ptr_cast<int*>(value), &accepting_connections)); + size = sizeof(accepting_connections); + return copy_to_user(value_size, &size); + } default: dbgln("setsockopt({}) at SOL_SOCKET not implemented.", option); return ENOPROTOOPT; |