summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-18 20:29:31 +0200
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-18 20:29:31 +0200
commit00d58ad187dc9ac57461ec73336b0ee1ec98a5d9 (patch)
tree8acb762b565746b4cabe8395de088b1498608b79
parent51db32cc1dab0cecb62484b048b3bdf27fd871af (diff)
downloadmonitoring-plugins-00d58ad187dc9ac57461ec73336b0ee1ec98a5d9.tar.gz
check_tcp: Use C99 booleans
-rw-r--r--plugins/check_tcp.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 1d307cf3..a1a14b45 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
44static int check_cert = FALSE; 44static bool check_cert = false;
45static int days_till_exp_warn, days_till_exp_crit; 45static 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
66static int server_port = 0; 66static int server_port = 0;
67static char *server_address = NULL; 67static char *server_address = NULL;
68static int host_specified = FALSE; 68static bool host_specified = false;
69static char *server_send = NULL; 69static char *server_send = NULL;
70static char *server_quit = NULL; 70static char *server_quit = NULL;
71static char **server_expect; 71static char **server_expect;
@@ -88,7 +88,7 @@ static int match_flags = NP_MATCH_EXACT;
88 88
89#ifdef HAVE_SSL 89#ifdef HAVE_SSL
90static char *sni = NULL; 90static char *sni = NULL;
91static int sni_specified = FALSE; 91static 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 */
402static int 402static int process_arguments (int argc, char **argv) {
403process_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