summaryrefslogtreecommitdiffstats
path: root/web/attachments/258859-check_dns.c.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/258859-check_dns.c.patch')
-rw-r--r--web/attachments/258859-check_dns.c.patch97
1 files changed, 97 insertions, 0 deletions
diff --git a/web/attachments/258859-check_dns.c.patch b/web/attachments/258859-check_dns.c.patch
new file mode 100644
index 0000000..256624f
--- /dev/null
+++ b/web/attachments/258859-check_dns.c.patch
@@ -0,0 +1,97 @@
1--- check_dns.c 2007-01-29 08:46:41.000000000 +1100
2+++ check_dns-patched.c 2007-11-26 21:31:23.000000000 +1100
3@@ -62,6 +62,9 @@
4 int expect_authority = FALSE;
5 thresholds *time_thresholds = NULL;
6
7+#define IPV4_SIZE 16*sizeof(char)
8+int order_results = FALSE;
9+
10 int
11 main (int argc, char **argv)
12 {
13@@ -178,6 +181,56 @@
14 _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),
15 NSLOOKUP_COMMAND);
16
17+ /* Order the results from DNS server */
18+ if (order_results) {
19+ int num_result = 1; /* No commas? only one address */
20+ int i = 0;
21+ char *ipv4_sort = NULL;
22+ char *pstrtmp;
23+ char *pstrtok;
24+
25+ pstrtmp = strchr(address, ',');
26+ while (pstrtmp) {
27+ num_result++;
28+ pstrtmp += sizeof(char);
29+ pstrtmp = strchr(pstrtmp, ',');
30+ }
31+
32+ if (num_result > 1) {
33+ ipv4_sort = malloc(IPV4_SIZE*num_result);
34+ if (NULL == ipv4_sort)
35+ die (STATE_UNKNOWN,
36+ _("DNS UNKNOWN - Failed allocating %d bytes for ordering results\n"),
37+ IPV4_SIZE*num_result);
38+
39+ memset(ipv4_sort, 0, IPV4_SIZE*num_result);
40+ pstrtmp = strdup(address);
41+ pstrtok = strtok(pstrtmp, ",");
42+ i = 0;
43+ while (pstrtok) {
44+ strncpy(ipv4_sort+(i*IPV4_SIZE), pstrtok, IPV4_SIZE);
45+ pstrtok = strtok(NULL, ",");
46+ i++;
47+ }
48+ free(pstrtmp);
49+
50+ qsort(ipv4_sort, num_result, IPV4_SIZE, strcmp);
51+
52+ pstrtmp = address;
53+ for (i = 0; i < num_result; i++) {
54+ strcpy(pstrtmp, ipv4_sort+(i*IPV4_SIZE));
55+ pstrtmp += (strlen(pstrtmp));
56+ if (i+1 < num_result) {
57+ *pstrtmp = ',';
58+ pstrtmp += sizeof(char);
59+ }
60+ *pstrtmp = '\0';
61+ }
62+
63+ free(ipv4_sort);
64+ }
65+ }
66+
67 /* compare to expected address */
68 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
69 result = STATE_CRITICAL;
70@@ -316,7 +369,7 @@
71 strcpy (argv[c], "-t");
72
73 while (1) {
74- c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index);
75+ c = getopt_long (argc, argv, "hVvAot:H:s:r:a:w:c:", long_opts, &opt_index);
76
77 if (c == -1 || c == EOF)
78 break;
79@@ -331,6 +384,9 @@
80 case 'v': /* version */
81 verbose = TRUE;
82 break;
83+ case 'o':
84+ order_results = TRUE;
85+ break;
86 case 't': /* timeout period */
87 timeout_interval = atoi (optarg);
88 break;
89@@ -431,6 +487,8 @@
90 printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with ."));
91 printf (" -A, --expect-authority\n");
92 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
93+ printf (" -o\n");
94+ printf (" %s\n", _("Order the results from DNS server. Useful for round-robind setups."));
95 printf (" -w, --warning=seconds\n");
96 printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
97 printf (" -c, --critical=seconds\n");