summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer/DNSServer.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-02-06 17:13:04 +0000
committerAndreas Kling <kling@serenityos.org>2022-02-14 11:44:09 +0100
commit4ca0669d1e732b1697a7944a7899b2250bb81cf1 (patch)
tree2033072165988c06a6eea19a4ba4323913ba8498 /Userland/Services/LookupServer/DNSServer.cpp
parent17d3592cabffe3bc413df45cb4b166b55d600f44 (diff)
downloadserenity-4ca0669d1e732b1697a7944a7899b2250bb81cf1.zip
LookupServer: Convert to Core::Stream::UDPSocket
Diffstat (limited to 'Userland/Services/LookupServer/DNSServer.cpp')
-rw-r--r--Userland/Services/LookupServer/DNSServer.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/Userland/Services/LookupServer/DNSServer.cpp b/Userland/Services/LookupServer/DNSServer.cpp
index 5c664f36a8..7d3846f0d0 100644
--- a/Userland/Services/LookupServer/DNSServer.cpp
+++ b/Userland/Services/LookupServer/DNSServer.cpp
@@ -16,24 +16,27 @@ DNSServer::DNSServer(Object* parent)
{
bind(IPv4Address(), 53);
on_ready_to_receive = [this]() {
- handle_client();
+ auto result = handle_client();
+ if (result.is_error()) {
+ dbgln("DNSServer: Failed to handle client: {}", result.error());
+ }
};
}
-void DNSServer::handle_client()
+ErrorOr<void> DNSServer::handle_client()
{
sockaddr_in client_address;
auto buffer = receive(1024, client_address);
auto optional_request = DNSPacket::from_raw_packet(buffer.data(), buffer.size());
if (!optional_request.has_value()) {
dbgln("Got an invalid DNS packet");
- return;
+ return {};
}
auto& request = optional_request.value();
if (!request.is_query()) {
dbgln("It's not a request");
- return;
+ return {};
}
LookupServer& lookup_server = LookupServer::the();
@@ -46,7 +49,7 @@ void DNSServer::handle_client()
if (question.class_code() != DNSRecordClass::IN)
continue;
response.add_question(question);
- auto answers = lookup_server.lookup(question.name(), question.record_type());
+ auto answers = TRY(lookup_server.lookup(question.name(), question.record_type()));
for (auto& answer : answers) {
response.add_answer(answer);
}
@@ -59,8 +62,8 @@ void DNSServer::handle_client()
buffer = response.to_byte_buffer();
- // FIXME: We should be handling errors here.
- [[maybe_unused]] auto result = send(buffer, client_address);
+ TRY(send(buffer, client_address));
+ return {};
}
}