diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-09-11 19:38:05 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-12-16 22:21:35 +0330 |
commit | 3da0c072f40d1a93a295e07766355f9278941e13 (patch) | |
tree | 6a23f74ca2de815b0482ecd7fbdfe86c83ad085d /Kernel/Net/IPv4Socket.cpp | |
parent | e4a1bc154266afe45e34df7c2d22cdc97639303d (diff) | |
download | serenity-3da0c072f40d1a93a295e07766355f9278941e13.zip |
Kernel: Return the correct result for FIONREAD on datagram sockets
Before this commit, we only checked the receive buffer on the socket,
which is unused on datagram streams. Now we return the actual size of
the datagram without the protocol headers, which required the protocol
to tell us what the size of the payload is.
Diffstat (limited to 'Kernel/Net/IPv4Socket.cpp')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index fb0a19052a..17d1e07300 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -774,7 +774,15 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac return ioctl_arp(); case FIONREAD: { - int readable = m_receive_buffer->immediately_readable(); + int readable = 0; + if (buffer_mode() == BufferMode::Bytes) { + readable = static_cast<int>(m_receive_buffer->immediately_readable()); + } else { + if (m_receive_queue.size() != 0u) { + readable = static_cast<int>(TRY(protocol_size(m_receive_queue.first().data->bytes()))); + } + } + return copy_to_user(static_ptr_cast<int*>(arg), &readable); } } |