mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-03 06:40:05 +00:00
LookupServer: Move DNS name serialization to DNSName class
This commit is contained in:
parent
42bc5f2cc1
commit
d6f7ced4f1
Notes:
sideshowbarker
2024-07-18 22:17:11 +09:00
Author: https://github.com/bugaevc
Commit: d6f7ced4f1
Pull-request: https://github.com/SerenityOS/serenity/pull/5345
3 changed files with 17 additions and 12 deletions
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DNSName.h"
|
#include "DNSName.h"
|
||||||
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Forward.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace LookupServer {
|
||||||
|
@ -43,4 +44,6 @@ private:
|
||||||
String m_name;
|
String m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OutputStream& operator<<(OutputStream& stream, const DNSName&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,22 +83,12 @@ ByteBuffer DNSPacket::to_byte_buffer() const
|
||||||
|
|
||||||
stream << ReadonlyBytes { &header, sizeof(header) };
|
stream << ReadonlyBytes { &header, sizeof(header) };
|
||||||
for (auto& question : m_questions) {
|
for (auto& question : m_questions) {
|
||||||
auto parts = question.name().as_string().split('.');
|
stream << question.name();
|
||||||
for (auto& part : parts) {
|
|
||||||
stream << (u8)part.length();
|
|
||||||
stream << part.bytes();
|
|
||||||
}
|
|
||||||
stream << '\0';
|
|
||||||
stream << htons(question.record_type());
|
stream << htons(question.record_type());
|
||||||
stream << htons(question.class_code());
|
stream << htons(question.class_code());
|
||||||
}
|
}
|
||||||
for (auto& answer : m_answers) {
|
for (auto& answer : m_answers) {
|
||||||
auto parts = answer.name().as_string().split('.');
|
stream << answer.name();
|
||||||
for (auto& part : parts) {
|
|
||||||
stream << (u8)part.length();
|
|
||||||
stream << part.bytes();
|
|
||||||
}
|
|
||||||
stream << '\0';
|
|
||||||
stream << htons(answer.type());
|
stream << htons(answer.type());
|
||||||
stream << htons(answer.class_code());
|
stream << htons(answer.class_code());
|
||||||
stream << htonl(answer.ttl());
|
stream << htonl(answer.ttl());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue