From 82fe3f71b2c323bdbe9c977283b01972fbb48471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Tue, 20 Jul 2021 01:40:16 -0300 Subject: [PATCH] Add hosts(5) output. Useful for cat'ing into /etc/hosts or to be used by a DNS server like dnsmasq. --- read-avahi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/read-avahi.c b/read-avahi.c index 70e5535..8faa21b 100644 --- a/read-avahi.c +++ b/read-avahi.c @@ -5,7 +5,8 @@ * DNS server. Requires avahi-browse(1) and a running Avahi daemon. * * Output is hardcoded: - * - dns.conf for unbound + * - dns.conf for unbound.conf(5) + * - hosts for a hosts(5) * * Copyright (c) 2021 Érico Nogueira * @@ -32,6 +33,9 @@ int main() /* unbound config file */ FILE *fu = fopen("dns.conf", "w"); if (!fu) return 1; + /* hosts */ + FILE *fh = fopen("hosts", "w"); + if (!fu) return 1; FILE *p = popen("avahi-browse --all --resolve --no-db-lookup --parsable --terminate", "re"); if (!p) return 1; @@ -66,10 +70,12 @@ int main() char *type = ipv6 ? "AAAA" : "A"; fprintf(fu, "local-data: \"%s. IN %s %s\"\n", name, type, ip); + fprintf(fh, "%s %s\n", ip, name); } free(line); fclose(fu); + fclose(fh); pclose(p); return 0;