summaryrefslogtreecommitdiffstats
path: root/plugins/check_fping.c
diff options
context:
space:
mode:
authorWilliam <william@blackhats.net.au>2025-04-02 10:50:56 +1000
committerWilliam <william@blackhats.net.au>2025-05-07 13:15:51 +1000
commit58a34245110f12192d3b3e99198086c119a57418 (patch)
tree8d38ee93d3e7292e43c8e8a3889d87c540b97106 /plugins/check_fping.c
parenta1472be88322140cf1f2fc39b9e1b654a86f8155 (diff)
downloadmonitoring-plugins-58a34245110f12192d3b3e99198086c119a57418.tar.gz
Improve logic
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r--plugins/check_fping.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index cf9c2d1c..9dadcec7 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -81,27 +81,61 @@ int main(int argc, char **argv) {
81 char *option_string = ""; 81 char *option_string = "";
82 char *fping_prog = NULL; 82 char *fping_prog = NULL;
83 83
84 /* compose the command */ 84 /* First determine if the target is dualstack or ipv6 only. */
85#ifdef USE_IPV6
86 bool server_is_inet6_addr = is_inet6_addr(server);
87#else
88 bool server_is_inet6_addr = false;
89#endif
90
91 /* PATH_TO_FPING6 implies USE_IPV6 */
85#ifdef PATH_TO_FPING6 92#ifdef PATH_TO_FPING6
86 if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { 93 /*
94 * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack
95 * -> we use ipv6
96 * If the user requested -4 OR the user made no assertion and the address is v4 ONLY
97 * -> we use ipv4
98 */
99 if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) {
87 fping_prog = strdup(PATH_TO_FPING6); 100 fping_prog = strdup(PATH_TO_FPING6);
88 } else { 101 } else {
89 xasprintf(&option_string, "%s-4 ", option_string); 102 xasprintf(&option_string, "%s-4 ", option_string);
90 fping_prog = strdup(PATH_TO_FPING); 103 fping_prog = strdup(PATH_TO_FPING);
91 } 104 }
92#else 105#else
93 if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { 106#ifdef USE_IPV6
94 // -4 / -6 must be set explicitly as when a host has dual stack 107 /*
95 // if we don't specify -4 then fping selects ipv6 which can mess 108 * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack
96 // with some checks. 109 * -> we use ipv6
110 * If the user requested -4 OR the user made no assertion and the address is v4 ONLY
111 * -> we use ipv4
112 */
113 if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) {
97 xasprintf(&option_string, "%s-6 ", option_string); 114 xasprintf(&option_string, "%s-6 ", option_string);
98 } else { 115 } else {
99 xasprintf(&option_string, "%s-4 ", option_string); 116 xasprintf(&option_string, "%s-4 ", option_string);
100 } 117 }
101 118#else
119 /*
120 * If the user requested -6
121 * -> warn that v6 is not available
122 * -> we use ipv4
123 */
124 if (address_family == AF_INET6) {
125 usage4(_("IPv6 support not available"));
126 }
127 /*
128 * Note here we still have to call with -4, else in the case of a dual stacked target
129 * we could potentially silently use ipv6 despite having just warned that it is not available
130 */
131 xasprintf(&option_string, "%s-4 ", option_string);
132 /* end USE_IPV6 */
133#endif
102 fping_prog = strdup(PATH_TO_FPING); 134 fping_prog = strdup(PATH_TO_FPING);
135 /* end PATH_TO_FPING6 */
103#endif 136#endif
104 137
138 /* compose the command */
105 if (config.target_timeout) { 139 if (config.target_timeout) {
106 xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout); 140 xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout);
107 } 141 }