diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2021-02-06 17:30:33 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-06 17:52:47 +0100 |
commit | d8967e4dff99accdbb0128e3175526fe881336a8 (patch) | |
tree | 02fff06ac085411d8a82bd73a77ea2800359a6e3 /Userland/Services | |
parent | 04ff46bff4b956052c94a2b1f14a669c4b57eab2 (diff) | |
download | serenity-d8967e4dff99accdbb0128e3175526fe881336a8.zip |
LookupServer+LibC: Pass IP addresses in binary
Now that we no longer depend on the textual IPC format, we can pass IP addresses
in the format most code actually has and needs it: in binary. The only places we
actually have to deal with textual address representation is:
* When reading /etc/hosts, we have to parse textual addresses & convert them to
binary;
* When doing reverse lookups, we have to form a pseudo-hostname of the form
x.x.x.x.in-addr.arpa.
So we do the conversion in those two cases.
This also increases uniformity between how we handle A (IPv4 address) and other
resource record types. Namely, we now store the raw binary data as received from
a DNS server.
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/LookupServer/ClientConnection.cpp | 5 | ||||
-rw-r--r-- | Userland/Services/LookupServer/DNSResponse.cpp | 3 | ||||
-rw-r--r-- | Userland/Services/LookupServer/LookupServer.cpp | 3 |
3 files changed, 5 insertions, 6 deletions
diff --git a/Userland/Services/LookupServer/ClientConnection.cpp b/Userland/Services/LookupServer/ClientConnection.cpp index bfbf7a3cc2..a7d90b4680 100644 --- a/Userland/Services/LookupServer/ClientConnection.cpp +++ b/Userland/Services/LookupServer/ClientConnection.cpp @@ -58,10 +58,9 @@ OwnPtr<Messages::LookupServer::LookupNameResponse> ClientConnection::handle(cons OwnPtr<Messages::LookupServer::LookupAddressResponse> ClientConnection::handle(const Messages::LookupServer::LookupAddress& message) { - auto optional_address = IPv4Address::from_string(message.address()); - if (!optional_address.has_value()) + if (message.address().length() != 4) return make<Messages::LookupServer::LookupAddressResponse>(1, String()); - auto& address = optional_address.value(); + IPv4Address address { (const u8*)message.address().characters() }; auto name = String::formatted("{}.{}.{}.{}.in-addr.arpa", address[3], address[2], diff --git a/Userland/Services/LookupServer/DNSResponse.cpp b/Userland/Services/LookupServer/DNSResponse.cpp index b14fd585ad..77d903f320 100644 --- a/Userland/Services/LookupServer/DNSResponse.cpp +++ b/Userland/Services/LookupServer/DNSResponse.cpp @@ -108,8 +108,7 @@ Optional<DNSResponse> DNSResponse::from_raw_response(const u8* raw_data, size_t size_t dummy_offset = offset; data = parse_dns_name(raw_data, dummy_offset, raw_size); } else if (record.type() == T_A) { - auto ipv4_address = IPv4Address((const u8*)record.data()); - data = ipv4_address.to_string(); + data = { record.data(), record.data_length() }; } else { // FIXME: Parse some other record types perhaps? dbgln("data=(unimplemented record type {})", record.type()); diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index cbad77f392..7145f54d89 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -96,9 +96,10 @@ void LookupServer::load_etc_hosts() (u8)atoi(sections[2].characters()), (u8)atoi(sections[3].characters()), }; + auto raw_addr = addr.to_in_addr_t(); auto name = fields[1]; - m_etc_hosts.set(name, addr.to_string()); + m_etc_hosts.set(name, String { (const char*)&raw_addr, sizeof(raw_addr) }); IPv4Address reverse_addr { (u8)atoi(sections[3].characters()), |