summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_tcp.c62
1 files changed, 29 insertions, 33 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index af318853..c13ac767 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -51,8 +51,8 @@ static int days_till_exp_warn, days_till_exp_crit;
51#endif 51#endif
52 52
53/* int my_recv(char *, size_t); */ 53/* int my_recv(char *, size_t); */
54static int process_arguments(int, char **); 54static int process_arguments(int /*argc*/, char ** /*argv*/);
55void print_help(void); 55static void print_help(void);
56void print_usage(void); 56void print_usage(void);
57 57
58#define EXPECT server_expect[0] 58#define EXPECT server_expect[0]
@@ -99,15 +99,6 @@ static bool sni_specified = false;
99static size_t flags; 99static size_t flags;
100 100
101int main(int argc, char **argv) { 101int main(int argc, char **argv) {
102 int result = STATE_UNKNOWN;
103 char *status = NULL;
104 struct timeval tv;
105 struct timeval timeout;
106 int match = -1;
107 fd_set rfds;
108
109 FD_ZERO(&rfds);
110
111 setlocale(LC_ALL, ""); 102 setlocale(LC_ALL, "");
112 bindtextdomain(PACKAGE, LOCALEDIR); 103 bindtextdomain(PACKAGE, LOCALEDIR);
113 textdomain(PACKAGE); 104 textdomain(PACKAGE);
@@ -202,7 +193,7 @@ int main(int argc, char **argv) {
202 server_port = PORT; 193 server_port = PORT;
203 server_send = SEND; 194 server_send = SEND;
204 server_quit = QUIT; 195 server_quit = QUIT;
205 status = NULL; 196 char *status = NULL;
206 197
207 /* Parse extra opts if any */ 198 /* Parse extra opts if any */
208 argv = np_extra_opts(&argc, argv, progname); 199 argv = np_extra_opts(&argc, argv, progname);
@@ -228,8 +219,10 @@ int main(int argc, char **argv) {
228 alarm(socket_timeout); 219 alarm(socket_timeout);
229 220
230 /* try to connect to the host at the given port number */ 221 /* try to connect to the host at the given port number */
222 struct timeval tv;
231 gettimeofday(&tv, NULL); 223 gettimeofday(&tv, NULL);
232 224
225 int result = STATE_UNKNOWN;
233 result = np_net_connect(server_address, server_port, &sd, PROTOCOL); 226 result = np_net_connect(server_address, server_port, &sd, PROTOCOL);
234 if (result == STATE_CRITICAL) 227 if (result == STATE_CRITICAL)
235 return econn_refuse_state; 228 return econn_refuse_state;
@@ -273,6 +266,10 @@ int main(int argc, char **argv) {
273 /* if(len) later on, we know we have a non-NULL response */ 266 /* if(len) later on, we know we have a non-NULL response */
274 ssize_t len = 0; 267 ssize_t len = 0;
275 268
269 int match = -1;
270 struct timeval timeout;
271 fd_set rfds;
272 FD_ZERO(&rfds);
276 if (server_expect_count) { 273 if (server_expect_count) {
277 ssize_t received = 0; 274 ssize_t received = 0;
278 275
@@ -377,15 +374,10 @@ int main(int argc, char **argv) {
377 374
378/* process command-line arguments */ 375/* process command-line arguments */
379static int process_arguments(int argc, char **argv) { 376static int process_arguments(int argc, char **argv) {
380 int c;
381 bool escape = false;
382 char *temp;
383
384 enum { 377 enum {
385 SNI_OPTION = CHAR_MAX + 1 378 SNI_OPTION = CHAR_MAX + 1
386 }; 379 };
387 380
388 int option = 0;
389 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, 381 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
390 {"critical", required_argument, 0, 'c'}, 382 {"critical", required_argument, 0, 'c'},
391 {"warning", required_argument, 0, 'w'}, 383 {"warning", required_argument, 0, 'w'},
@@ -418,13 +410,13 @@ static int process_arguments(int argc, char **argv) {
418 usage4(_("No arguments found")); 410 usage4(_("No arguments found"));
419 411
420 /* backwards compatibility */ 412 /* backwards compatibility */
421 for (c = 1; c < argc; c++) { 413 for (int i = 1; i < argc; i++) {
422 if (strcmp("-to", argv[c]) == 0) 414 if (strcmp("-to", argv[i]) == 0)
423 strcpy(argv[c], "-t"); 415 strcpy(argv[i], "-t");
424 else if (strcmp("-wt", argv[c]) == 0) 416 else if (strcmp("-wt", argv[i]) == 0)
425 strcpy(argv[c], "-w"); 417 strcpy(argv[i], "-w");
426 else if (strcmp("-ct", argv[c]) == 0) 418 else if (strcmp("-ct", argv[i]) == 0)
427 strcpy(argv[c], "-c"); 419 strcpy(argv[i], "-c");
428 } 420 }
429 421
430 if (!is_option(argv[1])) { 422 if (!is_option(argv[1])) {
@@ -434,13 +426,16 @@ static int process_arguments(int argc, char **argv) {
434 argc--; 426 argc--;
435 } 427 }
436 428
437 while (1) { 429 int option_char;
438 c = getopt_long(argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", longopts, &option); 430 bool escape = false;
431 while (true) {
432 int option = 0;
433 option_char = getopt_long(argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", longopts, &option);
439 434
440 if (c == -1 || c == EOF || c == 1) 435 if (option_char == -1 || option_char == EOF || option_char == 1)
441 break; 436 break;
442 437
443 switch (c) { 438 switch (option_char) {
444 case '?': /* print short usage statement if args not parsable */ 439 case '?': /* print short usage statement if args not parsable */
445 usage5(); 440 usage5();
446 case 'h': /* help */ 441 case 'h': /* help */
@@ -553,9 +548,10 @@ static int process_arguments(int argc, char **argv) {
553 else 548 else
554 usage4(_("Delay must be a positive integer")); 549 usage4(_("Delay must be a positive integer"));
555 break; 550 break;
556 case 'D': /* Check SSL cert validity - days 'til certificate expiration */ 551 case 'D': { /* Check SSL cert validity - days 'til certificate expiration */
557#ifdef HAVE_SSL 552#ifdef HAVE_SSL
558# ifdef USE_OPENSSL /* XXX */ 553# ifdef USE_OPENSSL /* XXX */
554 char *temp;
559 if ((temp = strchr(optarg, ',')) != NULL) { 555 if ((temp = strchr(optarg, ',')) != NULL) {
560 *temp = '\0'; 556 *temp = '\0';
561 if (!is_intnonneg(optarg)) 557 if (!is_intnonneg(optarg))
@@ -574,7 +570,7 @@ static int process_arguments(int argc, char **argv) {
574 } 570 }
575 check_cert = true; 571 check_cert = true;
576 flags |= FLAG_SSL; 572 flags |= FLAG_SSL;
577 break; 573 } break;
578# endif /* USE_OPENSSL */ 574# endif /* USE_OPENSSL */
579#endif 575#endif
580 /* fallthrough if we don't have ssl */ 576 /* fallthrough if we don't have ssl */
@@ -600,9 +596,9 @@ static int process_arguments(int argc, char **argv) {
600 } 596 }
601 } 597 }
602 598
603 c = optind; 599 option_char = optind;
604 if (!host_specified && c < argc) 600 if (!host_specified && option_char < argc)
605 server_address = strdup(argv[c++]); 601 server_address = strdup(argv[option_char++]);
606 602
607 if (server_address == NULL) 603 if (server_address == NULL)
608 usage4(_("You must provide a server address")); 604 usage4(_("You must provide a server address"));