From a964f87d144b58196838148e7e0806db7e3ae870 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:22:45 +0200 Subject: check_dns: Use C99 booleans diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 7ffce98..7dcec38 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -41,8 +41,8 @@ const char *email = "devel@monitoring-plugins.org"; int process_arguments (int, char **); int validate_arguments (void); -int error_scan (char *, int *); -int ip_match_cidr(const char *, const char *); +int error_scan (char *, bool *); +bool ip_match_cidr(const char *, const char *); unsigned long ip2long(const char *); void print_help (void); void print_usage (void); @@ -51,13 +51,13 @@ void print_usage (void); char query_address[ADDRESS_LENGTH] = ""; char dns_server[ADDRESS_LENGTH] = ""; char ptr_server[ADDRESS_LENGTH] = ""; -int verbose = FALSE; +bool verbose = false; char **expected_address = NULL; int expected_address_cnt = 0; -int expect_nxdomain = FALSE; +bool expect_nxdomain = false; -int expect_authority = FALSE; -int all_match = FALSE; +bool expect_authority = false; +bool all_match = false; thresholds *time_thresholds = NULL; static int @@ -80,15 +80,15 @@ main (int argc, char **argv) int n_addresses = 0; char *msg = NULL; char *temp_buffer = NULL; - int non_authoritative = FALSE; + bool non_authoritative = false; int result = STATE_UNKNOWN; double elapsed_time; long microsec; struct timeval tv; - int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ + bool parse_address = false; /* This flag scans for Address: but only after Name: */ output chld_out, chld_err; size_t i; - int is_nxdomain = FALSE; + int is_nxdomain = false; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -164,8 +164,8 @@ main (int argc, char **argv) /* the server is responding, we just got the host name... */ if (strstr (chld_out.line[i], "Name:")) - parse_address = TRUE; - else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || + parse_address = true; + else if (parse_address && (strstr (chld_out.line[i], "Address:") || strstr (chld_out.line[i], "Addresses:"))) { temp_buffer = index (chld_out.line[i], ':'); temp_buffer++; @@ -184,7 +184,7 @@ main (int argc, char **argv) addresses[n_addresses++] = strdup(temp_buffer); } else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { - non_authoritative = TRUE; + non_authoritative = true; } @@ -298,21 +298,21 @@ main (int argc, char **argv) printf (_(". %s returns %s"), query_address, address); if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) { printf ("|%s\n", fperfdata ("time", elapsed_time, "s", - TRUE, time_thresholds->warning->end, - TRUE, time_thresholds->critical->end, - TRUE, 0, FALSE, 0)); + true, time_thresholds->warning->end, + true, time_thresholds->critical->end, + true, 0, false, 0)); } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) { printf ("|%s\n", fperfdata ("time", elapsed_time, "s", - FALSE, 0, - TRUE, time_thresholds->critical->end, - TRUE, 0, FALSE, 0)); + false, 0, + true, time_thresholds->critical->end, + true, 0, false, 0)); } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) { printf ("|%s\n", fperfdata ("time", elapsed_time, "s", - TRUE, time_thresholds->warning->end, - FALSE, 0, - TRUE, 0, FALSE, 0)); + true, time_thresholds->warning->end, + false, 0, + true, 0, false, 0)); } else - printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); + printf ("|%s\n", fperfdata ("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0)); } else if (result == STATE_WARNING) printf (_("DNS WARNING - %s\n"), @@ -327,15 +327,14 @@ main (int argc, char **argv) return result; } -int -ip_match_cidr(const char *addr, const char *cidr_ro) -{ +bool ip_match_cidr(const char *addr, const char *cidr_ro) { char *subnet, *mask_c, *cidr = strdup(cidr_ro); int mask; subnet = strtok(cidr, "/"); mask_c = strtok(NULL, "\0"); - if (!subnet || !mask_c) - return FALSE; + if (!subnet || !mask_c) { + return false; + } mask = atoi(mask_c); /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ @@ -355,14 +354,14 @@ ip2long(const char* src) { } int -error_scan (char *input_buffer, int *is_nxdomain) +error_scan (char *input_buffer, bool *is_nxdomain) { const int nxdomain = strstr (input_buffer, "Non-existent") || strstr (input_buffer, "** server can't find") || strstr (input_buffer, "** Can't find") || strstr (input_buffer, "NXDOMAIN"); - if (nxdomain) *is_nxdomain = TRUE; + if (nxdomain) *is_nxdomain = true; /* the DNS lookup timed out */ if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || @@ -461,7 +460,7 @@ process_arguments (int argc, char **argv) print_revision (progname, NP_VERSION); exit (STATE_UNKNOWN); case 'v': /* version */ - verbose = TRUE; + verbose = true; break; case 't': /* timeout period */ timeout_interval = atoi (optarg); @@ -508,13 +507,13 @@ process_arguments (int argc, char **argv) } break; case 'n': /* expect NXDOMAIN */ - expect_nxdomain = TRUE; + expect_nxdomain = true; break; case 'A': /* expect authority */ - expect_authority = TRUE; + expect_authority = true; break; case 'L': /* all must match */ - all_match = TRUE; + all_match = true; break; case 'w': warning = optarg; -- cgit v0.10-9-g596f