Kernel: Implement the SO_ACCEPTCONN SOL_SOCKET-level option

This commit is contained in:
Idan Horowitz 2021-12-02 00:52:12 +02:00 committed by Andreas Kling
parent a0e2fedc20
commit 641498954f
Notes: sideshowbarker 2024-07-17 23:10:35 +09:00
2 changed files with 10 additions and 0 deletions

View file

@ -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,

View file

@ -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;