dn_expand.c 678 B

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