From a144d44fbdcdb3713769759ba2d0853b66412839 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 21 Jul 2018 16:45:34 +0000 Subject: Adaptation to skalibs-2.7.0.0 --- src/libs6dns/s6dns_engine.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libs6dns/s6dns_engine.c b/src/libs6dns/s6dns_engine.c index 26cb5f3..0057b14 100644 --- a/src/libs6dns/s6dns_engine.c +++ b/src/libs6dns/s6dns_engine.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -63,6 +62,43 @@ static int relevant (char const *q, unsigned int qlen, char const *ans, unsigned return 1 ; } +static int s6dns_mininetstring_read (int fd, stralloc *sa, uint32_t *w) +{ + if (!*w) + { + char pack[2] ; + switch (fd_read(fd, pack, 2)) + { + case -1 : return -1 ; + case 0 : return 0 ; + case 1 : *w = ((uint32_t)pack[0] << 8) | (1U << 31) ; break ; + case 2 : *w = ((uint32_t)pack[0] << 8) | (uint32_t)pack[1] | (1U << 30) ; break ; + default : return (errno = EDOM, -1) ; + } + } + if (*w & (1U << 31)) + { + unsigned char c ; + switch (fd_read(fd, (char *)&c, 1)) + { + case -1 : return -1 ; + case 0 : return (errno = EPIPE, -1) ; + case 1 : *w |= (uint32_t)c | (1U << 30) ; *w &= ~(1U << 31) ; break ; + default : return (errno = EDOM, -1) ; + } + } + if (*w & (1U << 30)) + { + if (!stralloc_readyplus(sa, *w & ~(1U << 30))) return -1 ; + *w &= ~(1U << 30) ; + } + { + size_t r = allread(fd, sa->s + sa->len, *w) ; + sa->len += r ; *w -= r ; + } + return *w ? -1 : 1 ; +} + /* Network core functions: transport-dependent */ @@ -258,7 +294,7 @@ static int s6dns_engine_read_udp (s6dns_engine_t *dt, tain_t const *stamp) static int s6dns_engine_read_tcp (s6dns_engine_t *dt, tain_t const *stamp) { - ssize_t r = sanitize_read(mininetstring_read(dt->fd, &dt->sa, &dt->protostate)) ; + ssize_t r = sanitize_read(s6dns_mininetstring_read(dt->fd, &dt->sa, &dt->protostate)) ; if (r < 0) return (prepare_next(dt, stamp, 1), 0) ; else if (!r) return (errno = EAGAIN, 0) ; else if ((dt->sa.len - dt->querylen) < 12) -- cgit v1.2.3