From 00d58ad187dc9ac57461ec73336b0ee1ec98a5d9 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:29:31 +0200 Subject: check_tcp: Use C99 booleans 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"; #include #ifdef HAVE_SSL -static int check_cert = FALSE; +static bool check_cert = false; static int days_till_exp_warn, days_till_exp_crit; # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) # 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; static int server_port = 0; static char *server_address = NULL; -static int host_specified = FALSE; +static bool host_specified = false; static char *server_send = NULL; static char *server_quit = NULL; static char **server_expect; @@ -88,7 +88,7 @@ static int match_flags = NP_MATCH_EXACT; #ifdef HAVE_SSL static char *sni = NULL; -static int sni_specified = FALSE; +static bool sni_specified = false; #endif #define FLAG_SSL 0x01 @@ -247,7 +247,7 @@ main (int argc, char **argv) #ifdef HAVE_SSL if (flags & FLAG_SSL){ result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); - if (result == STATE_OK && check_cert == TRUE) { + if (result == STATE_OK && check_cert) { result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); } } @@ -378,18 +378,18 @@ main (int argc, char **argv) if(match == NP_MATCH_FAILURE) printf ("|%s", fperfdata ("time", elapsed_time, "s", - (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0, - (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0, - TRUE, 0, - TRUE, socket_timeout) + (flags & FLAG_TIME_WARN ? true : false), 0, + (flags & FLAG_TIME_CRIT ? true : false), 0, + true, 0, + true, socket_timeout) ); else printf("|%s", fperfdata ("time", elapsed_time, "s", - (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time, - (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time, - TRUE, 0, - TRUE, socket_timeout) + (flags & FLAG_TIME_WARN ? true : false), warning_time, + (flags & FLAG_TIME_CRIT ? true : false), critical_time, + true, 0, + true, socket_timeout) ); putchar('\n'); @@ -399,11 +399,9 @@ main (int argc, char **argv) /* process command-line arguments */ -static int -process_arguments (int argc, char **argv) -{ +static int process_arguments (int argc, char **argv) { int c; - int escape = 0; + bool escape = false; char *temp; enum { @@ -492,7 +490,7 @@ process_arguments (int argc, char **argv) #endif break; case 'H': /* hostname */ - host_specified = TRUE; + host_specified = true; server_address = optarg; break; case 'c': /* critical */ @@ -527,7 +525,7 @@ process_arguments (int argc, char **argv) server_port = atoi (optarg); break; case 'E': - escape = 1; + escape = true; break; case 's': if (escape) @@ -601,7 +599,7 @@ process_arguments (int argc, char **argv) usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi (optarg); } - check_cert = TRUE; + check_cert = true; flags |= FLAG_SSL; break; # endif /* USE_OPENSSL */ @@ -617,7 +615,7 @@ process_arguments (int argc, char **argv) case SNI_OPTION: #ifdef HAVE_SSL flags |= FLAG_SSL; - sni_specified = TRUE; + sni_specified = true; sni = optarg; #else die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); @@ -630,15 +628,15 @@ process_arguments (int argc, char **argv) } c = optind; - if(host_specified == FALSE && c < argc) + if(!host_specified && c < argc) server_address = strdup (argv[c++]); if (server_address == NULL) usage4 (_("You must provide a server address")); - else if (server_address[0] != '/' && is_host (server_address) == FALSE) + else if (server_address[0] != '/' && !is_host(server_address)) die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address); - return TRUE; + return OK; } -- cgit v0.10-9-g596f