OLD | NEW |
(Empty) | |
| 1 #include <resolv.h> |
| 2 #include "libc.h" |
| 3 |
| 4 int __dn_expand(const unsigned char *base, const unsigned char *end, const unsig
ned char *src, char *dest, int space) |
| 5 { |
| 6 const unsigned char *p = src; |
| 7 char *dend, *dbegin = dest; |
| 8 int len = -1, i, j; |
| 9 if (p==end || space <= 0) return -1; |
| 10 dend = dest + (space > 254 ? 254 : space); |
| 11 /* detect reference loop using an iteration counter */ |
| 12 for (i=0; i < end-base; i+=2) { |
| 13 /* loop invariants: p<end, dest<dend */ |
| 14 if (*p & 0xc0) { |
| 15 if (p+1==end) return -1; |
| 16 j = ((p[0] & 0x3f) << 8) | p[1]; |
| 17 if (len < 0) len = p+2-src; |
| 18 if (j >= end-base) return -1; |
| 19 p = base+j; |
| 20 } else if (*p) { |
| 21 if (dest != dbegin) *dest++ = '.'; |
| 22 j = *p++; |
| 23 if (j >= end-p || j >= dend-dest) return -1; |
| 24 while (j--) *dest++ = *p++; |
| 25 } else { |
| 26 *dest = 0; |
| 27 if (len < 0) len = p+1-src; |
| 28 return len; |
| 29 } |
| 30 } |
| 31 return -1; |
| 32 } |
| 33 |
| 34 weak_alias(__dn_expand, dn_expand); |
OLD | NEW |