diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-10 03:05:47 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-10 03:05:47 +0000 |
commit | 416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 (patch) | |
tree | 1c746d673dcec7a8488c6ac51db8245411034376 /src/libs6dns/s6dns_domain_fromstring.c | |
download | s6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.xz |
Initial commit
Diffstat (limited to 'src/libs6dns/s6dns_domain_fromstring.c')
-rw-r--r-- | src/libs6dns/s6dns_domain_fromstring.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_domain_fromstring.c b/src/libs6dns/s6dns_domain_fromstring.c new file mode 100644 index 0000000..9346e24 --- /dev/null +++ b/src/libs6dns/s6dns_domain_fromstring.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include <errno.h> +#include <skalibs/bytestr.h> +#include <s6-dns/s6dns-domain.h> + +int s6dns_domain_fromstring (s6dns_domain_t *d, char const *s, unsigned int len) +{ + register unsigned int j = 1 ; + register unsigned int i = 0 ; + register unsigned int lastdot = 0 ; + d->s[0] = '.' ; + for (; i < len ; i++) + { + if (lastdot) + { + if ((j >= 255) || (lastdot++ >= 64)) return (errno = ENAMETOOLONG, 0) ; + d->s[j++] = s[i] ; + } + if (s[i] == '.') lastdot = 0 ; + else if (!lastdot) + { + i-- ; + lastdot = 1 ; + } + } + case_lowerb(d->s + 1, j-1) ; + d->len = j ; + return 1 ; +} |