diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2021-02-06 17:48:12 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-06 17:52:47 +0100 |
commit | 1dad63824b2af8928b30a9f56aff147c52c71458 (patch) | |
tree | 8d7ab813691975ae59721237dcbf147fc8960352 /Userland/Services/LookupServer/LookupServer.cpp | |
parent | e3135e7ca56daf0b06587b76e999293b02433105 (diff) | |
download | serenity-1dad63824b2af8928b30a9f56aff147c52c71458.zip |
LookupServer: Unify DNSRequest & DNSResponse
They're really the same thing: a DNS packet can contain both questions and
answers, and there's a single bit in the header that determines whether the
packet represents a query or a response. It'll be simpler for us to represent
both types of packets using the same class.
This class can be both serialized and deserialized to/from a raw DNS packet.
Diffstat (limited to 'Userland/Services/LookupServer/LookupServer.cpp')
-rw-r--r-- | Userland/Services/LookupServer/LookupServer.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index 7145f54d89..7831734471 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -26,8 +26,7 @@ #include "LookupServer.h" #include "ClientConnection.h" -#include "DNSRequest.h" -#include "DNSResponse.h" +#include "DNSPacket.h" #include <AK/ByteBuffer.h> #include <AK/Debug.h> #include <AK/HashMap.h> @@ -173,7 +172,9 @@ Vector<String> LookupServer::lookup(const String& hostname, const String& namese m_lookup_cache.remove(it); } - DNSRequest request; + DNSPacket request; + request.set_is_query(); + request.set_id(arc4random_uniform(UINT16_MAX)); request.add_question(hostname, record_type, should_randomize_case); auto buffer = request.to_byte_buffer(); @@ -204,7 +205,7 @@ Vector<String> LookupServer::lookup(const String& hostname, const String& namese did_get_response = true; - auto o_response = DNSResponse::from_raw_response(response_buffer, nrecv); + auto o_response = DNSPacket::from_raw_packet(response_buffer, nrecv); if (!o_response.has_value()) return {}; @@ -215,7 +216,7 @@ Vector<String> LookupServer::lookup(const String& hostname, const String& namese return {}; } - if (response.code() == DNSResponse::Code::REFUSED) { + if (response.code() == DNSPacket::Code::REFUSED) { if (should_randomize_case == ShouldRandomizeCase::Yes) { // Retry with 0x20 case randomization turned off. return lookup(hostname, nameserver, did_get_response, record_type, ShouldRandomizeCase::No); |