You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

  1. /* udns_misc.c
  2. miscellaneous routines
  3. Copyright (C) 2005 Michael Tokarev <mjt@corpit.ru>
  4. This file is part of UDNS library, an async DNS stub resolver.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library, in file named COPYING.LGPL; if not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place,
  16. Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include "udns.h"
  19. int dns_findname(const struct dns_nameval *nv, const char *name) {
  20. register const char *a, *b;
  21. for(; nv->name; ++nv)
  22. for(a = name, b = nv->name; ; ++a, ++b)
  23. if (DNS_DNUC(*a) != *b) break;
  24. else if (!*a) return nv->val;
  25. return -1;
  26. }
  27. const char *_dns_format_code(char *buf, const char *prefix, int code) {
  28. char *bp = buf;
  29. unsigned c, n;
  30. do *bp++ = DNS_DNUC(*prefix);
  31. while(*++prefix);
  32. *bp++ = '#';
  33. if (code < 0) code = -code, *bp++ = '-';
  34. n = 0; c = code;
  35. do ++n;
  36. while((c /= 10));
  37. c = code;
  38. bp[n--] = '\0';
  39. do bp[n--] = c % 10 + '0';
  40. while((c /= 10));
  41. return buf;
  42. }
  43. const char *dns_strerror(int err) {
  44. if (err >= 0) return "successeful completion";
  45. switch(err) {
  46. case DNS_E_TEMPFAIL: return "temporary failure in name resolution";
  47. case DNS_E_PROTOCOL: return "protocol error";
  48. case DNS_E_NXDOMAIN: return "domain name does not exist";
  49. case DNS_E_NODATA: return "valid domain but no data of requested type";
  50. case DNS_E_NOMEM: return "out of memory";
  51. case DNS_E_BADQUERY: return "malformed query";
  52. default: return "unknown error";
  53. }
  54. }
  55. const char *dns_version(void) {
  56. return UDNS_VERSION;
  57. }