summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorChristopher Dumas <christopherdumas@gmail.com>2019-06-06 08:29:26 -0700
committerAndreas Kling <awesomekling@gmail.com>2019-06-07 08:35:41 +0200
commit70a37f9a266871c9e23b3fc70ea815b8b7ae0f12 (patch)
tree93ed139f8bfefb9eb74881d2606e43d7efa78d2f /Servers
parent4f62176c3e2d86d1c305f904bc5f0894a4ee3a20 (diff)
downloadserenity-70a37f9a266871c9e23b3fc70ea815b8b7ae0f12.zip
LookupServer: Load hostnames
Diffstat (limited to 'Servers')
-rw-r--r--Servers/LookupServer/main.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/Servers/LookupServer/main.cpp b/Servers/LookupServer/main.cpp
index 3a2c713ba5..9929565a11 100644
--- a/Servers/LookupServer/main.cpp
+++ b/Servers/LookupServer/main.cpp
@@ -39,7 +39,27 @@ int main(int argc, char** argv)
config->file_name().characters());
auto DNS_IP = config->read_entry("DNS", "IPAddress", "127.0.0.53");
- HashMap<String, IPv4Address> dns_cache;
+ dbgprintf("LookupServer: Loading hosts from /etc/hosts:\n");
+ HashMap<String, IPv4Address> dns_custom_hostnames;
+ auto* file = fopen("/etc/hosts", "r");
+ auto linebuf = ByteBuffer::create_uninitialized(256);
+ while (fgets((char*)linebuf.pointer(), linebuf.size(), file)) {
+ auto str_line = String::copy(linebuf);
+ auto fields = str_line.split('\t');
+ auto sections = fields[0].split('.');
+ IPv4Address addr {
+ (byte)atoi(sections[0].characters()),
+ (byte)atoi(sections[1].characters()),
+ (byte)atoi(sections[2].characters()),
+ (byte)atoi(sections[3].characters()),
+ };
+ int len = 0;
+ while ((fields[1][len++]) != -123)
+ ;
+ auto name = fields[1].substring(0, len - 3);
+ dbgprintf("LookupServer: Hosts: %s\t%s\n", name.characters(), addr.to_string().characters());
+ dns_custom_hostnames.set(name, addr);
+ }
int server_fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (server_fd < 0) {
@@ -111,7 +131,10 @@ int main(int argc, char** argv)
Vector<String> responses;
- if (!hostname.is_empty()) {
+ if (dns_custom_hostnames.contains(hostname)) {
+ addresses.append(dns_custom_hostnames.get(hostname));
+ dbgprintf("LookupServer: Found preconfigured host (from /etc/hosts): %s\n", addresses[0].to_string().characters());
+ } else if (!hostname.is_empty()) {
bool did_timeout;
int retries = 3;
do {