gethostbyname.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * This file is a ghastly hack because nobody can agree on
  3. * gethostbyname_r()'s prototype.
  4. *
  5. * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*************************************************************************
  22. Usage:
  23. #include <errno.h>
  24. #include "gethostbyname.h"
  25. f ()
  26. {
  27. struct ghbnctx ctx;
  28. errno = 0;
  29. hp = gethostbyname_ctx (host, &ctx);
  30. if (hp == NULL)
  31. {
  32. if (errno != 0)
  33. handle_value_of_errno (errno);
  34. else
  35. handle_value_of_h_errno (h_error_ctx (&ctx));
  36. }
  37. else
  38. {
  39. ...
  40. }
  41. free_ghbnctx (&ctx);
  42. }
  43. *************************************************************************/
  44. #ifndef _gethostbyname_h
  45. #define _gethostbyname_h
  46. #if HAVE_GETIPNODEBYNAME
  47. struct ghbnctx
  48. {
  49. int h_err;
  50. struct hostent *hostent;
  51. };
  52. #elif HAVE_GETHOSTBYNAME_R == 6
  53. struct ghbnctx
  54. {
  55. int h_err;
  56. struct hostent hostent;
  57. char *hostbuf;
  58. size_t hostbuf_len;
  59. };
  60. #elif HAVE_GETHOSTBYNAME_R == 5
  61. struct ghbnctx
  62. {
  63. int h_err;
  64. struct hostent hostent;
  65. char *hostbuf;
  66. int hostbuf_len;
  67. };
  68. #elif HAVE_GETHOSTBYNAME_R == 3
  69. struct ghbnctx
  70. {
  71. int h_err;
  72. struct hostent_data hostent_data;
  73. struct hostent hostent;
  74. };
  75. #else
  76. struct ghbnctx
  77. {
  78. int h_err;
  79. };
  80. #endif
  81. struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx);
  82. int h_error_ctx (struct ghbnctx *ctx);
  83. void free_ghbnctx (struct ghbnctx *ctx);
  84. #endif