remove cruft from old resolver and numeric ip parsing
[musl] / src / network / dn_expand.c
1 #include <resolv.h>
2 #include "libc.h"
3
4 int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space)
5 {
6         const unsigned char *p = src;
7         int len = -1, j;
8         if (space > 256) space = 256;
9         if (p==end || !*p) return -1;
10         for (;;) {
11                 if (*p & 0xc0) {
12                         if (p+1==end) return -1;
13                         j = ((p[0] & 0x3f) << 8) | p[1];
14                         if (len < 0) len = p+2-src;
15                         if (j >= end-base) return -1;
16                         p = base+j;
17                 } else if (*p) {
18                         j = *p+1;
19                         if (j>=end-p || j>space) return -1;
20                         while (--j) *dest++ = *++p;
21                         *dest++ = *++p ? '.' : 0;
22                 } else {
23                         if (len < 0) len = p+1-src;
24                         return len;
25                 }
26         }
27 }
28
29 weak_alias(__dn_expand, dn_expand);