gethostbyname.h 2.4 KB

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