Code

More internationalization work
[nagiosplug.git] / plugins / gethostbyname.h
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  */
24 /*************************************************************************
25    Usage:
27    #include <errno.h>
28    #include "gethostbyname.h"
30    f ()
31    {
32      struct ghbnctx ctx;
34      errno = 0;
35      hp = gethostbyname_ctx (host, &ctx);
36      if (hp == NULL)
37        {
38          if (errno != 0)
39            handle_value_of_errno (errno);
40          else
41            handle_value_of_h_errno (h_error_ctx (&ctx));
42        }
43      else
44        {
45          ...
46        }
47      free_ghbnctx (&ctx);
48    }
49  *************************************************************************/
51 #ifndef _gethostbyname_h
52 #define _gethostbyname_h
54 #if HAVE_GETIPNODEBYNAME
56 struct ghbnctx
57   {
58     int h_err;
59     struct hostent *hostent;
60   };
62 #elif HAVE_GETHOSTBYNAME_R == 6
64 struct ghbnctx
65   {
66     int h_err;
67     struct hostent hostent;
68     char *hostbuf;
69     size_t hostbuf_len;
70   };
72 #elif HAVE_GETHOSTBYNAME_R == 5
74 struct ghbnctx
75   {
76     int h_err;
77     struct hostent hostent;
78     char *hostbuf;
79     int hostbuf_len;
80   };
82 #elif HAVE_GETHOSTBYNAME_R == 3
84 struct ghbnctx
85   {
86     int h_err;
87     struct hostent_data hostent_data;
88     struct hostent hostent;
89   };
91 #else
93 struct ghbnctx
94   {
95     int h_err;
96   };
98 #endif
100 struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx);
101 int h_error_ctx (struct ghbnctx *ctx);
102 void free_ghbnctx (struct ghbnctx *ctx);
104 #endif