diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index 9f946c4fc7b..5b77ca408a0 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -183,7 +183,7 @@ ErrorOr> 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 f806c6a6c42..75f26c54f0d 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Sergey Bugaev + * Copyright (c) 2022, Alexander Narsudinov * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -142,36 +144,28 @@ Vector MulticastDNS::local_addresses() const return addresses; } -Vector MulticastDNS::lookup(Name const& name, RecordType record_type) +ErrorOr> 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 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 {}; } - - // TODO: propagate the error somehow - auto buffer = MUST(receive(1024)); + auto buffer = TRY(receive(1024)); if (buffer.is_empty()) - return {}; + return Vector {}; 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 ff3ecfd2f34..4ccba4865d9 100644 --- a/Userland/Services/LookupServer/MulticastDNS.h +++ b/Userland/Services/LookupServer/MulticastDNS.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Sergey Bugaev + * Copyright (c) 2022, Alexander Narsudinov * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,7 +21,7 @@ using namespace DNS; class MulticastDNS : public Core::UDPServer { C_OBJECT(MulticastDNS) public: - Vector lookup(Name const&, RecordType record_type); + ErrorOr> lookup(Name const&, RecordType record_type); private: explicit MulticastDNS(Object* parent = nullptr);