summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2021-09-11 20:11:30 +0000
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-12-16 22:21:35 +0330
commit0cca6cef958f7742e4c232ef79311f6e5b039c1f (patch)
tree5fa8e965786917715dd96b439f332574972ff569 /Userland/Libraries/LibCore
parent3da0c072f40d1a93a295e07766355f9278941e13 (diff)
downloadserenity-0cca6cef958f7742e4c232ef79311f6e5b039c1f.zip
LibCore+LookupServer: Implement and use UDPServer::send
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/UDPServer.cpp14
-rw-r--r--Userland/Libraries/LibCore/UDPServer.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/UDPServer.cpp b/Userland/Libraries/LibCore/UDPServer.cpp
index fbe01fc7ce..9d754d2855 100644
--- a/Userland/Libraries/LibCore/UDPServer.cpp
+++ b/Userland/Libraries/LibCore/UDPServer.cpp
@@ -102,4 +102,18 @@ Optional<u16> UDPServer::local_port() const
return ntohs(address.sin_port);
}
+ErrorOr<size_t> UDPServer::send(ReadonlyBytes buffer, sockaddr_in const& to)
+{
+ if (m_fd < 0) {
+ return Error::from_errno(EBADF);
+ }
+
+ auto result = ::sendto(m_fd, buffer.data(), buffer.size(), 0, (sockaddr const*)&to, sizeof(to));
+ if (result < 0) {
+ return Error::from_errno(errno);
+ }
+
+ return result;
+}
+
}
diff --git a/Userland/Libraries/LibCore/UDPServer.h b/Userland/Libraries/LibCore/UDPServer.h
index 705f204fac..453cf43056 100644
--- a/Userland/Libraries/LibCore/UDPServer.h
+++ b/Userland/Libraries/LibCore/UDPServer.h
@@ -30,6 +30,8 @@ public:
return receive(size, saddr);
};
+ ErrorOr<size_t> send(ReadonlyBytes, sockaddr_in const& to);
+
Optional<IPv4Address> local_address() const;
Optional<u16> local_port() const;