blob: e5fab0a65f3c60f4a841e74037b010fe33392eda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/* ISC license. */
#include <errno.h>
#include <skalibs/posixishard.h>
#include <s6-dns/s6dns-domain.h>
static inline unsigned int s6dns_domain_label_decode (char *s, unsigned int max)
{
unsigned int len = *(unsigned char *)s ;
if ((len > 63) || (len >= max)) return (errno = EPROTO, 0) ;
*s = '.' ;
return len + 1 ;
}
int s6dns_domain_decode (s6dns_domain_t *d)
{
unsigned int max = 255 ;
unsigned int pos = 0 ;
for (;;)
{
unsigned int r = s6dns_domain_label_decode(d->s + pos, max - pos) ;
if (!r) return 0 ;
pos += r ;
if (r == 1) break ;
}
d->len = pos ;
return 1 ;
}
|