summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_domain_arpafromip6.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-10 03:05:47 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-10 03:05:47 +0000
commit416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 (patch)
tree1c746d673dcec7a8488c6ac51db8245411034376 /src/libs6dns/s6dns_domain_arpafromip6.c
downloads6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.xz
Initial commit
Diffstat (limited to 'src/libs6dns/s6dns_domain_arpafromip6.c')
-rw-r--r--src/libs6dns/s6dns_domain_arpafromip6.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_domain_arpafromip6.c b/src/libs6dns/s6dns_domain_arpafromip6.c
new file mode 100644
index 0000000..3b58127
--- /dev/null
+++ b/src/libs6dns/s6dns_domain_arpafromip6.c
@@ -0,0 +1,21 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/fmtscan.h>
+#include <s6-dns/s6dns-domain.h>
+
+void s6dns_domain_arpafromip6 (s6dns_domain_t *d, char const *ip6, unsigned int mask)
+{
+ register unsigned int i ;
+ if (mask > 128) mask = 128 ;
+ mask = mask ? 1 + ((mask-1) >> 2) : 0 ;
+ d->len = 0 ;
+ d->s[d->len++] = '.' ;
+ for (i = 32 - mask ; i < 32 ; i++)
+ {
+ unsigned char c = ip6[15-(i>>1)] ;
+ d->s[d->len++] = fmtscan_asc((i & 1) ? (c >> 4) : (c & 15)) ;
+ d->s[d->len++] = '.' ;
+ }
+ byte_copy(d->s + d->len, 9, "ip6.arpa.") ; d->len += 9 ;
+}