/contrib/bind9/lib/irs/gai_strerror.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 93 lines · 33 code · 6 blank · 54 comment · 1 complexity · ae5cfb52c4d4835f0d0cc73aeb94a651 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* $Id: gai_strerror.c,v 1.5 2009/09/02 23:48:02 tbox Exp $ */
  17. /*! \file gai_strerror.c
  18. * gai_strerror() returns an error message corresponding to an
  19. * error code returned by getaddrinfo() and getnameinfo(). The following error
  20. * codes and their meaning are defined in
  21. * \link netdb.h include/irs/netdb.h.\endlink
  22. * This implementation is almost an exact copy of lwres/gai_sterror.c except
  23. * that it catches up the latest API standard, RFC3493.
  24. *
  25. * \li #EAI_ADDRFAMILY address family for hostname not supported
  26. * \li #EAI_AGAIN temporary failure in name resolution
  27. * \li #EAI_BADFLAGS invalid value for ai_flags
  28. * \li #EAI_FAIL non-recoverable failure in name resolution
  29. * \li #EAI_FAMILY ai_family not supported
  30. * \li #EAI_MEMORY memory allocation failure
  31. * \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493)
  32. * \li #EAI_NONAME hostname nor servname provided, or not known
  33. * \li #EAI_SERVICE servname not supported for ai_socktype
  34. * \li #EAI_SOCKTYPE ai_socktype not supported
  35. * \li #EAI_SYSTEM system error returned in errno
  36. * \li #EAI_BADHINTS Invalid value for hints (non-standard)
  37. * \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard)
  38. * \li #EAI_OVERFLOW Argument buffer overflow
  39. * \li #EAI_INSECUREDATA Insecure Data (experimental)
  40. *
  41. * The message invalid error code is returned if ecode is out of range.
  42. *
  43. * ai_flags, ai_family and ai_socktype are elements of the struct
  44. * addrinfo used by lwres_getaddrinfo().
  45. *
  46. * \section gai_strerror_see See Also
  47. *
  48. * strerror(), getaddrinfo(), getnameinfo(), RFC3493.
  49. */
  50. #include <config.h>
  51. #include <irs/netdb.h>
  52. /*% Text of error messages. */
  53. static const char *gai_messages[] = {
  54. "no error",
  55. "address family for hostname not supported",
  56. "temporary failure in name resolution",
  57. "invalid value for ai_flags",
  58. "non-recoverable failure in name resolution",
  59. "ai_family not supported",
  60. "memory allocation failure",
  61. "no address associated with hostname",
  62. "hostname nor servname provided, or not known",
  63. "servname not supported for ai_socktype",
  64. "ai_socktype not supported",
  65. "system error returned in errno",
  66. "bad hints",
  67. "bad protocol",
  68. "argument buffer overflow",
  69. "insecure data provided"
  70. };
  71. /*%
  72. * Returns an error message corresponding to an error code returned by
  73. * getaddrinfo() and getnameinfo()
  74. */
  75. IRS_GAISTRERROR_RETURN_T
  76. gai_strerror(int ecode) {
  77. union {
  78. const char *const_ptr;
  79. char *deconst_ptr;
  80. } ptr;
  81. if ((ecode < 0) ||
  82. (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
  83. ptr.const_ptr = "invalid error code";
  84. else
  85. ptr.const_ptr = gai_messages[ecode];
  86. return (ptr.deconst_ptr);
  87. }