[monitoring-plugins] check_dns: split multiple IP addresses passed in ...

Jan Wagner git at monitoring-plugins.org
Wed Apr 7 18:10:11 CEST 2021


    Module: monitoring-plugins
    Branch: wip-2.3.1
    Commit: c9fdd1df1795cdcf414b08c08af4d51ec7eaea02
    Author: Rolf Eike Beer <eike at sf-mail.de>
 Committer: Jan Wagner <waja at cyconet.org>
      Date: Mon Nov  2 20:05:56 2020 +0100
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c9fdd1d

check_dns: split multiple IP addresses passed in one -a argument

---

 plugins/check_dns.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index b90f50e..0f2e654 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -473,9 +473,23 @@ process_arguments (int argc, char **argv)
     case 'a': /* expected address */
       if (strlen (optarg) >= ADDRESS_LENGTH)
         die (STATE_UNKNOWN, _("Input buffer overflow\n"));
-      expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
-      expected_address[expected_address_cnt] = strdup(optarg);
-      expected_address_cnt++;
+      if (strchr(optarg, ',') != NULL) {
+	char *comma = strchr(optarg, ',');
+	while (comma != NULL) {
+	  expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
+	  expected_address[expected_address_cnt] = strndup(optarg, comma - optarg);
+	  expected_address_cnt++;
+	  optarg = comma + 1;
+	  comma = strchr(optarg, ',');
+	}
+	expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
+	expected_address[expected_address_cnt] = strdup(optarg);
+	expected_address_cnt++;
+      } else {
+	expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
+	expected_address[expected_address_cnt] = strdup(optarg);
+	expected_address_cnt++;
+      }
       break;
     case 'A': /* expect authority */
       expect_authority = TRUE;



More information about the Commits mailing list