diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_tcp.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 8a42a643..8a2dcc5c 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
| @@ -57,12 +57,16 @@ SSL *ssl; | |||
| 57 | int connect_SSL (void); | 57 | int connect_SSL (void); |
| 58 | #endif | 58 | #endif |
| 59 | 59 | ||
| 60 | #define TCP_PROTOCOL 1 | 60 | enum { |
| 61 | #define UDP_PROTOCOL 2 | 61 | TCP_PROTOCOL = 1, |
| 62 | UDP_PROTOCOL = 2, | ||
| 63 | MAXBUF = 1024 | ||
| 64 | }; | ||
| 62 | 65 | ||
| 63 | int process_arguments (int, char **); | 66 | int process_arguments (int, char **); |
| 64 | void print_usage (void); | 67 | void print_usage (void); |
| 65 | void print_help (void); | 68 | void print_help (void); |
| 69 | int my_recv (void); | ||
| 66 | 70 | ||
| 67 | char *progname = "check_tcp"; | 71 | char *progname = "check_tcp"; |
| 68 | char *SERVICE = NULL; | 72 | char *SERVICE = NULL; |
| @@ -91,13 +95,13 @@ double elapsed_time = 0; | |||
| 91 | int verbose = FALSE; | 95 | int verbose = FALSE; |
| 92 | int use_ssl = FALSE; | 96 | int use_ssl = FALSE; |
| 93 | int sd = 0; | 97 | int sd = 0; |
| 98 | char *buffer = ""; | ||
| 94 | 99 | ||
| 95 | int | 100 | int |
| 96 | main (int argc, char **argv) | 101 | main (int argc, char **argv) |
| 97 | { | 102 | { |
| 98 | int result; | 103 | int result; |
| 99 | int i; | 104 | int i; |
| 100 | char *buffer = ""; | ||
| 101 | char *status = ""; | 105 | char *status = ""; |
| 102 | struct timeval tv; | 106 | struct timeval tv; |
| 103 | 107 | ||
| @@ -248,15 +252,15 @@ main (int argc, char **argv) | |||
| 248 | 252 | ||
| 249 | if (server_send || server_expect_count > 0) { | 253 | if (server_send || server_expect_count > 0) { |
| 250 | 254 | ||
| 251 | buffer = malloc (MAX_INPUT_BUFFER); | 255 | buffer = malloc (MAXBUF); |
| 256 | memset (buffer, '\0', MAXBUF); | ||
| 252 | /* watch for the expect string */ | 257 | /* watch for the expect string */ |
| 253 | #ifdef HAVE_SSL | 258 | while ((i = my_recv ()) > 0) { |
| 254 | if (use_ssl && SSL_read (ssl, buffer, MAX_INPUT_BUFFER - 1) > 0) | 259 | buffer[i] = '\0'; |
| 255 | asprintf (&status, "%s%s", status, buffer); | 260 | asprintf (&status, "%s%s", status, buffer); |
| 256 | else | 261 | if (buffer[i-2] == '\r' && buffer[i-1] == '\n') |
| 257 | #endif | 262 | break; |
| 258 | if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) > 0) | 263 | } |
| 259 | asprintf (&status, "%s%s", status, buffer); | ||
| 260 | 264 | ||
| 261 | /* return a CRITICAL status if we couldn't read any data */ | 265 | /* return a CRITICAL status if we couldn't read any data */ |
| 262 | if (status == NULL) | 266 | if (status == NULL) |
| @@ -279,7 +283,7 @@ main (int argc, char **argv) | |||
| 279 | } | 283 | } |
| 280 | } | 284 | } |
| 281 | 285 | ||
| 282 | if (server_quit) | 286 | if (server_quit != NULL) |
| 283 | #ifdef HAVE_SSL | 287 | #ifdef HAVE_SSL |
| 284 | if (use_ssl) { | 288 | if (use_ssl) { |
| 285 | SSL_write (ssl, QUIT, strlen (QUIT)); | 289 | SSL_write (ssl, QUIT, strlen (QUIT)); |
| @@ -572,3 +576,23 @@ connect_SSL (void) | |||
| 572 | } | 576 | } |
| 573 | #endif | 577 | #endif |
| 574 | 578 | ||
| 579 | |||
| 580 | |||
| 581 | int | ||
| 582 | my_recv (void) | ||
| 583 | { | ||
| 584 | int i; | ||
| 585 | |||
| 586 | #ifdef HAVE_SSL | ||
| 587 | if (use_ssl) { | ||
| 588 | i = SSL_read (ssl, buffer, MAXBUF - 1); | ||
| 589 | } | ||
| 590 | else { | ||
| 591 | #endif | ||
| 592 | i = read (sd, buffer, MAXBUF - 1); | ||
| 593 | #ifdef HAVE_SSL | ||
| 594 | } | ||
| 595 | #endif | ||
| 596 | |||
| 597 | return i; | ||
| 598 | } | ||
