/contrib/bind9/lib/lwres/gai_strerror.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 83 lines · 31 code · 7 blank · 45 comment · 1 complexity · 85ac0b9c0453ddfc87517df63ab523fa MD5 · raw file

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