summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2021-02-14 15:16:20 +0300
committerAndreas Kling <kling@serenityos.org>2021-02-15 09:14:42 +0100
commitd6f7ced4f100841a9123ee4835a116eea86c2034 (patch)
tree3e1bf1159f26e2a06a9ceb3ce4f34db7350737e9 /Userland/Services/LookupServer
parent42bc5f2cc19c5c528aed8902bb8a48e902da025f (diff)
downloadserenity-d6f7ced4f100841a9123ee4835a116eea86c2034.zip
LookupServer: Move DNS name serialization to DNSName class
Diffstat (limited to 'Userland/Services/LookupServer')
-rw-r--r--Userland/Services/LookupServer/DNSName.cpp12
-rw-r--r--Userland/Services/LookupServer/DNSName.h3
-rw-r--r--Userland/Services/LookupServer/DNSPacket.cpp14
3 files changed, 17 insertions, 12 deletions
diff --git a/Userland/Services/LookupServer/DNSName.cpp b/Userland/Services/LookupServer/DNSName.cpp
index ce9ad68f56..d3e8bf732a 100644
--- a/Userland/Services/LookupServer/DNSName.cpp
+++ b/Userland/Services/LookupServer/DNSName.cpp
@@ -26,6 +26,7 @@
*/
#include "DNSName.h"
+#include <AK/Vector.h>
namespace LookupServer {
@@ -69,4 +70,15 @@ DNSName DNSName::parse(const u8* data, size_t& offset, size_t max_offset, size_t
}
}
+OutputStream& operator<<(OutputStream& stream, const DNSName& name)
+{
+ auto parts = name.as_string().split_view('.');
+ for (auto& part : parts) {
+ stream << (u8)part.length();
+ stream << part.bytes();
+ }
+ stream << '\0';
+ return stream;
+}
+
}
diff --git a/Userland/Services/LookupServer/DNSName.h b/Userland/Services/LookupServer/DNSName.h
index 21d1b88e47..dc0fe7b5c2 100644
--- a/Userland/Services/LookupServer/DNSName.h
+++ b/Userland/Services/LookupServer/DNSName.h
@@ -27,6 +27,7 @@
#pragma once
+#include <AK/Forward.h>
#include <AK/String.h>
namespace LookupServer {
@@ -43,4 +44,6 @@ private:
String m_name;
};
+OutputStream& operator<<(OutputStream& stream, const DNSName&);
+
}
diff --git a/Userland/Services/LookupServer/DNSPacket.cpp b/Userland/Services/LookupServer/DNSPacket.cpp
index 0bf84d5ac3..b2658aa944 100644
--- a/Userland/Services/LookupServer/DNSPacket.cpp
+++ b/Userland/Services/LookupServer/DNSPacket.cpp
@@ -83,22 +83,12 @@ ByteBuffer DNSPacket::to_byte_buffer() const
stream << ReadonlyBytes { &header, sizeof(header) };
for (auto& question : m_questions) {
- auto parts = question.name().as_string().split('.');
- for (auto& part : parts) {
- stream << (u8)part.length();
- stream << part.bytes();
- }
- stream << '\0';
+ stream << question.name();
stream << htons(question.record_type());
stream << htons(question.class_code());
}
for (auto& answer : m_answers) {
- auto parts = answer.name().as_string().split('.');
- for (auto& part : parts) {
- stream << (u8)part.length();
- stream << part.bytes();
- }
- stream << '\0';
+ stream << answer.name();
stream << htons(answer.type());
stream << htons(answer.class_code());
stream << htonl(answer.ttl());