Skip to content

Commit

Permalink
LibDNS: Add a default entry for localhost
Browse files Browse the repository at this point in the history
In the future, we may want to parse /etc/hosts (or equivalent) into the
cache; this commit only adds localhost to make the normal workflow work.
  • Loading branch information
alimpfard committed Nov 10, 2024
1 parent 4337197 commit abf3f79
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Libraries/LibDNS/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ class Resolver {
: m_pending_lookups(make<RedBlackTree<u16, PendingLookup>>())
, m_create_socket(move(create_socket))
{
m_cache.with_write_locked([&](auto& cache) {
auto add_v4v6_entry = [&cache](StringView name_string, IPv4Address v4, IPv6Address v6) {
auto name = Messages::DomainName::from_string(name_string);
auto ptr = make_ref_counted<LookupResult>(name);
ptr->will_add_record_of_type(Messages::ResourceType::A);
ptr->will_add_record_of_type(Messages::ResourceType::AAAA);
cache.set(name_string, ptr);

ptr->add_record({ .name = {}, .type = Messages::ResourceType::A, .class_ = Messages::Class::IN, .ttl = 0, .record = Messages::Records::A { v4 }, .raw = {} });
ptr->add_record({ .name = {}, .type = Messages::ResourceType::AAAA, .class_ = Messages::Class::IN, .ttl = 0, .record = Messages::Records::AAAA { v6 }, .raw = {} });
};

add_v4v6_entry("localhost"sv, { 127, 0, 0, 1 }, IPv6Address::loopback());
});
}

NonnullRefPtr<Core::Promise<Empty>> when_socket_ready()
Expand Down

0 comments on commit abf3f79

Please sign in to comment.