summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Services/LookupServer')
-rw-r--r--Userland/Services/LookupServer/LookupServer.cpp2
-rw-r--r--Userland/Services/LookupServer/MulticastDNS.cpp26
-rw-r--r--Userland/Services/LookupServer/MulticastDNS.h3
3 files changed, 13 insertions, 18 deletions
diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp
index 9f946c4fc7..5b77ca408a 100644
--- a/Userland/Services/LookupServer/LookupServer.cpp
+++ b/Userland/Services/LookupServer/LookupServer.cpp
@@ -183,7 +183,7 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, RecordType record
// Fourth, look up .local names using mDNS instead of DNS nameservers.
if (name.as_string().ends_with(".local"sv)) {
- answers = m_mdns->lookup(name, record_type);
+ answers = TRY(m_mdns->lookup(name, record_type));
for (auto& answer : answers)
put_in_cache(answer);
return answers;
diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp
index f806c6a6c4..75f26c54f0 100644
--- a/Userland/Services/LookupServer/MulticastDNS.cpp
+++ b/Userland/Services/LookupServer/MulticastDNS.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Sergey Bugaev <bugaevc@serenityos.org>
+ * Copyright (c) 2022, Alexander Narsudinov <a.narsudinov@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -11,6 +12,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibCore/File.h>
+#include <LibCore/System.h>
#include <limits.h>
#include <poll.h>
#include <sys/socket.h>
@@ -142,36 +144,28 @@ Vector<IPv4Address> MulticastDNS::local_addresses() const
return addresses;
}
-Vector<Answer> MulticastDNS::lookup(Name const& name, RecordType record_type)
+ErrorOr<Vector<Answer>> MulticastDNS::lookup(Name const& name, RecordType record_type)
{
Packet request;
request.set_is_query();
request.set_recursion_desired(false);
request.add_question({ name, record_type, RecordClass::IN, false });
- if (emit_packet(request).is_error()) {
- perror("failed to emit request packet");
- return {};
- }
-
+ TRY(emit_packet(request));
Vector<Answer> answers;
// FIXME: It would be better not to block
// the main loop while we wait for a response.
while (true) {
- pollfd pfd { fd(), POLLIN, 0 };
- auto rc = poll(&pfd, 1, 1000);
- if (rc < 0) {
- perror("poll");
- } else if (rc == 0) {
+ auto pfd = pollfd { fd(), POLLIN, 0 };
+ auto rc = TRY(Core::System::poll({ &pfd, 1 }, 1000));
+ if (rc == 0) {
// Timed out.
- return {};
+ return Vector<Answer> {};
}
-
- // TODO: propagate the error somehow
- auto buffer = MUST(receive(1024));
+ auto buffer = TRY(receive(1024));
if (buffer.is_empty())
- return {};
+ return Vector<Answer> {};
auto optional_packet = Packet::from_raw_packet(buffer.data(), buffer.size());
if (!optional_packet.has_value()) {
dbgln("Got an invalid mDNS packet");
diff --git a/Userland/Services/LookupServer/MulticastDNS.h b/Userland/Services/LookupServer/MulticastDNS.h
index ff3ecfd2f3..4ccba4865d 100644
--- a/Userland/Services/LookupServer/MulticastDNS.h
+++ b/Userland/Services/LookupServer/MulticastDNS.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Sergey Bugaev <bugaevc@serenityos.org>
+ * Copyright (c) 2022, Alexander Narsudinov <a.narsudinov@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -20,7 +21,7 @@ using namespace DNS;
class MulticastDNS : public Core::UDPServer {
C_OBJECT(MulticastDNS)
public:
- Vector<Answer> lookup(Name const&, RecordType record_type);
+ ErrorOr<Vector<Answer>> lookup(Name const&, RecordType record_type);
private:
explicit MulticastDNS(Object* parent = nullptr);