summaryrefslogtreecommitdiffstats
path: root/plugins/gethostbyname.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-01-24 22:47:25 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-01-24 22:47:25 +0000
commitfe856aa957978504137c1d425815d4ed8a22be40 (patch)
treea5bb46ce0e64b2056f75700eadbf27aba7c39418 /plugins/gethostbyname.c
parent210f39bc84cfbb21cd72dc054e43f13815ee0616 (diff)
downloadmonitoring-plugins-fe856aa957978504137c1d425815d4ed8a22be40.tar.gz
Sync with gnulib - lots of extraneous code removed in preference to GNU code
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1580 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/gethostbyname.c')
-rw-r--r--plugins/gethostbyname.c241
1 files changed, 0 insertions, 241 deletions
diff --git a/plugins/gethostbyname.c b/plugins/gethostbyname.c
deleted file mode 100644
index c8f39edc..00000000
--- 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