gethostbyname.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * $Id$
  22. */
  23. /*************************************************************************
  24. Usage:
  25. #include <errno.h>
  26. #include "gethostbyname.h"
  27. f ()
  28. {
  29. struct ghbnctx ctx;
  30. errno = 0;
  31. hp = gethostbyname_ctx (host, &ctx);
  32. if (hp == NULL)
  33. {
  34. if (errno != 0)
  35. handle_value_of_errno (errno);
  36. else
  37. handle_value_of_h_errno (h_error_ctx (&ctx));
  38. }
  39. else
  40. {
  41. ...
  42. }
  43. free_ghbnctx (&ctx);
  44. }
  45. *************************************************************************/
  46. #ifndef _gethostbyname_h
  47. #define _gethostbyname_h
  48. #if HAVE_GETIPNODEBYNAME
  49. struct ghbnctx
  50. {
  51. int h_err;
  52. struct hostent *hostent;
  53. };
  54. #elif HAVE_GETHOSTBYNAME_R == 6
  55. struct ghbnctx
  56. {
  57. int h_err;
  58. struct hostent hostent;
  59. char *hostbuf;
  60. size_t hostbuf_len;
  61. };
  62. #elif HAVE_GETHOSTBYNAME_R == 5
  63. struct ghbnctx
  64. {
  65. int h_err;
  66. struct hostent hostent;
  67. char *hostbuf;
  68. int hostbuf_len;
  69. };
  70. #elif HAVE_GETHOSTBYNAME_R == 3
  71. struct ghbnctx
  72. {
  73. int h_err;
  74. struct hostent_data hostent_data;
  75. struct hostent hostent;
  76. };
  77. #else
  78. struct ghbnctx
  79. {
  80. int h_err;
  81. };
  82. #endif
  83. struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx);
  84. int h_error_ctx (struct ghbnctx *ctx);
  85. void free_ghbnctx (struct ghbnctx *ctx);
  86. #endif