summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_domain_arpafromip6.c
blob: 594eb69265975ea48582d5dc0fae6a9cd89443d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ISC license. */

#include <string.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)
{
  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++] = '.' ;
  }
  memcpy(d->s + d->len, "ip6.arpa.", 9) ; d->len += 9 ;
}