summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clients/s6-dnsip.c58
-rw-r--r--src/clients/s6-dnsip4-filter.c2
-rw-r--r--src/clients/s6-dnsip4.c60
-rw-r--r--src/clients/s6-dnsip6-filter.c2
-rw-r--r--src/clients/s6-dnsip6.c58
-rw-r--r--src/clients/s6-dnsmx.c41
-rw-r--r--src/clients/s6-dnsname.c61
-rw-r--r--src/clients/s6-dnsns.c38
-rw-r--r--src/clients/s6-dnsq.c5
-rw-r--r--src/clients/s6-dnsqr.c6
-rw-r--r--src/clients/s6-dnsqualify.c7
-rw-r--r--src/clients/s6-dnssoa.c2
-rw-r--r--src/clients/s6-dnssrv.c32
-rw-r--r--src/clients/s6-dnstxt.c29
-rw-r--r--src/clients/s6-randomip.c29
-rw-r--r--src/clients/s6dns-generic-filter.h2
-rw-r--r--src/clients/s6dns_generic_filter_main.c2
-rw-r--r--src/clients/s6dns_namescanner.c1
-rw-r--r--src/include/s6-dns/hosts.h21
-rw-r--r--src/include/s6-dns/skadns.h2
-rw-r--r--src/libs6dns/deps-lib/s6dns71
-rw-r--r--src/libs6dns/s6dns_finish.c1
-rw-r--r--src/libs6dns/s6dns_hosts_init.c6
-rw-r--r--src/libs6dns/s6dns_init.c6
-rw-r--r--src/skadns/skadns_startf.c1
-rw-r--r--src/skadns/skadnsd.c4
26 files changed, 361 insertions, 186 deletions
diff --git a/src/clients/s6-dnsip.c b/src/clients/s6-dnsip.c
index 9828443..6a5747d 100644
--- a/src/clients/s6-dnsip.c
+++ b/src/clients/s6-dnsip.c
@@ -11,49 +11,73 @@
#include <skalibs/buffer.h>
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns.h>
-#define USAGE "s6-dnsip [ -q ] [ -r ] [ -t timeout ] domain"
+#include <s6-dns/s6dns-rci.h>
+#include <s6-dns/hosts.h>
+#include <s6-dns/s6dns-resolve.h>
+
+#define USAGE "s6-dnsip [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
{
genalloc ips = GENALLOC_ZERO ; /* ip46full */
tain deadline ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
+ int flaghosts = 0 ;
int flagunsort = 0 ;
+ int r = 0 ;
PROG = "s6-dnsip" ;
- for (;;)
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qHhrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'H' : flaghosts = 0 ; break ;
+ case 'h' : flaghosts = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+ if (flaghosts)
+ {
+ flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
+ if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
+ }
+
+ if (flaghosts)
{
- int r = s6dns_resolve_aaaaa_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ r = flagqualify ? s6dns_hosts_aaaaa_q(argv[0], &ips) : s6dns_hosts_aaaaa_noq(argv[0], &ips) ;
+ if (r == -1) strerr_diefu3sys(111, "look up ", argv[0], " in hosts database") ;
+ }
+
+ if (!r)
+ {
+ r = s6dns_resolve_aaaaa_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
- if (!r && errno) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
+ if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
}
- if (!genalloc_len(ip46full, &ips)) return 1 ;
+ if (!genalloc_len(ip46full, &ips)) return 1 ;
if (flagunsort) random_unsort(ips.s, genalloc_len(ip46full, &ips), sizeof(ip46full)) ;
- for (i = 0 ; i < genalloc_len(ip46full, &ips) ; i++)
+ for (size_t i = 0 ; i < genalloc_len(ip46full, &ips) ; i++)
{
char fmt[IP6_FMT] ;
size_t n = ip46full_fmt(fmt, genalloc_s(ip46full, &ips) + i) ;
diff --git a/src/clients/s6-dnsip4-filter.c b/src/clients/s6-dnsip4-filter.c
index 4842734..dbfc82b 100644
--- a/src/clients/s6-dnsip4-filter.c
+++ b/src/clients/s6-dnsip4-filter.c
@@ -1,9 +1,11 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/fmtscan.h>
#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
+
#include <s6-dns/s6dns-constants.h>
#include <s6-dns/s6dns-message.h>
#include "s6dns-generic-filter.h"
diff --git a/src/clients/s6-dnsip4.c b/src/clients/s6-dnsip4.c
index db32804..370c006 100644
--- a/src/clients/s6-dnsip4.c
+++ b/src/clients/s6-dnsip4.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -9,53 +10,78 @@
#include <skalibs/buffer.h>
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns.h>
-#define USAGE "s6-dnsip4 [ -q ] [ -r ] [ -t timeout ] domain"
+#include <s6-dns/s6dns-rci.h>
+#include <s6-dns/hosts.h>
+#include <s6-dns/s6dns-resolve.h>
+
+#define USAGE "s6-dnsip4 [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
{
stralloc ips = STRALLOC_ZERO ;
tain deadline ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
+ int flaghosts = 0 ;
int flagunsort = 0 ;
+ int r = 0 ;
PROG = "s6-dnsip4" ;
- for (;;)
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qHhrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'H' : flaghosts = 0 ; break ;
+ case 'h' : flaghosts = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+ if (flaghosts)
+ {
+ flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
+ if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
+ }
+
+ if (flaghosts)
{
- int r = s6dns_resolve_a_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
- if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
+ r = flagqualify ? s6dns_hosts_a_q(argv[0], &ips) : s6dns_hosts_a_noq(argv[0], &ips) ;
+ if (r == -1) strerr_diefu3sys(111, "look up ", argv[0], " in hosts database") ;
+ }
+
+ if (!r)
+ {
+ r = s6dns_resolve_a_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ if (r == -1) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
}
+
if (!ips.len) return 1 ;
if (flagunsort) random_unsort(ips.s, ips.len / 4, 4) ;
- for (i = 0 ; i < ips.len / 4 ; i++)
+ for (size_t i = 0 ; i < ips.len / 4 ; i++)
{
char fmt[IP4_FMT] ;
size_t n = ip4_fmt(fmt, ips.s + 4 * i) ;
fmt[n++] = '\n' ;
- if (buffer_put(buffer_1small, fmt, n) < (ssize_t)n)
+ if (buffer_put(buffer_1small, fmt, n) == -1)
strerr_diefu1sys(111, "write to stdout") ;
}
if (!buffer_flush(buffer_1small))
diff --git a/src/clients/s6-dnsip6-filter.c b/src/clients/s6-dnsip6-filter.c
index d2855bc..a7840f7 100644
--- a/src/clients/s6-dnsip6-filter.c
+++ b/src/clients/s6-dnsip6-filter.c
@@ -1,9 +1,11 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/fmtscan.h>
#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
+
#include <s6-dns/s6dns-constants.h>
#include <s6-dns/s6dns-message.h>
#include "s6dns-generic-filter.h"
diff --git a/src/clients/s6-dnsip6.c b/src/clients/s6-dnsip6.c
index eb37a53..2fb2f6f 100644
--- a/src/clients/s6-dnsip6.c
+++ b/src/clients/s6-dnsip6.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -9,48 +10,73 @@
#include <skalibs/buffer.h>
#include <skalibs/tai.h>
#include <skalibs/random.h>
-#include <s6-dns/s6dns.h>
-#define USAGE "s6-dnsip6 [ -q ] [ -r ] [ -t timeout ] domain"
+#include <s6-dns/s6dns-rci.h>
+#include <s6-dns/hosts.h>
+#include <s6-dns/s6dns-resolve.h>
+
+#define USAGE "s6-dnsip6 [ -q ] [ -H | -h ] [ -r ] [ -t timeout ] domain"
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
{
stralloc ips = STRALLOC_ZERO ;
tain deadline ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
+ int flaghosts = 0 ;
int flagunsort = 0 ;
+ int r = 0 ;
PROG = "s6-dnsip6" ;
- for (;;)
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qHhrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'H' : flaghosts = 0 ; break ;
+ case 'h' : flaghosts = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+ if (flaghosts)
+ {
+ flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
+ if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
+ }
+
+ if (flaghosts)
{
- int r = s6dns_resolve_aaaa_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
- if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
+ r = flagqualify ? s6dns_hosts_aaaa_q(argv[0], &ips) : s6dns_hosts_aaaa_noq(argv[0], &ips) ;
+ if (r == -1) strerr_diefu3sys(111, "look up ", argv[0], " in hosts database") ;
+ }
+
+ if (!r)
+ {
+ r = s6dns_resolve_aaaa_g(&ips, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ if (r == -1) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
}
+
if (!ips.len) return 1 ;
if (flagunsort) random_unsort(ips.s, ips.len / 16, 16) ;
- for (i = 0 ; i < ips.len / 16 ; i++)
+ for (size_t i = 0 ; i < ips.len / 16 ; i++)
{
char fmt[IP6_FMT] ;
size_t n = ip6_fmt(fmt, ips.s + 16 * i) ;
diff --git a/src/clients/s6-dnsmx.c b/src/clients/s6-dnsmx.c
index 159a5c6..356eb4b 100644
--- a/src/clients/s6-dnsmx.c
+++ b/src/clients/s6-dnsmx.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -9,6 +10,7 @@
#include <skalibs/tai.h>
#include <skalibs/genalloc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsmx [ -q ] [ -r ] [ -t timeout ] name"
@@ -18,38 +20,43 @@ int main (int argc, char const *const *argv)
{
genalloc mxs = GENALLOC_ZERO ; /* array of s6dns_message_rr_mx_t */
tain deadline ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
int flagunsort = 0 ;
+ int r ;
PROG = "s6-dnsmx" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
- {
- int r = s6dns_resolve_mx_g(&mxs, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
- if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
- if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
- }
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+
+ r = s6dns_resolve_mx_g(&mxs, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
+ if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
if (!genalloc_len(s6dns_message_rr_mx_t, &mxs)) return 1 ;
if (flagunsort) random_unsort(mxs.s, genalloc_len(s6dns_message_rr_mx_t, &mxs), sizeof(s6dns_message_rr_mx_t)) ;
- for (i = 0 ; i < genalloc_len(s6dns_message_rr_mx_t, &mxs) ; i++)
+ for (size_t i = 0 ; i < genalloc_len(s6dns_message_rr_mx_t, &mxs) ; i++)
{
char buf[S6DNS_FMT_MX] ;
size_t len = s6dns_fmt_mx(buf, S6DNS_FMT_MX, genalloc_s(s6dns_message_rr_mx_t, &mxs) + i) ;
diff --git a/src/clients/s6-dnsname.c b/src/clients/s6-dnsname.c
index c35751b..7c35f06 100644
--- a/src/clients/s6-dnsname.c
+++ b/src/clients/s6-dnsname.c
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -11,9 +12,10 @@
#include <skalibs/genalloc.h>
#include <skalibs/ip46.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
-#define USAGE "s6-dnsname [ -4 | -6 ] [ -r ] [ -t timeout ] ip"
+#define USAGE "s6-dnsname [ -4 | -6 ] [ -H | -h ] [ -r ] [ -t timeout ] ip"
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
@@ -22,25 +24,33 @@ int main (int argc, char const *const *argv)
tain deadline ;
ip46full ip = IP46FULL_ZERO ;
unsigned int t = 0 ;
+ int flaghosts = 0 ;
int flagunsort = 0 ;
int do4 = 0 ;
int do6 = 0 ;
PROG = "s6-dnsname" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "46rt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case '4' : do4 = 1 ; break ;
- case '6' : do6 = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "46Hhrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case '4' : do4 = 1 ; break ;
+ case '6' : do6 = 1 ; break ;
+ case 'H' : flaghosts = 0 ; break ;
+ case 'h' : flaghosts = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
+
if (!do4 && !do6) do4 = do6 = 1 ;
if (do4 && do6)
{
@@ -56,12 +66,38 @@ int main (int argc, char const *const *argv)
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+ if (flaghosts)
+ {
+ flaghosts = s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") ;
+ if (flaghosts == -1) strerr_diefu1sys(111, "initialize hosts database from /etc/hosts or /etc/hosts.cdb") ;
+ }
+
+ if (flaghosts)
+ {
+ stralloc sa = STRALLOC_ZERO ;
+ int r = s6dns_hosts_name(ip.ip, &sa, &ds, ip.is6) ;
+ if (r == -1) strerr_diefu3sys(111, "look up ", argv[0], " in hosts database") ;
+ if (r)
+ {
+ for (size_t i = 0 ; i < genalloc_len(size_t, &ds) ; i++)
+ {
+ if (buffer_puts(buffer_1, sa.s + genalloc_s(size_t, &ds)[i]) < 0
+ || buffer_put(buffer_1, "\n", 1) < 0) goto err ;
+ }
+ if (!buffer_flush(buffer_1)) goto err ;
+ return 0 ;
+ }
+ }
+
{
int r = ip.is6 ? s6dns_resolve_name6_g(&ds, ip.ip, &deadline) : s6dns_resolve_name4_g(&ds, ip.ip, &deadline) ;
if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
}
+
if (!genalloc_len(s6dns_domain_t, &ds)) return 1 ;
if (flagunsort) random_unsort(ds.s, genalloc_len(s6dns_domain_t, &ds), sizeof(s6dns_domain_t)) ;
{
@@ -72,6 +108,7 @@ int main (int argc, char const *const *argv)
}
if (buffer_putflush(buffer_1, "\n", 1) < 1) goto err ;
return 0 ;
+
err:
strerr_diefu1sys(111, "write to stdout") ;
}
diff --git a/src/clients/s6-dnsns.c b/src/clients/s6-dnsns.c
index 88f5197..7e19caf 100644
--- a/src/clients/s6-dnsns.c
+++ b/src/clients/s6-dnsns.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -10,6 +11,7 @@
#include <skalibs/tai.h>
#include <skalibs/genalloc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsns [ -q ] [ -r ] [ -t timeout ] name"
@@ -22,31 +24,37 @@ int main (int argc, char const *const *argv)
unsigned int t = 0 ;
int flagqualify = 0 ;
int flagunsort = 0 ;
+ int r ;
PROG = "s6-dnsns" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
- {
- int r = s6dns_resolve_ns_g(&ds, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
- if (r < 0) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
- if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
- }
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+
+ r = s6dns_resolve_ns_g(&ds, argv[0], strlen(argv[0]), flagqualify, &deadline) ;
+ if (r == -1) strerr_diefu2sys((errno == ETIMEDOUT) ? 99 : 111, "resolve ", argv[0]) ;
+ if (!r) strerr_diefu4x(2, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
if (!genalloc_len(s6dns_domain_t, &ds)) return 1 ;
if (flagunsort) random_unsort(ds.s, genalloc_len(s6dns_domain_t, &ds), sizeof(s6dns_domain_t)) ;
{
diff --git a/src/clients/s6-dnsq.c b/src/clients/s6-dnsq.c
index c6d50cf..6f85c42 100644
--- a/src/clients/s6-dnsq.c
+++ b/src/clients/s6-dnsq.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/bitarray.h>
#include <skalibs/strerr.h>
@@ -11,6 +12,7 @@
#include <skalibs/genwrite.h>
#include <skalibs/tai.h>
#include <skalibs/ip46.h>
+
#include <s6-dns/s6dns.h>
#include <s6-dns/s6dns-analyze.h>
#include <s6-dns/s6dns-debug.h>
@@ -60,11 +62,10 @@ int main (int argc, char const *const *argv)
{
ip46 z[S6DNS_MAX_SERVERS] ;
size_t n ;
- unsigned int k = 0 ;
if (!*argv[2+i]) continue ;
if (!ip46_scanlist(z, S6DNS_MAX_SERVERS - j, argv[2 + i], &n))
strerr_diefu2sys(100, "make an IP address list out of ", argv[2+i]) ;
- for (; k < n ; k++)
+ for (size_t k = 0 ; k < n ; k++)
{
memcpy(s6dns_ip46list_ip(&servers, j + k), z[k].ip, SKALIBS_IP_SIZE) ;
#ifdef SKALIBS_IPV6_ENABLED
diff --git a/src/clients/s6-dnsqr.c b/src/clients/s6-dnsqr.c
index 290b06a..d8424e5 100644
--- a/src/clients/s6-dnsqr.c
+++ b/src/clients/s6-dnsqr.c
@@ -3,12 +3,14 @@
#include <string.h>
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/strerr.h>
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
#include <skalibs/genwrite.h>
#include <skalibs/tai.h>
+
#include <s6-dns/s6dns.h>
#include <s6-dns/s6dns-analyze.h>
#include <s6-dns/s6dns-debug.h>
@@ -54,7 +56,9 @@ int main (int argc, char const *const *argv)
if (debuglevel & 2) { dbh.pre_send = &s6dns_debug_dumpdt_pre_send ; dbh.post_send = &s6dns_debug_dumpdt_post_send ; }
tain_now_set_stopwatch_g() ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+
if (!s6dns_resolve_core_r_g(&d, qtype, &s6dns_engine_here, &s6dns_rci_here.servers, &dbh, &deadline))
{
char fmt[UINT16_FMT] ;
diff --git a/src/clients/s6-dnsqualify.c b/src/clients/s6-dnsqualify.c
index 38bf3ea..1752389 100644
--- a/src/clients/s6-dnsqualify.c
+++ b/src/clients/s6-dnsqualify.c
@@ -2,8 +2,10 @@
#include <sys/types.h>
#include <string.h>
+
#include <skalibs/strerr.h>
#include <skalibs/buffer.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnsqualify name"
@@ -16,7 +18,10 @@ int main (int argc, char const *const *argv)
if (argc < 2) dieusage() ;
if (!s6dns_domain_fromstring(&d, argv[1], strlen(argv[1])))
strerr_diefu2sys(100, "make a domain name from ", argv[1]) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+
{
s6dns_domain_t list[s6dns_rci_here.rulesnum] ;
unsigned int n = s6dns_qualify(list, &d) ;
diff --git a/src/clients/s6-dnssoa.c b/src/clients/s6-dnssoa.c
index 4df42b4..0ed2ff3 100644
--- a/src/clients/s6-dnssoa.c
+++ b/src/clients/s6-dnssoa.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -10,6 +11,7 @@
#include <skalibs/tai.h>
#include <skalibs/genalloc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnssoa [ -q ] [ -r ] [ -t timeout ] name"
diff --git a/src/clients/s6-dnssrv.c b/src/clients/s6-dnssrv.c
index b60e3be..c0b9fe3 100644
--- a/src/clients/s6-dnssrv.c
+++ b/src/clients/s6-dnssrv.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -10,6 +11,7 @@
#include <skalibs/tai.h>
#include <skalibs/genalloc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnssrv [ -q ] [ -r ] [ -t timeout ] service protocol name"
@@ -19,30 +21,36 @@ int main (int argc, char const *const *argv)
{
genalloc srvs = GENALLOC_ZERO ; /* array of s6dns_message_rr_srv_t */
tain deadline ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
int flagunsort = 0 ;
PROG = "s6-dnssrv" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "qt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 3) dieusage() ;
tain_now_set_stopwatch_g() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
tain_add_g(&deadline, &deadline) ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
+
{
size_t n0 = strlen(argv[0]) ;
size_t n1 = strlen(argv[1]) ;
@@ -63,7 +71,7 @@ int main (int argc, char const *const *argv)
}
if (!genalloc_len(s6dns_message_rr_srv_t, &srvs)) return 1 ;
if (flagunsort) random_unsort(srvs.s, genalloc_len(s6dns_message_rr_srv_t, &srvs), sizeof(s6dns_message_rr_srv_t)) ;
- for (i = 0 ; i < genalloc_len(s6dns_message_rr_srv_t, &srvs) ; i++)
+ for (size_t i = 0 ; i < genalloc_len(s6dns_message_rr_srv_t, &srvs) ; i++)
{
char buf[S6DNS_FMT_SRV] ;
size_t len = s6dns_fmt_srv(buf, S6DNS_FMT_SRV, genalloc_s(s6dns_message_rr_srv_t, &srvs) + i) ;
diff --git a/src/clients/s6-dnstxt.c b/src/clients/s6-dnstxt.c
index 2564917..5818ac8 100644
--- a/src/clients/s6-dnstxt.c
+++ b/src/clients/s6-dnstxt.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
@@ -11,6 +12,7 @@
#include <skalibs/genalloc.h>
#include <skalibs/skamisc.h>
#include <skalibs/random.h>
+
#include <s6-dns/s6dns.h>
#define USAGE "s6-dnstxt [ -q ] [ -r ] [ -t timeout ] name"
@@ -23,24 +25,27 @@ int main (int argc, char const *const *argv)
genalloc offsets = GENALLOC_ZERO ; /* array of size_t */
tain deadline ;
size_t n ;
- size_t i = 0 ;
unsigned int t = 0 ;
int flagqualify = 0 ;
int flagunsort = 0 ;
PROG = "s6-dnstxt" ;
- for (;;)
+
{
- int opt = lgetopt(argc, argv, "qrt:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case 'q' : flagqualify = 1 ; break ;
- case 'r' : flagunsort = 1 ; break ;
- case 't' : if (!uint0_scan(subgetopt_here.arg, &t)) dieusage() ; break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "qrt:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'q' : flagqualify = 1 ; break ;
+ case 'r' : flagunsort = 1 ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (argc < 1) dieusage() ;
if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ;
@@ -56,7 +61,7 @@ int main (int argc, char const *const *argv)
if (!n) return 1 ;
{
size_t printable_offsets[n] ;
- for (i = 0 ; i < n ; i++)
+ for (size_t i = 0 ; i < n ; i++)
{
size_t beg = genalloc_s(size_t, &offsets)[i] ;
size_t end = (i < n-1 ? genalloc_s(size_t, &offsets)[i+1] : sa.len) - 1 ;
@@ -67,7 +72,7 @@ int main (int argc, char const *const *argv)
genalloc_free(size_t, &offsets) ;
stralloc_free(&sa) ;
if (flagunsort) random_unsort((char *)printable_offsets, n, sizeof(size_t)) ;
- for (i = 0 ; i < n ; i++)
+ for (size_t i = 0 ; i < n ; i++)
if ((buffer_puts(buffer_1small, quoted.s + printable_offsets[i]) < 0)
|| (buffer_put(buffer_1small, "\n", 1) < 1))
strerr_diefu1sys(111, "write to stdout") ;
diff --git a/src/clients/s6-randomip.c b/src/clients/s6-randomip.c
index 6a43794..158440a 100644
--- a/src/clients/s6-randomip.c
+++ b/src/clients/s6-randomip.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <sys/types.h>
+#include <stddef.h>
#include <errno.h>
#include <skalibs/types.h>
@@ -22,22 +22,23 @@ int main (int argc, char const *const *argv)
size_t what = 0 ;
int finite = 0 ;
PROG = "s6-randomip" ;
- for (;;)
{
- int opt = lgetopt(argc, argv, "46n:") ;
- if (opt == -1) break ;
- switch (opt)
+ subgetopt l = SUBGETOPT_ZERO ;
+ for (;;)
{
- case '4' : what |= 1 ; break ;
- case '6' : what |= 2 ; break ;
- case 'n' :
- if (!uint0_scan(subgetopt_here.arg, &n)) dieusage() ;
- finite = 1 ;
- break ;
- default : dieusage() ;
+ int opt = subgetopt_r(argc, argv, "46n:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case '4' : what |= 1 ; break ;
+ case '6' : what |= 2 ; break ;
+ case 'n' : if (!uint0_scan(l.arg, &n)) dieusage() ; finite = 1 ;
+ break ;
+ default : dieusage() ;
+ }
}
+ argc -= l.ind ; argv += l.ind ;
}
- argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
if (!what) what = 1 ;
what = 1 << (1 << what) ;
for (i = 0 ; !finite || (i < n) ; i++)
@@ -52,7 +53,7 @@ int main (int argc, char const *const *argv)
random_buf(ip, len) ;
len = (len == 16) ? ip6_fmt(fmt, ip) : ip4_fmt(fmt, ip) ;
fmt[len++] = '\n' ;
- if (buffer_put(buffer_1, fmt, len) < (ssize_t)len)
+ if (buffer_put(buffer_1, fmt, len) < len)
strerr_diefu1sys(111, "write to stdout") ;
}
if (!buffer_flush(buffer_1))
diff --git a/src/clients/s6dns-generic-filter.h b/src/clients/s6dns-generic-filter.h
index 29f758e..9f92dea 100644
--- a/src/clients/s6dns-generic-filter.h
+++ b/src/clients/s6dns-generic-filter.h
@@ -5,7 +5,9 @@
#include <sys/types.h>
#include <stdint.h>
+
#include <skalibs/stralloc.h>
+
#include <s6-dns/s6dns-domain.h>
typedef size_t scan_func (s6dns_domain_t *, char const *) ;
diff --git a/src/clients/s6dns_generic_filter_main.c b/src/clients/s6dns_generic_filter_main.c
index 3e1894d..4c58aae 100644
--- a/src/clients/s6dns_generic_filter_main.c
+++ b/src/clients/s6dns_generic_filter_main.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/error.h>
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
@@ -15,6 +16,7 @@
#include <skalibs/buffer.h>
#include <skalibs/bufalloc.h>
#include <skalibs/skamisc.h>
+
#include <s6-dns/s6dns-constants.h>
#include <s6-dns/s6dns-domain.h>
#include <s6-dns/skadns.h>
diff --git a/src/clients/s6dns_namescanner.c b/src/clients/s6dns_namescanner.c
index 2df6aae..57d3836 100644
--- a/src/clients/s6dns_namescanner.c
+++ b/src/clients/s6dns_namescanner.c
@@ -3,6 +3,7 @@
#include <sys/types.h>
#include <limits.h>
#include <errno.h>
+
#include <s6-dns/s6dns-domain.h>
#include "s6dns-generic-filter.h"
diff --git a/src/include/s6-dns/hosts.h b/src/include/s6-dns/hosts.h
index 0f85d0b..e76bfcb 100644
--- a/src/include/s6-dns/hosts.h
+++ b/src/include/s6-dns/hosts.h
@@ -13,11 +13,8 @@ extern cdb s6dns_hosts_here ;
extern int s6dns_hosts_compile (int, int) ;
-extern int s6dns_hosts_init_r (cdb *, char const *, char const *, char const *) ;
-#define s6dns_hosts_init() s6dns_hosts_init_r(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb")
-#define s6dns_hosts_free_r(c) cdb_free(c)
-#define s6dns_hosts_free() s6dns_hosts_free_r(&s6dns_hosts_here)
-
+extern int s6dns_hosts_init (cdb *, char const *, char const *, char const *) ;
+#define s6dns_hosts_free(c) cdb_free(c)
/* IP to name */
@@ -41,8 +38,8 @@ extern int s6dns_hosts_ip_string_r (cdb const *, char const *, stralloc *, unsig
#define s6dns_hosts_ip_noq(name, sa, is6) s6dns_hosts_ip_noq_r(&s6dns_hosts_here, (name), sa, is6)
#define s6dns_hosts_ip_unq(name, sa, is6) s6dns_hosts_ip_unq_r(&s6dns_hosts_here, (name), sa, is6)
-#define s6dns_hosts_a_string_r(c, name, sa, isalias) s6dns_hosts_ip_string_r(c, name, sa, !!(isunq) << 1)
-#define s6dns_hosts_aaaa_string_r(c, name, sa, isalias) s6dns_hosts_ip_string_r(c, name, sa, (!!(isunq) << 1) | 1)
+#define s6dns_hosts_a_string_r(c, name, sa, isunq) s6dns_hosts_ip_string_r(c, name, sa, !!(isunq) << 1)
+#define s6dns_hosts_aaaa_string_r(c, name, sa, isunq) s6dns_hosts_ip_string_r(c, name, sa, (!!(isunq) << 1) | 1)
extern int s6dns_hosts_aaaaa_string_r (cdb const *, char const *, genalloc *, int) ;
#define s6dns_hosts_a_string(name, sa, isunq) s6dns_hosts_a_string_r(&s6dns_hosts_here, (name), sa, isunq)
@@ -68,14 +65,14 @@ extern int s6dns_hosts_aaaaa_string_r (cdb const *, char const *, genalloc *, in
/* name to IP, with qualification */
-extern int s6dns_hosts_ip_q_r (cdb const *, char const *, stralloc *sa, char const *, unsigned int, int) ;
-#define s6dns_hosts_a_q_r(c, name, sa, rules, rulesnum) s6dns_hosts_ip_q_r(c, name, sa, rules, rulesnum, 0)
-#define s6dns_hosts_aaaa_q_r(c, name, rules, rulesnum, sa) s6dns_hosts_ip_q_r(c, name, sa, rules, rulesnum, 1)
+extern int s6dns_hosts_ip_q_r (cdb const *, char const *, stralloc *, char const *, unsigned int, int) ;
+#define s6dns_hosts_a_q_r(c, name, sa, rules, rulesnum) s6dns_hosts_ip_q_r(c, name, sa, rules, (rulesnum), 0)
+#define s6dns_hosts_aaaa_q_r(c, name, sa, rules, rulesnum) s6dns_hosts_ip_q_r(c, name, sa, rules, (rulesnum), 1)
extern int s6dns_hosts_aaaaa_q_r (cdb const *, char const *, genalloc *, char const *, unsigned int) ;
#define s6dns_hosts_ip_q(name, sa, is6) s6dns_hosts_ip_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum, is6)
#define s6dns_hosts_a_q(name, sa) s6dns_hosts_a_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
-#define s6dns_hosts_aaaa_q(name, sa) s6dns_hosts_ip_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
-#define s6dns_hosts_aaaaa_q(name, ga) s6dns_hosts_aaaaa_q_r(&s6dns_hosts_here, (name), ga)
+#define s6dns_hosts_aaaa_q(name, sa) s6dns_hosts_aaaa_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
+#define s6dns_hosts_aaaaa_q(name, ga) s6dns_hosts_aaaaa_q_r(&s6dns_hosts_here, (name), ga, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
#endif
diff --git a/src/include/s6-dns/skadns.h b/src/include/s6-dns/skadns.h
index 8f27d2e..32e3648 100644
--- a/src/include/s6-dns/skadns.h
+++ b/src/include/s6-dns/skadns.h
@@ -5,10 +5,12 @@
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/tai.h>
#include <skalibs/genalloc.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/textclient.h>
+
#include <s6-dns/config.h>
#include <s6-dns/s6dns-domain.h>
diff --git a/src/libs6dns/deps-lib/s6dns b/src/libs6dns/deps-lib/s6dns
index 6eaf610..266b574 100644
--- a/src/libs6dns/deps-lib/s6dns
+++ b/src/libs6dns/deps-lib/s6dns
@@ -1,5 +1,24 @@
+s6dns_analyze_packet.o
+s6dns_analyze_qtype_parse.o
+s6dns_analyze_record.o
+s6dns_analyze_record_a.o
+s6dns_analyze_record_aaaa.o
+s6dns_analyze_record_caa.o
+s6dns_analyze_record_domain.o
+s6dns_analyze_record_hinfo.o
+s6dns_analyze_record_mx.o
+s6dns_analyze_record_soa.o
+s6dns_analyze_record_srv.o
+s6dns_analyze_record_strings.o
+s6dns_analyze_record_unknown.o
+s6dns_analyze_rtypetable.o
s6dns_constants_error.o
s6dns_constants_error_str.o
+s6dns_debug_dumpdt_post_recv.o
+s6dns_debug_dumpdt_post_send.o
+s6dns_debug_dumpdt_pre_send.o
+s6dns_debug_dumpdt_stderr.o
+s6dns_debug_dumpdt_stdout.o
s6dns_debughook_zero.o
s6dns_domain_arpafromip4.o
s6dns_domain_arpafromip6.o
@@ -18,46 +37,49 @@ s6dns_engine_freen.o
s6dns_engine_here.o
s6dns_engine_nextdeadline.o
s6dns_engine_zero.o
+s6dns_finish.o
+s6dns_fmt_caa.o
s6dns_fmt_domainlist.o
s6dns_fmt_hinfo.o
s6dns_fmt_mx.o
s6dns_fmt_soa.o
s6dns_fmt_srv.o
-s6dns_fmt_caa.o
-s6dns_hosts_compile.o
s6dns_hosts_aaaaa_q.o
s6dns_hosts_aaaaa_string.o
+s6dns_hosts_compile.o
+s6dns_hosts_here.o
+s6dns_hosts_init.o
s6dns_hosts_ip_q.o
s6dns_hosts_ip_string.o
s6dns_hosts_name.o
-s6dns_hosts_here.o
+s6dns_init.o
s6dns_message_counts_next.o
s6dns_message_counts_pack.o
s6dns_message_counts_unpack.o
s6dns_message_counts_zero.o
+s6dns_message_get_caa.o
s6dns_message_get_domain.o
s6dns_message_get_domain_nodecode.o
s6dns_message_get_hinfo.o
-s6dns_message_get_string.o
-s6dns_message_get_string_internal.o
-s6dns_message_get_strings.o
s6dns_message_get_mx.o
s6dns_message_get_soa.o
s6dns_message_get_srv.o
-s6dns_message_get_caa.o
+s6dns_message_get_string.o
+s6dns_message_get_string_internal.o
+s6dns_message_get_strings.o
s6dns_message_header_pack.o
s6dns_message_header_unpack.o
s6dns_message_header_zero.o
-s6dns_message_parse_answer_aaaa.o
+s6dns_message_parse.o
s6dns_message_parse_answer_a.o
+s6dns_message_parse_answer_aaaa.o
+s6dns_message_parse_answer_caa.o
s6dns_message_parse_answer_domain.o
s6dns_message_parse_answer_hinfo.o
s6dns_message_parse_answer_mx.o
s6dns_message_parse_answer_soa.o
s6dns_message_parse_answer_srv.o
-s6dns_message_parse_answer_caa.o
s6dns_message_parse_answer_strings.o
-s6dns_message_parse.o
s6dns_message_parse_getrr.o
s6dns_message_parse_init.o
s6dns_message_parse_next.o
@@ -68,36 +90,15 @@ s6dns_rci_here.o
s6dns_rci_init.o
s6dns_rci_zero.o
s6dns_resolve_core.o
-s6dns_resolve_parse.o
-s6dns_resolven_loop.o
-s6dns_resolven_parse.o
s6dns_resolve_dpag.o
s6dns_resolve_mpag.o
s6dns_resolve_name4.o
s6dns_resolve_name6.o
+s6dns_resolve_parse.o
+s6dns_resolven_loop.o
+s6dns_resolven_parse.o
s6dns_resolvenoq.o
-s6dns_resolveq.o
s6dns_resolvenoq_aaaaa.o
+s6dns_resolveq.o
s6dns_resolveq_aaaaa.o
-s6dns_analyze_packet.o
-s6dns_analyze_qtype_parse.o
-s6dns_analyze_record.o
-s6dns_analyze_record_a.o
-s6dns_analyze_record_aaaa.o
-s6dns_analyze_record_hinfo.o
-s6dns_analyze_record_mx.o
-s6dns_analyze_record_soa.o
-s6dns_analyze_record_srv.o
-s6dns_analyze_record_caa.o
-s6dns_analyze_record_domain.o
-s6dns_analyze_record_strings.o
-s6dns_analyze_record_unknown.o
-s6dns_analyze_rtypetable.o
-s6dns_debug_dumpdt_stdout.o
-s6dns_debug_dumpdt_stderr.o
-s6dns_debug_dumpdt_post_recv.o
-s6dns_debug_dumpdt_pre_send.o
-s6dns_debug_dumpdt_post_send.o
-s6dns_init.o
-s6dns_finish.o
-lskarnet
diff --git a/src/libs6dns/s6dns_finish.c b/src/libs6dns/s6dns_finish.c
index f786329..a8a479a 100644
--- a/src/libs6dns/s6dns_finish.c
+++ b/src/libs6dns/s6dns_finish.c
@@ -7,5 +7,6 @@
void s6dns_finish ()
{
s6dns_engine_free(&s6dns_engine_here) ;
+ s6dns_hosts_free(&s6dns_hosts_here) ;
s6dns_rci_free(&s6dns_rci_here) ;
}
diff --git a/src/libs6dns/s6dns_hosts_init.c b/src/libs6dns/s6dns_hosts_init.c
index 762d738..8f78ab1 100644
--- a/src/libs6dns/s6dns_hosts_init.c
+++ b/src/libs6dns/s6dns_hosts_init.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
+#include <time.h>
#include <skalibs/posixplz.h>
#include <skalibs/cdb.h>
@@ -12,7 +13,7 @@
#include <s6-dns/hosts.h>
-int s6dns_hosts_init_r (cdb *c, char const *txtfile, char const *cdbfile, char const *tmpprefix)
+int s6dns_hosts_init (cdb *c, char const *txtfile, char const *cdbfile, char const *tmpprefix)
{
int fdr ;
int fdc = openc_read(cdbfile) ;
@@ -25,7 +26,8 @@ int s6dns_hosts_init_r (cdb *c, char const *txtfile, char const *cdbfile, char c
if (errno == ENOENT) goto useit ;
else goto errc ;
}
- if (stc.st_mtim > str.st_mtim) goto useit ;
+ if (stc.st_mtim.tv_sec > str.st_mtim.tv_sec
+ || (stc.st_mtim.tv_sec == str.st_mtim.tv_sec && stc.st_mtim.tv_nsec > str.st_mtim.tv_nsec)) goto useit ;
fd_close(fdc) ;
}
diff --git a/src/libs6dns/s6dns_init.c b/src/libs6dns/s6dns_init.c
index 7f98d13..10dcbf5 100644
--- a/src/libs6dns/s6dns_init.c
+++ b/src/libs6dns/s6dns_init.c
@@ -1,10 +1,16 @@
/* ISC license. */
#include <s6-dns/s6dns-rci.h>
+#include <s6-dns/hosts.h>
#include <s6-dns/s6dns.h>
int s6dns_init (void)
{
if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf")) return 0 ;
+ if (s6dns_hosts_init(&s6dns_hosts_here, "/etc/hosts", "/etc/hosts.cdb", "/tmp/hosts.cdb") == -1) goto err ;
return 1 ;
+
+ err:
+ s6dns_rci_free(&s6dns_rci_here) ;
+ return 0 ;
}
diff --git a/src/skadns/skadns_startf.c b/src/skadns/skadns_startf.c
index bf20edd..e9fadd3 100644
--- a/src/skadns/skadns_startf.c
+++ b/src/skadns/skadns_startf.c
@@ -2,6 +2,7 @@
#include <skalibs/posixplz.h>
#include <skalibs/textclient.h>
+
#include <s6-dns/skadns.h>
int skadns_startf (skadns_t *a, tain const *deadline, tain *stamp)
diff --git a/src/skadns/skadnsd.c b/src/skadns/skadnsd.c
index 8714d2b..0909dfa 100644
--- a/src/skadns/skadnsd.c
+++ b/src/skadns/skadnsd.c
@@ -115,7 +115,9 @@ int main (void)
if (ndelay_on(1) < 0) strerr_diefu2sys(111, "ndelay_on ", "1") ;
if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
tain_now_set_stopwatch_g() ;
- if (!s6dns_init()) strerr_diefu1sys(111, "s6dns_init") ;
+
+ if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"))
+ strerr_diefu1sys(111, "initialize structures from /etc/resolv.conf") ;
{
tain deadline ;