summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammad Zahalqa <m@tryfinally.com>2020-08-08 16:02:28 +0300
committerAndreas Kling <kling@serenityos.org>2020-08-09 21:10:01 +0200
commit043d548b391147a00986de797a4a57ffb5e58673 (patch)
treed1bcd5121c007626b9c4984a903b3933b41dc562
parentd9470bdae763e18291875d1e55dfdc2e608595c0 (diff)
downloadserenity-043d548b391147a00986de797a4a57ffb5e58673.zip
LibCore: fix UDP Server receive to trim buffer to actuall bytes receiveed
-rw-r--r--Libraries/LibCore/UDPServer.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Libraries/LibCore/UDPServer.cpp b/Libraries/LibCore/UDPServer.cpp
index 2b5b466074..6683b956f2 100644
--- a/Libraries/LibCore/UDPServer.cpp
+++ b/Libraries/LibCore/UDPServer.cpp
@@ -79,13 +79,15 @@ bool UDPServer::bind(const IPv4Address& address, u16 port)
ByteBuffer UDPServer::receive(size_t size, sockaddr_in& in)
{
- auto buf = ByteBuffer::create_zeroed(size);
+ auto buf = ByteBuffer::create_uninitialized(size);
socklen_t in_len = sizeof(in);
ssize_t rlen = ::recvfrom(m_fd, buf.data(), size, 0, (sockaddr*)&in, &in_len);
if (rlen < 0) {
dbg() << "recvfrom: " << strerror(errno);
return {};
}
+
+ buf.trim(rlen);
return buf;
}