diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-02-18 22:20:01 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-02-18 22:20:01 +0000 |
commit | 2bd8a33c8d801fba8df8eb96c106a67c110126e6 (patch) | |
tree | 5a02f81919bc8a3213450d858d2a4543e1a176cb /plugins/check_tcp.c | |
parent | 1ae5554699c9dd0e64c69ca2668fd76a92bc51ae (diff) | |
download | monitoring-plugins-2bd8a33c8d801fba8df8eb96c106a67c110126e6.tar.gz |
failed if header was more than 1023 bytes
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@341 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_tcp.c')
-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; int connect_SSL (void); #endif -#define TCP_PROTOCOL 1 -#define UDP_PROTOCOL 2 +enum { + TCP_PROTOCOL = 1, + UDP_PROTOCOL = 2, + MAXBUF = 1024 +}; int process_arguments (int, char **); void print_usage (void); void print_help (void); +int my_recv (void); char *progname = "check_tcp"; char *SERVICE = NULL; @@ -91,13 +95,13 @@ double elapsed_time = 0; int verbose = FALSE; int use_ssl = FALSE; int sd = 0; +char *buffer = ""; int main (int argc, char **argv) { int result; int i; - char *buffer = ""; char *status = ""; struct timeval tv; @@ -248,15 +252,15 @@ main (int argc, char **argv) if (server_send || server_expect_count > 0) { - buffer = malloc (MAX_INPUT_BUFFER); + buffer = malloc (MAXBUF); + memset (buffer, '\0', MAXBUF); /* watch for the expect string */ -#ifdef HAVE_SSL - if (use_ssl && SSL_read (ssl, buffer, MAX_INPUT_BUFFER - 1) > 0) + while ((i = my_recv ()) > 0) { + buffer[i] = '\0'; asprintf (&status, "%s%s", status, buffer); - else -#endif - if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) > 0) - asprintf (&status, "%s%s", status, buffer); + if (buffer[i-2] == '\r' && buffer[i-1] == '\n') + break; + } /* return a CRITICAL status if we couldn't read any data */ if (status == NULL) @@ -279,7 +283,7 @@ main (int argc, char **argv) } } - if (server_quit) + if (server_quit != NULL) #ifdef HAVE_SSL if (use_ssl) { SSL_write (ssl, QUIT, strlen (QUIT)); @@ -572,3 +576,23 @@ connect_SSL (void) } #endif + + +int +my_recv (void) +{ + int i; + +#ifdef HAVE_SSL + if (use_ssl) { + i = SSL_read (ssl, buffer, MAXBUF - 1); + } + else { +#endif + i = read (sd, buffer, MAXBUF - 1); +#ifdef HAVE_SSL + } +#endif + + return i; +} |