mirror of
https://github.com/RGBCube/serenity
synced 2025-07-08 14:47:35 +00:00
Kernel: Properly support the SO_BROADCAST socket option
POSIX requires that broadcast sends will only be allowed if the SO_BROADCAST socket option was set on the socket. Also, broadcast sends to protocols that do not support broadcast (like TCP), should always fail.
This commit is contained in:
parent
8b2beb2ebe
commit
545f4b6cc1
7 changed files with 36 additions and 6 deletions
|
@ -130,6 +130,12 @@ ErrorOr<void> Socket::setsockopt(int level, int option, Userspace<void const*> u
|
|||
case SO_REUSEADDR:
|
||||
dbgln("FIXME: SO_REUSEADDR requested, but not implemented.");
|
||||
return {};
|
||||
case SO_BROADCAST: {
|
||||
if (user_value_size != sizeof(int))
|
||||
return EINVAL;
|
||||
m_broadcast_allowed = TRY(copy_typed_from_user(static_ptr_cast<int const*>(user_value))) != 0;
|
||||
return {};
|
||||
}
|
||||
default:
|
||||
dbgln("setsockopt({}) at SOL_SOCKET not implemented.", option);
|
||||
return ENOPROTOOPT;
|
||||
|
@ -235,6 +241,14 @@ ErrorOr<void> Socket::getsockopt(OpenFileDescription&, int level, int option, Us
|
|||
size = sizeof(routing_disabled);
|
||||
return copy_to_user(value_size, &size);
|
||||
}
|
||||
case SO_BROADCAST: {
|
||||
int broadcast_allowed = m_broadcast_allowed ? 1 : 0;
|
||||
if (size < sizeof(broadcast_allowed))
|
||||
return EINVAL;
|
||||
TRY(copy_to_user(static_ptr_cast<int*>(value), &broadcast_allowed));
|
||||
size = sizeof(broadcast_allowed);
|
||||
return copy_to_user(value_size, &size);
|
||||
}
|
||||
default:
|
||||
dbgln("getsockopt({}) at SOL_SOCKET not implemented.", option);
|
||||
return ENOPROTOOPT;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue