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 *****************************************************************************/
34 /*************************************************************************
35 Usage:
37 #include <errno.h>
38 #include "gethostbyname.h"
40 f ()
41 {
42 struct ghbnctx ctx;
44 errno = 0;
45 hp = gethostbyname_ctx (host, &ctx);
46 if (hp == NULL)
47 {
48 if (errno != 0)
49 handle_value_of_errno (errno);
50 else
51 handle_value_of_h_errno (h_error_ctx (&ctx));
52 }
53 else
54 {
55 ...
56 }
57 free_ghbnctx (&ctx);
58 }
59 *************************************************************************/
61 #ifndef _gethostbyname_h
62 #define _gethostbyname_h
64 #if HAVE_GETIPNODEBYNAME
66 struct ghbnctx
67 {
68 int h_err;
69 struct hostent *hostent;
70 };
72 #elif HAVE_GETHOSTBYNAME_R == 6
74 struct ghbnctx
75 {
76 int h_err;
77 struct hostent hostent;
78 char *hostbuf;
79 size_t hostbuf_len;
80 };
82 #elif HAVE_GETHOSTBYNAME_R == 5
84 struct ghbnctx
85 {
86 int h_err;
87 struct hostent hostent;
88 char *hostbuf;
89 int hostbuf_len;
90 };
92 #elif HAVE_GETHOSTBYNAME_R == 3
94 struct ghbnctx
95 {
96 int h_err;
97 struct hostent_data hostent_data;
98 struct hostent hostent;
99 };
101 #else
103 struct ghbnctx
104 {
105 int h_err;
106 };
108 #endif
110 struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx);
111 int h_error_ctx (struct ghbnctx *ctx);
112 void free_ghbnctx (struct ghbnctx *ctx);
114 #endif