From 416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 10 Dec 2014 03:05:47 +0000 Subject: Initial commit --- src/libs6dns/s6dns_domain_decode.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/libs6dns/s6dns_domain_decode.c (limited to 'src/libs6dns/s6dns_domain_decode.c') diff --git a/src/libs6dns/s6dns_domain_decode.c b/src/libs6dns/s6dns_domain_decode.c new file mode 100644 index 0000000..db4ccf5 --- /dev/null +++ b/src/libs6dns/s6dns_domain_decode.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include +#include +#include +#include + +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 ; +} -- cgit v1.3.1