blob: db4ccf506936e7ac9c541f32dcb388e4ce90cf9c (
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/error.h>
#include <skalibs/bytestr.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 = '.' ;
case_lowerb(s+1, len) ;
return len + 1 ;
}
int s6dns_domain_decode (s6dns_domain_t *d)
{
unsigned int max = 255 ;
unsigned int pos = 0 ;
for (;;)
{
register 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 ;
}
|