summaryrefslogtreecommitdiffstats
path: root/plugins/check_tcp.c
diff options
context:
space:
mode:
authorM. Sean Finney <seanius@users.sourceforge.net>2005-05-24 20:25:19 (GMT)
committerM. Sean Finney <seanius@users.sourceforge.net>2005-05-24 20:25:19 (GMT)
commit35f2cfd6e82407eb64e80ef3311fbc1e86829112 (patch)
treef594fa7064ffe9ecb17ada8f479ecc52781e41f1 /plugins/check_tcp.c
parent9d0badbb5002ae72c5ffba30be371939a30a0f68 (diff)
downloadmonitoring-plugins-35f2cfd6e82407eb64e80ef3311fbc1e86829112.tar.gz
optimizations and cleanup from andreas
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1173 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r--plugins/check_tcp.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index fd2fe66..1bf1f4c 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -57,11 +57,7 @@ int connect_SSL (void);
57int check_certificate (X509 **); 57int check_certificate (X509 **);
58#endif 58#endif
59 59
60enum { 60#define MAXBUF 1024
61 TCP_PROTOCOL = 1,
62 UDP_PROTOCOL = 2,
63 MAXBUF = 1024
64};
65 61
66int process_arguments (int, char **); 62int process_arguments (int, char **);
67int my_recv (void); 63int my_recv (void);
@@ -120,7 +116,7 @@ main (int argc, char **argv)
120 SEND = NULL; 116 SEND = NULL;
121 EXPECT = NULL; 117 EXPECT = NULL;
122 QUIT = NULL; 118 QUIT = NULL;
123 PROTOCOL = UDP_PROTOCOL; 119 PROTOCOL = IPPROTO_UDP;
124 PORT = 0; 120 PORT = 0;
125 } 121 }
126 else if (strstr (argv[0], "check_tcp")) { 122 else if (strstr (argv[0], "check_tcp")) {
@@ -129,7 +125,7 @@ main (int argc, char **argv)
129 SEND = NULL; 125 SEND = NULL;
130 EXPECT = NULL; 126 EXPECT = NULL;
131 QUIT = NULL; 127 QUIT = NULL;
132 PROTOCOL = TCP_PROTOCOL; 128 PROTOCOL = IPPROTO_TCP;
133 PORT = 0; 129 PORT = 0;
134 } 130 }
135 else if (strstr (argv[0], "check_ftp")) { 131 else if (strstr (argv[0], "check_ftp")) {
@@ -138,7 +134,7 @@ main (int argc, char **argv)
138 SEND = NULL; 134 SEND = NULL;
139 EXPECT = strdup ("220"); 135 EXPECT = strdup ("220");
140 QUIT = strdup ("QUIT\r\n"); 136 QUIT = strdup ("QUIT\r\n");
141 PROTOCOL = TCP_PROTOCOL; 137 PROTOCOL = IPPROTO_TCP;
142 PORT = 21; 138 PORT = 21;
143 } 139 }
144 else if (strstr (argv[0], "check_smtp")) { 140 else if (strstr (argv[0], "check_smtp")) {
@@ -147,7 +143,7 @@ main (int argc, char **argv)
147 SEND = NULL; 143 SEND = NULL;
148 EXPECT = strdup ("220"); 144 EXPECT = strdup ("220");
149 QUIT = strdup ("QUIT\r\n"); 145 QUIT = strdup ("QUIT\r\n");
150 PROTOCOL = TCP_PROTOCOL; 146 PROTOCOL = IPPROTO_TCP;
151 PORT = 25; 147 PORT = 25;
152 } 148 }
153 else if (strstr (argv[0], "check_pop")) { 149 else if (strstr (argv[0], "check_pop")) {
@@ -156,7 +152,7 @@ main (int argc, char **argv)
156 SEND = NULL; 152 SEND = NULL;
157 EXPECT = strdup ("+OK"); 153 EXPECT = strdup ("+OK");
158 QUIT = strdup ("QUIT\r\n"); 154 QUIT = strdup ("QUIT\r\n");
159 PROTOCOL = TCP_PROTOCOL; 155 PROTOCOL = IPPROTO_TCP;
160 PORT = 110; 156 PORT = 110;
161 } 157 }
162 else if (strstr (argv[0], "check_imap")) { 158 else if (strstr (argv[0], "check_imap")) {
@@ -165,7 +161,7 @@ main (int argc, char **argv)
165 SEND = NULL; 161 SEND = NULL;
166 EXPECT = strdup ("* OK"); 162 EXPECT = strdup ("* OK");
167 QUIT = strdup ("a1 LOGOUT\r\n"); 163 QUIT = strdup ("a1 LOGOUT\r\n");
168 PROTOCOL = TCP_PROTOCOL; 164 PROTOCOL = IPPROTO_TCP;
169 PORT = 143; 165 PORT = 143;
170 } 166 }
171#ifdef HAVE_SSL 167#ifdef HAVE_SSL
@@ -175,7 +171,7 @@ main (int argc, char **argv)
175 SEND=NULL; 171 SEND=NULL;
176 EXPECT = strdup ("* OK"); 172 EXPECT = strdup ("* OK");
177 QUIT = strdup ("a1 LOGOUT\r\n"); 173 QUIT = strdup ("a1 LOGOUT\r\n");
178 PROTOCOL=TCP_PROTOCOL; 174 PROTOCOL=IPPROTO_TCP;
179 use_ssl=TRUE; 175 use_ssl=TRUE;
180 PORT=993; 176 PORT=993;
181 } 177 }
@@ -185,7 +181,7 @@ main (int argc, char **argv)
185 SEND=NULL; 181 SEND=NULL;
186 EXPECT = strdup ("+OK"); 182 EXPECT = strdup ("+OK");
187 QUIT = strdup ("QUIT\r\n"); 183 QUIT = strdup ("QUIT\r\n");
188 PROTOCOL=TCP_PROTOCOL; 184 PROTOCOL=IPPROTO_TCP;
189 use_ssl=TRUE; 185 use_ssl=TRUE;
190 PORT=995; 186 PORT=995;
191 } 187 }
@@ -195,7 +191,7 @@ main (int argc, char **argv)
195 SEND=NULL; 191 SEND=NULL;
196 EXPECT = strdup ("220"); 192 EXPECT = strdup ("220");
197 QUIT = strdup ("QUIT\r\n"); 193 QUIT = strdup ("QUIT\r\n");
198 PROTOCOL=TCP_PROTOCOL; 194 PROTOCOL=IPPROTO_TCP;
199 use_ssl=TRUE; 195 use_ssl=TRUE;
200 PORT=465; 196 PORT=465;
201 } 197 }
@@ -205,7 +201,7 @@ main (int argc, char **argv)
205 SEND = strdup("<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n"); 201 SEND = strdup("<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n");
206 EXPECT = strdup("<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'"); 202 EXPECT = strdup("<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'");
207 QUIT = strdup("</stream:stream>\n"); 203 QUIT = strdup("</stream:stream>\n");
208 PROTOCOL=TCP_PROTOCOL; 204 PROTOCOL=IPPROTO_TCP;
209 use_ssl=TRUE; 205 use_ssl=TRUE;
210 PORT = 5222; 206 PORT = 5222;
211 } 207 }
@@ -219,7 +215,7 @@ main (int argc, char **argv)
219 server_expect = realloc (server_expect, ++server_expect_count); 215 server_expect = realloc (server_expect, ++server_expect_count);
220 asprintf (&server_expect[server_expect_count - 1], "201"); 216 asprintf (&server_expect[server_expect_count - 1], "201");
221 QUIT = strdup("QUIT\r\n"); 217 QUIT = strdup("QUIT\r\n");
222 PROTOCOL = TCP_PROTOCOL; 218 PROTOCOL = IPPROTO_TCP;
223 use_ssl=TRUE; 219 use_ssl=TRUE;
224 PORT = 563; 220 PORT = 563;
225} 221}
@@ -235,7 +231,7 @@ main (int argc, char **argv)
235 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count)); 231 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
236 asprintf (&server_expect[server_expect_count - 1], "201"); 232 asprintf (&server_expect[server_expect_count - 1], "201");
237 asprintf (&QUIT, "QUIT\r\n"); 233 asprintf (&QUIT, "QUIT\r\n");
238 PROTOCOL = TCP_PROTOCOL; 234 PROTOCOL = IPPROTO_TCP;
239 PORT = 119; 235 PORT = 119;
240 } 236 }
241 else { 237 else {
@@ -288,13 +284,7 @@ main (int argc, char **argv)
288 result = connect_SSL (); 284 result = connect_SSL ();
289 else 285 else
290#endif 286#endif
291 { 287 result = my_connect (server_address, server_port, &sd, PROTOCOL);
292 if (PROTOCOL == UDP_PROTOCOL)
293 result = my_udp_connect (server_address, server_port, &sd);
294 else
295 /* default is TCP */
296 result = my_tcp_connect (server_address, server_port, &sd);
297 }
298 288
299 if (result == STATE_CRITICAL) 289 if (result == STATE_CRITICAL)
300 return STATE_CRITICAL; 290 return STATE_CRITICAL;