Add hosts(5) output.

Useful for cat'ing into /etc/hosts or to be used by a DNS server like
dnsmasq.
This commit is contained in:
Érico Nogueira 2021-07-20 01:40:16 -03:00
parent ecc0b29e91
commit 82fe3f71b2
1 changed files with 7 additions and 1 deletions

View File

@ -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;