summaryrefslogtreecommitdiffstats
path: root/plugins/check_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r--plugins/check_tcp.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index d8fc26e..5fe024b 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -54,8 +54,6 @@ static int server_port = 0;
54static char *server_address = NULL; 54static char *server_address = NULL;
55static char *server_send = NULL; 55static char *server_send = NULL;
56static char *server_quit = NULL; 56static char *server_quit = NULL;
57char *lineend = "";
58char *lineendquit = "\r\n";
59static char **server_expect; 57static char **server_expect;
60static size_t server_expect_count = 0; 58static size_t server_expect_count = 0;
61static size_t maxbytes = 0; 59static size_t maxbytes = 0;
@@ -246,6 +244,12 @@ main (int argc, char **argv)
246 } 244 }
247 245
248 if(flags & FLAG_VERBOSE) { 246 if(flags & FLAG_VERBOSE) {
247 if (server_send) {
248 printf("Send string: %s\n", server_send);
249 }
250 if (server_quit) {
251 printf("Quit string: %s\n", server_quit);
252 }
249 printf("server_expect_count: %d\n", (int)server_expect_count); 253 printf("server_expect_count: %d\n", (int)server_expect_count);
250 for(i = 0; i < server_expect_count; i++) 254 for(i = 0; i < server_expect_count; i++)
251 printf("\t%d: %s\n", i, server_expect[i]); 255 printf("\t%d: %s\n", i, server_expect[i]);
@@ -364,6 +368,7 @@ static int
364process_arguments (int argc, char **argv) 368process_arguments (int argc, char **argv)
365{ 369{
366 int c; 370 int c;
371 int escape = 0;
367 372
368 int option = 0; 373 int option = 0;
369 static struct option longopts[] = { 374 static struct option longopts[] = {
@@ -375,7 +380,7 @@ process_arguments (int argc, char **argv)
375 {"timeout", required_argument, 0, 't'}, 380 {"timeout", required_argument, 0, 't'},
376 {"protocol", required_argument, 0, 'P'}, 381 {"protocol", required_argument, 0, 'P'},
377 {"port", required_argument, 0, 'p'}, 382 {"port", required_argument, 0, 'p'},
378 {"lineend", required_argument, 0, 'l'}, 383 {"escape", required_argument, 0, 'E'},
379 {"send", required_argument, 0, 's'}, 384 {"send", required_argument, 0, 's'},
380 {"expect", required_argument, 0, 'e'}, 385 {"expect", required_argument, 0, 'e'},
381 {"maxbytes", required_argument, 0, 'm'}, 386 {"maxbytes", required_argument, 0, 'm'},
@@ -417,7 +422,7 @@ process_arguments (int argc, char **argv)
417 } 422 }
418 423
419 while (1) { 424 while (1) {
420 c = getopt_long (argc, argv, "+hVv46H:l:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", 425 c = getopt_long (argc, argv, "+hVv46EH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
421 longopts, &option); 426 longopts, &option);
422 427
423 if (c == -1 || c == EOF || c == 1) 428 if (c == -1 || c == EOF || c == 1)
@@ -485,30 +490,14 @@ process_arguments (int argc, char **argv)
485 else 490 else
486 server_port = atoi (optarg); 491 server_port = atoi (optarg);
487 break; 492 break;
488 case 'l': 493 case 'E':
489 switch (*optarg) { 494 escape = 1;
490 case 'n':
491 lineend = strdup("\n");
492 lineendquit = lineend;
493 break;
494 case 'r':
495 lineend = strdup("\r");
496 lineendquit = lineend;
497 break;
498 case 'b':
499 lineend = strdup("\r\n");
500 lineendquit = lineend;
501 break;
502 case 'e':
503 lineend = strdup("");
504 lineendquit = lineend;
505 break;
506 default:
507 usage4 (_("Unrecognized option to -l, must be r, n, b or e"));
508 }
509 break; 495 break;
510 case 's': 496 case 's':
511 asprintf(&server_send, "%s%s", optarg, lineend); 497 if (escape)
498 server_send = np_escaped_string(optarg);
499 else
500 asprintf(&server_send, "%s", optarg);
512 break; 501 break;
513 case 'e': /* expect string (may be repeated) */ 502 case 'e': /* expect string (may be repeated) */
514 EXPECT = NULL; 503 EXPECT = NULL;
@@ -525,7 +514,10 @@ process_arguments (int argc, char **argv)
525 else 514 else
526 maxbytes = strtol (optarg, NULL, 0); 515 maxbytes = strtol (optarg, NULL, 0);
527 case 'q': 516 case 'q':
528 asprintf(&server_quit, "%s%s", optarg, lineendquit); 517 if (escape)
518 server_quit = np_escaped_string(optarg);
519 else
520 asprintf(&server_quit, "%s\r\n", optarg);
529 break; 521 break;
530 case 'r': 522 case 'r':
531 if (!strncmp(optarg,"ok",2)) 523 if (!strncmp(optarg,"ok",2))
@@ -604,10 +596,9 @@ print_help (void)
604 printf (_(UT_IPv46)); 596 printf (_(UT_IPv46));
605 597
606 printf (_("\ 598 printf (_("\
607 -l, --lineend=b|e|n|r\n\ 599 -E, --escape\n\
608 Ending on -s and -q strings. b - both: <cr><lf> style, e - empty no\n\ 600 Can use \\n, \\r, \\t or \\ in send or quit string.\n\
609 end, n - newline: newline end, r - return: carriage return end\n\ 601 Default: nothing added to send, \\r\\n added to end of quit\n\
610 Default is \"-l e -s <send> -l b -q <quit>\".\n\
611 -s, --send=STRING\n\ 602 -s, --send=STRING\n\
612 String to send to the server\n\ 603 String to send to the server\n\
613 -e, --expect=STRING\n\ 604 -e, --expect=STRING\n\
@@ -653,6 +644,6 @@ Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
653 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ 644 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
654 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ 645 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
655 [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\ 646 [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
656 [-D <days to cert expiry>] [-S <use SSL>] [-l <n|r|b|e>]\n", progname); 647 [-D <days to cert expiry>] [-S <use SSL>] [-E]\n", progname);
657} 648}
658 649