mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
LookupServer: Move DNS name serialization to DNSName class
This commit is contained in:
parent
42bc5f2cc1
commit
d6f7ced4f1
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