summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1ae5554)
raw | patch | inline | side by side (parent: 1ae5554)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Tue, 18 Feb 2003 22:20:01 +0000 (22:20 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Tue, 18 Feb 2003 22:20:01 +0000 (22:20 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@341 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_tcp.c | patch | blob | history |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 8a42a6439d28fc0b5499a7b789b239b10b54be4a..8a2dcc5c53a14d090c7aa350f075ee64cbbaaf8d 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
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;
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;
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)
}
}
- if (server_quit)
+ if (server_quit != NULL)
#ifdef HAVE_SSL
if (use_ssl) {
SSL_write (ssl, QUIT, strlen (QUIT));
}
#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;
+}