1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LookupServer: Introduce DNSName

This is a wrapper around a string representing a domain name (such as
"example.com"). It never has a trailing dot.

For now, this class doesn't do much except wrap the raw string. Subsequent
commits will add or move more functionality to it.
This commit is contained in:
Sergey Bugaev 2021-02-14 15:02:02 +03:00 committed by Andreas Kling
parent de811faf55
commit ae1e82fd2f
9 changed files with 117 additions and 38 deletions

View file

@ -58,9 +58,6 @@ void DNSPacket::add_question(const String& name, u16 record_type, ShouldRandomiz
builder.append(ch);
}
if (name[name.length() - 1] != '.')
builder.append('.');
m_questions.empend(builder.to_string(), record_type, (u16)C_IN);
}
@ -85,7 +82,7 @@ ByteBuffer DNSPacket::to_byte_buffer() const
stream << ReadonlyBytes { &header, sizeof(header) };
for (auto& question : m_questions) {
auto parts = question.name().split('.');
auto parts = question.name().as_string().split('.');
for (auto& part : parts) {
stream << (u8)part.length();
stream << part.bytes();
@ -95,7 +92,7 @@ ByteBuffer DNSPacket::to_byte_buffer() const
stream << htons(question.class_code());
}
for (auto& answer : m_answers) {
auto parts = answer.name().split('.');
auto parts = answer.name().as_string().split('.');
for (auto& part : parts) {
stream << (u8)part.length();
stream << part.bytes();