summaryrefslogtreecommitdiffstats
path: root/plugins/netutils.c
diff options
context:
space:
mode:
authorStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2004-12-01 08:28:36 (GMT)
committerStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2004-12-01 08:28:36 (GMT)
commitdf11705edb0dc42b30d625081d43c4378dbe95b1 (patch)
tree4a7aa9eb78a0a32176352d13a19dd6ebf7d12ecf /plugins/netutils.c
parent68ecdb70054dffaf0732016795e9735b19350b5d (diff)
downloadmonitoring-plugins-df11705edb0dc42b30d625081d43c4378dbe95b1.tar.gz
1075725: patch to my_connect() to deal with SEGV if connect fails
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@960 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index c99983f..aee53d3 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -213,7 +213,7 @@ static int
213my_connect (const char *host_name, int port, int *sd, int proto) 213my_connect (const char *host_name, int port, int *sd, int proto)
214{ 214{
215 struct addrinfo hints; 215 struct addrinfo hints;
216 struct addrinfo *res; 216 struct addrinfo *res, *res0;
217 char port_str[6]; 217 char port_str[6];
218 int result; 218 int result;
219 219
@@ -223,13 +223,14 @@ my_connect (const char *host_name, int port, int *sd, int proto)
223 hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM; 223 hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
224 224
225 snprintf (port_str, sizeof (port_str), "%d", port); 225 snprintf (port_str, sizeof (port_str), "%d", port);
226 result = getaddrinfo (host_name, port_str, &hints, &res); 226 result = getaddrinfo (host_name, port_str, &hints, &res0);
227 227
228 if (result != 0) { 228 if (result != 0) {
229 printf ("%s\n", gai_strerror (result)); 229 printf ("%s\n", gai_strerror (result));
230 return STATE_UNKNOWN; 230 return STATE_UNKNOWN;
231 } 231 }
232 else { 232 else {
233 res = res0;
233 while (res) { 234 while (res) {
234 /* attempt to create a socket */ 235 /* attempt to create a socket */
235 *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ? 236 *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
@@ -260,7 +261,7 @@ my_connect (const char *host_name, int port, int *sd, int proto)
260 close (*sd); 261 close (*sd);
261 res = res->ai_next; 262 res = res->ai_next;
262 } 263 }
263 freeaddrinfo (res); 264 freeaddrinfo (res0);
264 } 265 }
265 266
266 if (result == 0) 267 if (result == 0)