summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 69b016a..4d1fbf3 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -2,7 +2,7 @@
2 2
3VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t 3VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t
4 4
5INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ 5INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@
6 6
7datadir = @datadir@ 7datadir = @datadir@
8localedir = $(datadir)/locale 8localedir = $(datadir)/locale
@@ -33,7 +33,7 @@ EXTRA_DIST = t utils.c netutils.c sslutils.c popen.c utils.h netutils.h \
33 33
34PLUGINHDRS = common.h 34PLUGINHDRS = common.h
35 35
36BASEOBJS = utils.o ../lib/libnagiosplug.a ../lib/libcoreutils.a 36BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a
37NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) 37NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS)
38SSLOBJS = sslutils.o 38SSLOBJS = sslutils.o
39NETLIBS = $(NETOBJS) $(SOCKETLIBS) 39NETLIBS = $(NETOBJS) $(SOCKETLIBS)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index ee6d0cb..94214ee 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -171,7 +171,6 @@ main (int argc, char **argv)
171 char *helocmd = NULL; 171 char *helocmd = NULL;
172 char *error_msg = NULL; 172 char *error_msg = NULL;
173 struct timeval tv; 173 struct timeval tv;
174 struct hostent *hp;
175 174
176 setlocale (LC_ALL, ""); 175 setlocale (LC_ALL, "");
177 bindtextdomain (PACKAGE, LOCALEDIR); 176 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -191,9 +190,6 @@ main (int argc, char **argv)
191 printf(_("gethostname() failed!\n")); 190 printf(_("gethostname() failed!\n"));
192 return STATE_CRITICAL; 191 return STATE_CRITICAL;
193 } 192 }
194 hp = gethostbyname(localhostname);
195 if(!hp) helocmd = localhostname;
196 else helocmd = hp->h_name;
197 } else { 193 } else {
198 helocmd = localhostname; 194 helocmd = localhostname;
199 } 195 }
@@ -202,6 +198,9 @@ main (int argc, char **argv)
202 else 198 else
203 asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n"); 199 asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n");
204 200
201 if (verbose)
202 printf("HELOCMD: %s", helocmd);
203
205 /* initialize the MAIL command with optional FROM command */ 204 /* initialize the MAIL command with optional FROM command */
206 asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n"); 205 asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
207 206
diff --git a/plugins/common.h b/plugins/common.h
index b335743..69cd800 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -103,18 +103,11 @@
103#include <signal.h> 103#include <signal.h>
104#endif 104#endif
105 105
106/* GNU Libraries */
106#include <getopt.h> 107#include <getopt.h>
107#include <ctype.h> 108#include "vasprintf.h"
108 109#include "snprintf.h"
109#ifdef HAVE_LWRES_NETDB_H 110#include "vsnprintf.h"
110#include <lwres/netdb.h>
111#else
112# if !HAVE_GETADDRINFO
113# include "getaddrinfo.h"
114# else
115# include <netdb.h>
116# endif
117#endif
118 111
119#ifdef HAVE_LOCALE_H 112#ifdef HAVE_LOCALE_H
120#include <locale.h> 113#include <locale.h>
@@ -138,22 +131,6 @@
138# define strtoul(a,b,c) (unsigned long)atol((a)) 131# define strtoul(a,b,c) (unsigned long)atol((a))
139#endif 132#endif
140 133
141#ifndef HAVE_ASPRINTF
142int asprintf(char **strp, const char *fmt, ...);
143#endif
144
145#ifndef HAVE_VASPRINTF
146/* int vasprintf(char **strp, const char *fmt, va_list ap); */
147#endif
148
149#ifndef HAVE_SNPRINTF
150int snprintf(char *str, size_t size, const char *format, ...);
151#endif
152
153#ifndef HAVE_VSNPRINTF
154int vsnprintf(char *str, size_t size, const char *format, va_list ap);
155#endif
156
157/* SSL implementations */ 134/* SSL implementations */
158#ifdef HAVE_GNUTLS_OPENSSL_H 135#ifdef HAVE_GNUTLS_OPENSSL_H
159# include <gnutls/openssl.h> 136# include <gnutls/openssl.h>
diff --git a/plugins/getaddrinfo.c b/plugins/getaddrinfo.c
deleted file mode 100644
index 5697820..0000000
--- a/plugins/getaddrinfo.c
+++ /dev/null
@@ -1,305 +0,0 @@
1/*
2 * This file is part of libESMTP, a library for submission of RFC 2822
3 * formatted electronic mail messages using the SMTP protocol described
4 * in RFC 2821.
5 * Modified by Jeremy T. Bouse for use in Nagios plugins
6 *
7 * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface.
25 *
26 * $Id$
27 */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33/* Need to turn off Posix features in glibc to build this */
34#undef _POSIX_C_SOURCE
35#undef _XOPEN_SOURCE
36
37#include <stdlib.h>
38#include <string.h>
39#include <ctype.h>
40#include <errno.h>
41
42#include <sys/socket.h>
43#include <netinet/in.h>
44#include <arpa/inet.h>
45
46#include <netdb.h>
47
48#include "gethostbyname.h"
49#include "getaddrinfo.h"
50
51static struct addrinfo *
52dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen)
53{
54 struct addrinfo *ret;
55
56 ret = malloc (sizeof (struct addrinfo));
57 if (ret == NULL)
58 return NULL;
59 memcpy (ret, info, sizeof (struct addrinfo));
60 ret->ai_addr = malloc (addrlen);
61 if (ret->ai_addr == NULL)
62 {
63 free (ret);
64 return NULL;
65 }
66 memcpy (ret->ai_addr, addr, addrlen);
67 ret->ai_addrlen = addrlen;
68 return ret;
69}
70
71int
72getaddrinfo (const char *nodename, const char *servname,
73 const struct addrinfo *hints, struct addrinfo **res)
74{
75 struct hostent *hp;
76 struct servent *servent;
77 const char *socktype;
78 int port;
79 struct addrinfo hint, result;
80 struct addrinfo *ai, *sai, *eai;
81 struct ghbnctx ghbnctx;
82 char **addrs;
83 int code;
84
85 memset (&result, 0, sizeof result);
86
87 /* default for hints */
88 if (hints == NULL)
89 {
90 memset (&hint, 0, sizeof hint);
91 hint.ai_family = PF_UNSPEC;
92 hints = &hint;
93 }
94
95 result.ai_socktype = hints->ai_socktype;
96
97 /* Note: maintain port in host byte order to make debugging easier */
98 if (servname != NULL) {
99 if (isdigit (*servname))
100 port = strtol (servname, NULL, 10);
101 else if ((servent = getservbyname (servname, socktype)) != NULL)
102 port = ntohs (servent->s_port);
103 else
104 return EAI_NONAME;
105 }
106
107 /* if nodename == NULL refer to the local host for a client or any
108 for a server */
109 if (nodename == NULL)
110 {
111 struct sockaddr_in sin;
112
113 /* check protocol family is PF_UNSPEC or PF_INET - could try harder
114 for IPv6 but that's more code than I'm prepared to write */
115 if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
116 result.ai_family = AF_INET;
117 else
118 return EAI_FAMILY;
119
120 sin.sin_family = result.ai_family;
121 sin.sin_port = htons (port);
122 if (hints->ai_flags & AI_PASSIVE)
123 sin.sin_addr.s_addr = htonl (INADDR_ANY);
124 else
125 sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
126 /* Duplicate result and addr and return */
127 *res = dup_addrinfo (&result, &sin, sizeof sin);
128 return (*res == NULL) ? EAI_MEMORY : 0;
129 }
130
131 /* If AI_NUMERIC is specified, use inet_addr to translate numbers and
132 dots notation. */
133 if (hints->ai_flags & AI_NUMERICHOST)
134 {
135 struct sockaddr_in sin;
136
137 /* check protocol family is PF_UNSPEC or PF_INET */
138 if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
139 result.ai_family = AF_INET;
140 else
141 return EAI_FAMILY;
142
143 sin.sin_family = result.ai_family;
144 sin.sin_port = htons (port);
145 sin.sin_addr.s_addr = inet_addr (nodename);
146 /* Duplicate result and addr and return */
147 *res = dup_addrinfo (&result, &sin, sizeof sin);
148 return (*res == NULL) ? EAI_MEMORY : 0;
149 }
150
151 errno = 0;
152 hp = gethostbyname_ctx (nodename, &ghbnctx);
153 if (hp == NULL)
154 {
155 if (errno != 0)
156 {
157 free_ghbnctx (&ghbnctx);
158 return EAI_SYSTEM;
159 }
160 code = h_error_ctx (&ghbnctx);
161 switch (code)
162 {
163 case HOST_NOT_FOUND: code = EAI_NODATA; break;
164 case NO_DATA: code = EAI_NODATA; break;
165#if defined(NO_ADDRESS) && NO_ADDRESS != NO_DATA
166 case NO_ADDRESS: code = EAI_NODATA; break;
167#endif
168 case NO_RECOVERY: code = EAI_FAIL; break;
169 case TRY_AGAIN: code = EAI_AGAIN; break;
170 default: code = EAI_FAIL; break;
171 }
172 free_ghbnctx (&ghbnctx);
173 return code;
174 }
175
176 /* Check that the address family is acceptable.
177 */
178 switch (hp->h_addrtype)
179 {
180 case AF_INET:
181 if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET))
182 goto eai_family;
183 break;
184#ifdef USE_IPV6
185 case AF_INET6:
186 if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6))
187 goto eai_family;
188 break;
189#endif
190 default:
191 eai_family:
192 free_ghbnctx (&ghbnctx);
193 return EAI_FAMILY;
194 }
195
196 /* For each element pointed to by hp, create an element in the
197 result linked list. */
198 sai = eai = NULL;
199 for (addrs = hp->h_addr_list; *addrs != NULL; addrs++)
200 {
201 struct sockaddr sa;
202 size_t addrlen;
203
204 sa.sa_family = hp->h_addrtype;
205 switch (hp->h_addrtype)
206 {
207 case AF_INET:
208 ((struct sockaddr_in *) &sa)->sin_port = htons (port);
209 memcpy (&((struct sockaddr_in *) &sa)->sin_addr,
210 *addrs, hp->h_length);
211 addrlen = sizeof (struct sockaddr_in);
212 break;
213#ifdef USE_IPV6
214 case AF_INET6:
215# if SIN6_LEN
216 ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length;
217# endif
218 ((struct sockaddr_in6 *) &sa)->sin6_port = htons (port);
219 memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr,
220 *addrs, hp->h_length);
221 addrlen = sizeof (struct sockaddr_in6);
222 break;
223#endif
224 default:
225 continue;
226 }
227
228 result.ai_family = hp->h_addrtype;
229 ai = dup_addrinfo (&result, &sa, addrlen);
230 if (ai == NULL)
231 {
232 free_ghbnctx (&ghbnctx);
233 freeaddrinfo (sai);
234 return EAI_MEMORY;
235 }
236 if (sai == NULL)
237 sai = ai;
238 else
239 eai->ai_next = ai;
240 eai = ai;
241 }
242
243 if (sai == NULL)
244 {
245 free_ghbnctx (&ghbnctx);
246 return EAI_NODATA;
247 }
248
249 if (hints->ai_flags & AI_CANONNAME)
250 {
251 sai->ai_canonname = malloc (strlen (hp->h_name) + 1);
252 if (sai->ai_canonname == NULL)
253 {
254 free_ghbnctx (&ghbnctx);
255 freeaddrinfo (sai);
256 return EAI_MEMORY;
257 }
258 strcpy (sai->ai_canonname, hp->h_name);
259 }
260
261 free_ghbnctx (&ghbnctx);
262 *res = sai;
263 return 0;
264}
265
266void
267freeaddrinfo (struct addrinfo *ai)
268{
269 struct addrinfo *next;
270
271 while (ai != NULL)
272 {
273 next = ai->ai_next;
274 if (ai->ai_canonname != NULL)
275 free (ai->ai_canonname);
276 if (ai->ai_addr != NULL)
277 free (ai->ai_addr);
278 free (ai);
279 ai = next;
280 }
281}
282
283const char *
284gai_strerror (int ecode)
285{
286 static const char *eai_descr[] =
287 {
288 "no error",
289 "address family for nodename not supported", /* EAI_ADDRFAMILY */
290 "temporary failure in name resolution", /* EAI_AGAIN */
291 "invalid value for ai_flags", /* EAI_BADFLAGS */
292 "non-recoverable failure in name resolution", /* EAI_FAIL */
293 "ai_family not supported", /* EAI_FAMILY */
294 "memory allocation failure", /* EAI_MEMORY */
295 "no address associated with nodename", /* EAI_NODATA */
296 "nodename nor servname provided, or not known", /* EAI_NONAME */
297 "servname not supported for ai_socktype", /* EAI_SERVICE */
298 "ai_socktype not supported", /* EAI_SOCKTYPE */
299 "system error returned in errno", /* EAI_SYSTEM */
300 };
301
302 if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0]))
303 return "unknown error";
304 return eai_descr[ecode];
305}
diff --git a/plugins/getaddrinfo.h b/plugins/getaddrinfo.h
deleted file mode 100644
index d411524..0000000
--- a/plugins/getaddrinfo.h
+++ /dev/null
@@ -1,71 +0,0 @@
1#ifndef _getaddrinfo_h
2#define _getaddrinfo_h
3/*
4 * This file is part of libESMTP, a library for submission of RFC 2822
5 * formatted electronic mail messages using the SMTP protocol described
6 * in RFC 2821.
7 * Modified by Jeremy T. Bouse for use in Nagios plugins
8 *
9 * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26/* Structure and prototypes aken from RFC 2553
27 *
28 * $Id$
29 */
30
31struct addrinfo
32 {
33 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
34 int ai_family; /* PF_xxx */
35 int ai_socktype; /* SOCK_xxx */
36 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
37 size_t ai_addrlen; /* length of ai_addr */
38 char *ai_canonname; /* canonical name for nodename */
39 struct sockaddr *ai_addr; /* binary address */
40 struct addrinfo *ai_next; /* next structure in linked list */
41 };
42
43/* Supposed to be defined in <netdb.h> */
44#define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
45#define AI_CANONNAME 2 /* Request for canonical name. */
46#define AI_NUMERICHOST 4 /* Don't use name resolution. */
47
48/* Supposed to be defined in <netdb.h> */
49#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */
50#define EAI_AGAIN 2 /* temporary failure in name resolution */
51#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
52#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
53#define EAI_FAMILY 5 /* ai_family not supported */
54#define EAI_MEMORY 6 /* memory allocation failure */
55#define EAI_NODATA 7 /* no address associated with nodename */
56#define EAI_NONAME 8 /* nodename nor servname provided, or not known */
57#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
58#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
59#define EAI_SYSTEM 11 /* system error returned in errno */
60
61/* RFC 2553 / Posix resolver */
62int getaddrinfo (const char *nodename, const char *servname,
63 const struct addrinfo *hints, struct addrinfo **res);
64
65/* Free addrinfo structure and associated storage */
66void freeaddrinfo (struct addrinfo *ai);
67
68/* Convert error return from getaddrinfo() to string */
69const char *gai_strerror (int code);
70
71#endif
diff --git a/plugins/gethostbyname.c b/plugins/gethostbyname.c
deleted file mode 100644
index c8f39ed..0000000
--- a/plugins/gethostbyname.c
+++ /dev/null
@@ -1,241 +0,0 @@
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
35#ifdef HAVE_CONFIG_H
36#include <config.h>
37#endif
38
39#define _SVID_SOURCE 1 /* Need this to get gethostbyname_r() */
40
41#include <assert.h>
42
43#include <stdlib.h>
44#include <string.h>
45#include <netdb.h>
46#include <errno.h>
47
48#include "gethostbyname.h"
49
50#if HAVE_GETIPNODEBYNAME
51
52void
53free_ghbnctx (struct ghbnctx *ctx)
54{
55 assert (ctx != NULL);
56
57 if (ctx->hostent != NULL)
58 freehostent (ctx->hostent);
59}
60
61struct hostent *
62gethostbyname_ctx (const char *host, struct ghbnctx *ctx)
63{
64 assert (ctx != NULL);
65
66 memset (ctx, 0, sizeof (struct ghbnctx));
67 ctx->hostent = getipnodebyname (host, AF_UNSPEC, AI_ADDRCONFIG, &ctx->h_err);
68 return ctx->hostent;
69}
70
71int
72h_error_ctx (struct ghbnctx *ctx)
73{
74 assert (ctx != NULL);
75
76 return ctx->h_err;
77}
78
79#elif HAVE_GETHOSTBYNAME_R == 6
80
81void
82free_ghbnctx (struct ghbnctx *ctx)
83{
84 assert (ctx != NULL);
85
86 if (ctx->hostbuf != NULL)
87 free (ctx->hostbuf);
88}
89
90struct hostent *
91gethostbyname_ctx (const char *host, struct ghbnctx *ctx)
92{
93 struct hostent *hp;
94 char *tmp;
95 int err;
96
97 assert (ctx != NULL);
98
99 memset (ctx, 0, sizeof (struct ghbnctx));
100 ctx->hostbuf_len = 2048;
101 if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL)
102 {
103 errno = ENOMEM;
104 return NULL;
105 }
106 while ((err = gethostbyname_r (host,
107 &ctx->hostent, ctx->hostbuf, ctx->hostbuf_len,
108 &hp, &ctx->h_err)) == ERANGE)
109 {
110 ctx->hostbuf_len += 1024;
111 if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL)
112 {
113 errno = ENOMEM;
114 return NULL;
115 }
116 ctx->hostbuf = tmp;
117 }
118 if (err != 0)
119 {
120 errno = err;
121 return NULL;
122 }
123 return hp;
124}
125
126int
127h_error_ctx (struct ghbnctx *ctx)
128{
129 assert (ctx != NULL);
130
131 return ctx->h_err;
132}
133
134#elif HAVE_GETHOSTBYNAME_R == 5
135
136void
137free_ghbnctx (struct ghbnctx *ctx)
138{
139 assert (ctx != NULL);
140
141 if (ctx->hostbuf != NULL)
142 free (ctx->hostbuf);
143}
144
145struct hostent *
146gethostbyname_ctx (const char *host, struct ghbnctx *ctx)
147{
148 struct hostent *hp;
149 char *tmp;
150
151 assert (ctx != NULL);
152
153 memset (ctx, 0, sizeof (struct ghbnctx));
154 ctx->hostbuf_len = 2048;
155 if ((ctx->hostbuf = malloc (ctx->hostbuf_len)) == NULL)
156 {
157 errno = ENOMEM;
158 return NULL;
159 }
160 while ((hp = gethostbyname_r (host, &ctx->hostent,
161 ctx->hostbuf, ctx->hostbuf_len,
162 &ctx->h_err)) == NULL && errno == ERANGE)
163 {
164 ctx->hostbuf_len += 1024;
165 if ((tmp = realloc (ctx->hostbuf, ctx->hostbuf_len)) == NULL)
166 {
167 errno = ENOMEM;
168 return NULL;
169 }
170 ctx->hostbuf = tmp;
171 }
172 return hp;
173}
174
175int
176h_error_ctx (struct ghbnctx *ctx)
177{
178 assert (ctx != NULL);
179
180 return ctx->h_err;
181}
182
183#elif HAVE_GETHOSTBYNAME_R == 3
184
185void
186free_ghbnctx (struct ghbnctx *ctx)
187{
188 assert (ctx != NULL);
189
190 /* FIXME: does this need to do anything? */
191}
192
193struct hostent *
194gethostbyname_ctx (const char *host, struct ghbnctx *ctx)
195{
196 assert (ctx != NULL);
197
198 if (!gethostbyname_r (host, &ctx->hostent, &ctx->hostent_data))
199 {
200 ctx->h_err = h_errno; /* FIXME: is this correct? */
201 return NULL;
202 }
203 return &ctx->hostent;
204}
205
206int
207h_error_ctx (struct ghbnctx *ctx)
208{
209 assert (ctx != NULL);
210
211 return ctx->h_err;
212}
213
214#else
215
216void
217free_ghbnctx (struct ghbnctx *ctx __attribute__ ((unused)))
218{
219 assert (ctx != NULL);
220}
221
222struct hostent *
223gethostbyname_ctx (const char *host, struct ghbnctx *ctx)
224{
225 struct hostent *hp;
226
227 hp = gethostbyname (host);
228 if (hp == NULL)
229 ctx->h_err = h_errno;
230 return hp;
231}
232
233int
234h_error_ctx (struct ghbnctx *ctx)
235{
236 assert (ctx != NULL);
237
238 return ctx->h_err;
239}
240
241#endif
diff --git a/plugins/gethostbyname.h b/plugins/gethostbyname.h
deleted file mode 100644
index d95ab26..0000000
--- a/plugins/gethostbyname.h
+++ /dev/null
@@ -1,115 +0,0 @@
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/*************************************************************************
35 Usage:
36
37 #include <errno.h>
38 #include "gethostbyname.h"
39
40 f ()
41 {
42 struct ghbnctx ctx;
43
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 *************************************************************************/
60
61#ifndef _gethostbyname_h
62#define _gethostbyname_h
63
64#if HAVE_GETIPNODEBYNAME
65
66struct ghbnctx
67 {
68 int h_err;
69 struct hostent *hostent;
70 };
71
72#elif HAVE_GETHOSTBYNAME_R == 6
73
74struct ghbnctx
75 {
76 int h_err;
77 struct hostent hostent;
78 char *hostbuf;
79 size_t hostbuf_len;
80 };
81
82#elif HAVE_GETHOSTBYNAME_R == 5
83
84struct ghbnctx
85 {
86 int h_err;
87 struct hostent hostent;
88 char *hostbuf;
89 int hostbuf_len;
90 };
91
92#elif HAVE_GETHOSTBYNAME_R == 3
93
94struct ghbnctx
95 {
96 int h_err;
97 struct hostent_data hostent_data;
98 struct hostent hostent;
99 };
100
101#else
102
103struct ghbnctx
104 {
105 int h_err;
106 };
107
108#endif
109
110struct hostent *gethostbyname_ctx (const char *host, struct ghbnctx *ctx);
111int h_error_ctx (struct ghbnctx *ctx);
112void free_ghbnctx (struct ghbnctx *ctx);
113
114#endif
115
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 3fc4ef8..b90c5e6 100644
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
@@ -39,6 +39,7 @@
39#include "utils.h" 39#include "utils.h"
40#include <netinet/in.h> 40#include <netinet/in.h>
41#include <arpa/inet.h> 41#include <arpa/inet.h>
42#include "getaddrinfo.h"
42 43
43#ifdef HAVE_SYS_UN_H 44#ifdef HAVE_SYS_UN_H
44# include <sys/un.h> 45# include <sys/un.h>