summaryrefslogtreecommitdiffstats
path: root/plugins/netutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 83f8942f..1bb4f076 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -161,6 +161,10 @@ process_request (const char *server_address, int server_port, int proto,
161int 161int
162np_net_connect (const char *host_name, int port, int *sd, int proto) 162np_net_connect (const char *host_name, int port, int *sd, int proto)
163{ 163{
164 /* send back STATE_UNKOWN if there's an error
165 send back STATE_OK if we connect
166 send back STATE_CRITICAL if we can't connect.
167 Let upstream figure out what to send to the user. */
164 struct addrinfo hints; 168 struct addrinfo hints;
165 struct addrinfo *r, *res; 169 struct addrinfo *r, *res;
166 struct sockaddr_un su; 170 struct sockaddr_un su;
@@ -250,16 +254,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
250 else if (was_refused) { 254 else if (was_refused) {
251 switch (econn_refuse_state) { /* a user-defined expected outcome */ 255 switch (econn_refuse_state) { /* a user-defined expected outcome */
252 case STATE_OK: 256 case STATE_OK:
253 case STATE_WARNING: /* user wants WARN or OK on refusal */ 257 case STATE_WARNING: /* user wants WARN or OK on refusal, or... */
254 return econn_refuse_state; 258 case STATE_CRITICAL: /* user did not set econn_refuse_state, or wanted critical */
255 break;
256 case STATE_CRITICAL: /* user did not set econn_refuse_state */
257 if (is_socket) 259 if (is_socket)
258 printf("connect to file socket %s: %s\n", host_name, strerror(errno)); 260 printf("connect to file socket %s: %s\n", host_name, strerror(errno));
259 else 261 else
260 printf("connect to address %s and port %d: %s\n", 262 printf("connect to address %s and port %d: %s\n",
261 host_name, port, strerror(errno)); 263 host_name, port, strerror(errno));
262 return econn_refuse_state; 264 return STATE_CRITICAL;
263 break; 265 break;
264 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */ 266 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
265 return STATE_UNKNOWN; 267 return STATE_UNKNOWN;
@@ -357,20 +359,21 @@ is_addr (const char *address)
357} 359}
358 360
359int 361int
360resolve_host_or_addr (const char *address, int family) 362dns_lookup (const char *in, struct sockaddr_storage *ss, int family)
361{ 363{
362 struct addrinfo hints; 364 struct addrinfo hints;
363 struct addrinfo *res; 365 struct addrinfo *res;
364 int retval; 366 int retval;
365 367
366 memset (&hints, 0, sizeof (hints)); 368 memset (&hints, 0, sizeof(struct addrinfo));
367 hints.ai_family = family; 369 hints.ai_family = family;
368 retval = getaddrinfo (address, NULL, &hints, &res);
369 370
371 retval = getaddrinfo (in, NULL, &hints, &res);
370 if (retval != 0) 372 if (retval != 0)
371 return FALSE; 373 return FALSE;
372 else { 374
373 freeaddrinfo (res); 375 if (ss != NULL)
374 return TRUE; 376 memcpy (ss, res->ai_addr, res->ai_addrlen);
375 } 377 freeaddrinfo (res);
378 return TRUE;
376} 379}