summaryrefslogtreecommitdiff
path: root/src/clients
diff options
context:
space:
mode:
Diffstat (limited to 'src/clients')
-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
18 files changed, 299 insertions, 136 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"