diff options
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r-- | plugins/netutils.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c index ce8b428b..926547e4 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
@@ -40,8 +40,10 @@ int was_refused = FALSE; | |||
40 | void | 40 | void |
41 | socket_timeout_alarm_handler (int sig) | 41 | socket_timeout_alarm_handler (int sig) |
42 | { | 42 | { |
43 | 43 | if (sig == SIGALRM) | |
44 | printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout); | 44 | printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout); |
45 | else | ||
46 | printf ("CRITICAL - Abnormal timeout after %d seconds\n", socket_timeout); | ||
45 | 47 | ||
46 | exit (STATE_CRITICAL); | 48 | exit (STATE_CRITICAL); |
47 | } | 49 | } |
@@ -99,7 +101,7 @@ process_tcp_request2 (char *server_address, int server_port, | |||
99 | return STATE_CRITICAL; | 101 | return STATE_CRITICAL; |
100 | 102 | ||
101 | send_result = send (sd, send_buffer, strlen (send_buffer), 0); | 103 | send_result = send (sd, send_buffer, strlen (send_buffer), 0); |
102 | if (send_result != strlen (send_buffer)) { | 104 | if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) { |
103 | printf ("send() failed\n"); | 105 | printf ("send() failed\n"); |
104 | result = STATE_WARNING; | 106 | result = STATE_WARNING; |
105 | } | 107 | } |
@@ -177,7 +179,7 @@ process_request (char *server_address, int server_port, int proto, | |||
177 | return STATE_CRITICAL; | 179 | return STATE_CRITICAL; |
178 | 180 | ||
179 | send_result = send (sd, send_buffer, strlen (send_buffer), 0); | 181 | send_result = send (sd, send_buffer, strlen (send_buffer), 0); |
180 | if (send_result != strlen (send_buffer)) { | 182 | if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) { |
181 | printf ("send() failed\n"); | 183 | printf ("send() failed\n"); |
182 | result = STATE_WARNING; | 184 | result = STATE_WARNING; |
183 | } | 185 | } |
@@ -248,7 +250,6 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
248 | { | 250 | { |
249 | struct addrinfo hints; | 251 | struct addrinfo hints; |
250 | struct addrinfo *res; | 252 | struct addrinfo *res; |
251 | struct addrinfo *ptrp; | ||
252 | char port_str[6]; | 253 | char port_str[6]; |
253 | int result; | 254 | int result; |
254 | 255 | ||
@@ -267,7 +268,7 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
267 | while (res) { | 268 | while (res) { |
268 | /* attempt to create a socket */ | 269 | /* attempt to create a socket */ |
269 | *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ? | 270 | *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ? |
270 | SOCK_DGRAM : SOCK_STREAM, res->ai_protocol); | 271 | SOCK_DGRAM : SOCK_STREAM, res->ai_protocol); |
271 | 272 | ||
272 | if (*sd < 0) { | 273 | if (*sd < 0) { |
273 | printf ("Socket creation failed\n"); | 274 | printf ("Socket creation failed\n"); |
@@ -285,13 +286,13 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
285 | 286 | ||
286 | if (result < 0) { | 287 | if (result < 0) { |
287 | switch (errno) { | 288 | switch (errno) { |
288 | case ECONNREFUSED: | 289 | case ECONNREFUSED: |
289 | switch (econn_refuse_state) { | 290 | switch (econn_refuse_state) { |
290 | case STATE_OK: | 291 | case STATE_OK: |
291 | case STATE_WARNING: | 292 | case STATE_WARNING: |
292 | was_refused = TRUE; | 293 | was_refused = TRUE; |
293 | } | 294 | } |
294 | break; | 295 | break; |
295 | } | 296 | } |
296 | } | 297 | } |
297 | 298 | ||
@@ -314,55 +315,56 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
314 | int | 315 | int |
315 | is_host (char *address) | 316 | is_host (char *address) |
316 | { | 317 | { |
317 | if (is_addr (address) || is_hostname (address)) | 318 | if (is_addr (address) || is_hostname (address)) |
318 | return (TRUE); | 319 | return (TRUE); |
319 | 320 | ||
320 | return (FALSE); | 321 | return (FALSE); |
321 | } | 322 | } |
322 | 323 | ||
323 | int | 324 | int |
324 | is_addr (char *address) | 325 | is_addr (char *address) |
325 | { | 326 | { |
327 | if (is_inet_addr (address)) | ||
328 | return (TRUE); | ||
329 | |||
326 | #ifdef USE_IPV6 | 330 | #ifdef USE_IPV6 |
327 | if (is_inet_addr (address) || is_inet6_addr (address)) | 331 | if (is_inet6_addr (address)) |
328 | #else | 332 | return (TRUE); |
329 | if (is_inet_addr (address)) | ||
330 | #endif | 333 | #endif |
331 | return (TRUE); | ||
332 | 334 | ||
333 | return (FALSE); | 335 | return (FALSE); |
334 | } | 336 | } |
335 | 337 | ||
336 | int | 338 | int |
337 | resolve_host_or_addr (char *address, int family) | 339 | resolve_host_or_addr (char *address, int family) |
338 | { | 340 | { |
339 | struct addrinfo hints; | 341 | struct addrinfo hints; |
340 | struct addrinfo *res; | 342 | struct addrinfo *res; |
341 | int retval; | 343 | int retval; |
342 | 344 | ||
343 | memset (&hints, 0, sizeof (hints)); | 345 | memset (&hints, 0, sizeof (hints)); |
344 | hints.ai_family = family; | 346 | hints.ai_family = family; |
345 | retval = getaddrinfo (address, NULL, &hints, &res); | 347 | retval = getaddrinfo (address, NULL, &hints, &res); |
346 | 348 | ||
347 | if (retval != 0) | 349 | if (retval != 0) |
348 | return FALSE; | 350 | return FALSE; |
349 | else { | 351 | else { |
350 | freeaddrinfo (res); | 352 | freeaddrinfo (res); |
351 | return TRUE; | 353 | return TRUE; |
352 | } | 354 | } |
353 | } | 355 | } |
354 | 356 | ||
355 | int | 357 | int |
356 | is_inet_addr (char *address) | 358 | is_inet_addr (char *address) |
357 | { | 359 | { |
358 | return resolve_host_or_addr (address, AF_INET); | 360 | return resolve_host_or_addr (address, AF_INET); |
359 | } | 361 | } |
360 | 362 | ||
361 | #ifdef USE_IPV6 | 363 | #ifdef USE_IPV6 |
362 | int | 364 | int |
363 | is_inet6_addr (char *address) | 365 | is_inet6_addr (char *address) |
364 | { | 366 | { |
365 | return resolve_host_or_addr (address, AF_INET6); | 367 | return resolve_host_or_addr (address, AF_INET6); |
366 | } | 368 | } |
367 | #endif | 369 | #endif |
368 | 370 | ||
@@ -370,9 +372,9 @@ int | |||
370 | is_hostname (char *s1) | 372 | is_hostname (char *s1) |
371 | { | 373 | { |
372 | #ifdef USE_IPV6 | 374 | #ifdef USE_IPV6 |
373 | return resolve_host_or_addr (s1, AF_UNSPEC); | 375 | return resolve_host_or_addr (s1, AF_UNSPEC); |
374 | #else | 376 | #else |
375 | return resolve_host_or_addr (s1, AF_INET); | 377 | return resolve_host_or_addr (s1, AF_INET); |
376 | #endif | 378 | #endif |
377 | } | 379 | } |
378 | 380 | ||