diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-18 18:29:31 (GMT) |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-18 18:29:31 (GMT) |
commit | 00d58ad187dc9ac57461ec73336b0ee1ec98a5d9 (patch) | |
tree | 8acb762b565746b4cabe8395de088b1498608b79 /plugins | |
parent | 51db32cc1dab0cecb62484b048b3bdf27fd871af (diff) | |
download | monitoring-plugins-00d58ad187dc9ac57461ec73336b0ee1ec98a5d9.tar.gz |
check_tcp: Use C99 booleans
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_tcp.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 1d307cf..a1a14b4 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
41 | #include <sys/select.h> | 41 | #include <sys/select.h> |
42 | 42 | ||
43 | #ifdef HAVE_SSL | 43 | #ifdef HAVE_SSL |
44 | static int check_cert = FALSE; | 44 | static bool check_cert = false; |
45 | static int days_till_exp_warn, days_till_exp_crit; | 45 | static int days_till_exp_warn, days_till_exp_crit; |
46 | # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 46 | # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
47 | # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | 47 | # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) |
@@ -65,7 +65,7 @@ static int READ_TIMEOUT = 2; | |||
65 | 65 | ||
66 | static int server_port = 0; | 66 | static int server_port = 0; |
67 | static char *server_address = NULL; | 67 | static char *server_address = NULL; |
68 | static int host_specified = FALSE; | 68 | static bool host_specified = false; |
69 | static char *server_send = NULL; | 69 | static char *server_send = NULL; |
70 | static char *server_quit = NULL; | 70 | static char *server_quit = NULL; |
71 | static char **server_expect; | 71 | static char **server_expect; |
@@ -88,7 +88,7 @@ static int match_flags = NP_MATCH_EXACT; | |||
88 | 88 | ||
89 | #ifdef HAVE_SSL | 89 | #ifdef HAVE_SSL |
90 | static char *sni = NULL; | 90 | static char *sni = NULL; |
91 | static int sni_specified = FALSE; | 91 | static bool sni_specified = false; |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | #define FLAG_SSL 0x01 | 94 | #define FLAG_SSL 0x01 |
@@ -247,7 +247,7 @@ main (int argc, char **argv) | |||
247 | #ifdef HAVE_SSL | 247 | #ifdef HAVE_SSL |
248 | if (flags & FLAG_SSL){ | 248 | if (flags & FLAG_SSL){ |
249 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); | 249 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); |
250 | if (result == STATE_OK && check_cert == TRUE) { | 250 | if (result == STATE_OK && check_cert) { |
251 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 251 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
252 | } | 252 | } |
253 | } | 253 | } |
@@ -378,18 +378,18 @@ main (int argc, char **argv) | |||
378 | if(match == NP_MATCH_FAILURE) | 378 | if(match == NP_MATCH_FAILURE) |
379 | printf ("|%s", | 379 | printf ("|%s", |
380 | fperfdata ("time", elapsed_time, "s", | 380 | fperfdata ("time", elapsed_time, "s", |
381 | (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0, | 381 | (flags & FLAG_TIME_WARN ? true : false), 0, |
382 | (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0, | 382 | (flags & FLAG_TIME_CRIT ? true : false), 0, |
383 | TRUE, 0, | 383 | true, 0, |
384 | TRUE, socket_timeout) | 384 | true, socket_timeout) |
385 | ); | 385 | ); |
386 | else | 386 | else |
387 | printf("|%s", | 387 | printf("|%s", |
388 | fperfdata ("time", elapsed_time, "s", | 388 | fperfdata ("time", elapsed_time, "s", |
389 | (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time, | 389 | (flags & FLAG_TIME_WARN ? true : false), warning_time, |
390 | (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time, | 390 | (flags & FLAG_TIME_CRIT ? true : false), critical_time, |
391 | TRUE, 0, | 391 | true, 0, |
392 | TRUE, socket_timeout) | 392 | true, socket_timeout) |
393 | ); | 393 | ); |
394 | 394 | ||
395 | putchar('\n'); | 395 | putchar('\n'); |
@@ -399,11 +399,9 @@ main (int argc, char **argv) | |||
399 | 399 | ||
400 | 400 | ||
401 | /* process command-line arguments */ | 401 | /* process command-line arguments */ |
402 | static int | 402 | static int process_arguments (int argc, char **argv) { |
403 | process_arguments (int argc, char **argv) | ||
404 | { | ||
405 | int c; | 403 | int c; |
406 | int escape = 0; | 404 | bool escape = false; |
407 | char *temp; | 405 | char *temp; |
408 | 406 | ||
409 | enum { | 407 | enum { |
@@ -492,7 +490,7 @@ process_arguments (int argc, char **argv) | |||
492 | #endif | 490 | #endif |
493 | break; | 491 | break; |
494 | case 'H': /* hostname */ | 492 | case 'H': /* hostname */ |
495 | host_specified = TRUE; | 493 | host_specified = true; |
496 | server_address = optarg; | 494 | server_address = optarg; |
497 | break; | 495 | break; |
498 | case 'c': /* critical */ | 496 | case 'c': /* critical */ |
@@ -527,7 +525,7 @@ process_arguments (int argc, char **argv) | |||
527 | server_port = atoi (optarg); | 525 | server_port = atoi (optarg); |
528 | break; | 526 | break; |
529 | case 'E': | 527 | case 'E': |
530 | escape = 1; | 528 | escape = true; |
531 | break; | 529 | break; |
532 | case 's': | 530 | case 's': |
533 | if (escape) | 531 | if (escape) |
@@ -601,7 +599,7 @@ process_arguments (int argc, char **argv) | |||
601 | usage2 (_("Invalid certificate expiration period"), optarg); | 599 | usage2 (_("Invalid certificate expiration period"), optarg); |
602 | days_till_exp_warn = atoi (optarg); | 600 | days_till_exp_warn = atoi (optarg); |
603 | } | 601 | } |
604 | check_cert = TRUE; | 602 | check_cert = true; |
605 | flags |= FLAG_SSL; | 603 | flags |= FLAG_SSL; |
606 | break; | 604 | break; |
607 | # endif /* USE_OPENSSL */ | 605 | # endif /* USE_OPENSSL */ |
@@ -617,7 +615,7 @@ process_arguments (int argc, char **argv) | |||
617 | case SNI_OPTION: | 615 | case SNI_OPTION: |
618 | #ifdef HAVE_SSL | 616 | #ifdef HAVE_SSL |
619 | flags |= FLAG_SSL; | 617 | flags |= FLAG_SSL; |
620 | sni_specified = TRUE; | 618 | sni_specified = true; |
621 | sni = optarg; | 619 | sni = optarg; |
622 | #else | 620 | #else |
623 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | 621 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); |
@@ -630,15 +628,15 @@ process_arguments (int argc, char **argv) | |||
630 | } | 628 | } |
631 | 629 | ||
632 | c = optind; | 630 | c = optind; |
633 | if(host_specified == FALSE && c < argc) | 631 | if(!host_specified && c < argc) |
634 | server_address = strdup (argv[c++]); | 632 | server_address = strdup (argv[c++]); |
635 | 633 | ||
636 | if (server_address == NULL) | 634 | if (server_address == NULL) |
637 | usage4 (_("You must provide a server address")); | 635 | usage4 (_("You must provide a server address")); |
638 | else if (server_address[0] != '/' && is_host (server_address) == FALSE) | 636 | else if (server_address[0] != '/' && !is_host(server_address)) |
639 | die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address); | 637 | die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address); |
640 | 638 | ||
641 | return TRUE; | 639 | return OK; |
642 | } | 640 | } |
643 | 641 | ||
644 | 642 | ||