summaryrefslogtreecommitdiffstats
path: root/plugins/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/utils.c')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 4234c43..b3348d6 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -32,6 +32,8 @@
32#include "netutils.h" 32#include "netutils.h"
33 33
34int socket_timeout = DEFAULT_SOCKET_TIMEOUT; 34int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
35int econn_refuse_state = STATE_CRITICAL;
36int was_refused = FALSE;
35 37
36/* handles socket timeouts */ 38/* handles socket timeouts */
37void 39void
@@ -275,8 +277,22 @@ my_connect (char *host_name, int port, int *sd, int proto)
275 /* attempt to open a connection */ 277 /* attempt to open a connection */
276 result = connect (*sd, res->ai_addr, res->ai_addrlen); 278 result = connect (*sd, res->ai_addr, res->ai_addrlen);
277 279
278 if (result == 0) 280 if (result == 0) {
281 was_refused = FALSE;
279 break; 282 break;
283 }
284
285 if (result < 0) {
286 switch (errno) {
287 case ECONNREFUSED:
288 switch (econn_refuse_state) {
289 case STATE_OK:
290 case STATE_WARNING:
291 was_refused = TRUE;
292 }
293 break;
294 }
295 }
280 296
281 close (*sd); 297 close (*sd);
282 res = res->ai_next; 298 res = res->ai_next;
@@ -286,6 +302,8 @@ my_connect (char *host_name, int port, int *sd, int proto)
286 302
287 if (result == 0) 303 if (result == 0)
288 return STATE_OK; 304 return STATE_OK;
305 else if (was_refused)
306 return econn_refuse_state;
289 else { 307 else {
290 printf ("%s\n", strerror(errno)); 308 printf ("%s\n", strerror(errno));
291 return STATE_CRITICAL; 309 return STATE_CRITICAL;