gai_strerror.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <stdio.h>
  16. #include <netdb.h>
  17. static const struct
  18. {
  19. int code;
  20. const char *msg;
  21. }
  22. values[] =
  23. {
  24. { EAI_ADDRFAMILY, "Address family for hostname not supported" },
  25. { EAI_AGAIN, "Temporary failure in name resolution" },
  26. { EAI_BADFLAGS, "Bad value for ai_flags" },
  27. { EAI_FAIL, "Non-recoverable failure in name resolution" },
  28. { EAI_FAMILY, "ai_family not supported" },
  29. { EAI_MEMORY, "Memory allocation failure" },
  30. { EAI_NODATA, "No address associated with hostname" },
  31. { EAI_NONAME, "Name or service not known" },
  32. { EAI_SERVICE, "Servname not supported for ai_socktype" },
  33. { EAI_SOCKTYPE, "ai_socktype not supported" },
  34. { EAI_SYSTEM, "System error" },
  35. { EAI_INPROGRESS, "Processing request in progress" },
  36. { EAI_CANCELED, "Request canceled" },
  37. { EAI_NOTCANCELED, "Request not canceled" },
  38. { EAI_ALLDONE, "All requests done" },
  39. { EAI_INTR, "Interrupted by a signal" }
  40. };
  41. const char *
  42. gai_strerror (int code)
  43. {
  44. size_t i;
  45. for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
  46. if (values[i].code == code)
  47. return values[i].msg;
  48. return "Unknown error";
  49. }