diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-18 20:46:16 +0200 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-18 20:46:16 +0200 |
commit | a51e8f82e7c5a51893d43c7d00495ceba6a661ab (patch) | |
tree | 4042a9240d695207bd1865dc177d4eb086f0c384 /plugins | |
parent | c2ceefd783043235ac24aa4f529bb42c95df905c (diff) | |
download | monitoring-plugins-a51e8f82e7c5a51893d43c7d00495ceba6a661ab.tar.gz |
plugins/netutils: Use C99 booleans
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/netutils.c | 32 | ||||
-rw-r--r-- | plugins/netutils.h | 6 |
2 files changed, 17 insertions, 21 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c index 1bb4f076..c6af248e 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
@@ -34,7 +34,7 @@ unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | |||
34 | unsigned int socket_timeout_state = STATE_CRITICAL; | 34 | unsigned int socket_timeout_state = STATE_CRITICAL; |
35 | 35 | ||
36 | int econn_refuse_state = STATE_CRITICAL; | 36 | int econn_refuse_state = STATE_CRITICAL; |
37 | int was_refused = FALSE; | 37 | bool was_refused = false; |
38 | #if USE_IPV6 | 38 | #if USE_IPV6 |
39 | int address_family = AF_UNSPEC; | 39 | int address_family = AF_UNSPEC; |
40 | #else | 40 | #else |
@@ -215,14 +215,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) | |||
215 | result = connect (*sd, r->ai_addr, r->ai_addrlen); | 215 | result = connect (*sd, r->ai_addr, r->ai_addrlen); |
216 | 216 | ||
217 | if (result == 0) { | 217 | if (result == 0) { |
218 | was_refused = FALSE; | 218 | was_refused = false; |
219 | break; | 219 | break; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (result < 0) { | 222 | if (result < 0) { |
223 | switch (errno) { | 223 | switch (errno) { |
224 | case ECONNREFUSED: | 224 | case ECONNREFUSED: |
225 | was_refused = TRUE; | 225 | was_refused = true; |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | } | 228 | } |
@@ -246,7 +246,7 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) | |||
246 | } | 246 | } |
247 | result = connect(*sd, (struct sockaddr *)&su, sizeof(su)); | 247 | result = connect(*sd, (struct sockaddr *)&su, sizeof(su)); |
248 | if (result < 0 && errno == ECONNREFUSED) | 248 | if (result < 0 && errno == ECONNREFUSED) |
249 | was_refused = TRUE; | 249 | was_refused = true; |
250 | } | 250 | } |
251 | 251 | ||
252 | if (result == 0) | 252 | if (result == 0) |
@@ -326,13 +326,11 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int | |||
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | int | 329 | bool is_host (const char *address) { |
330 | is_host (const char *address) | ||
331 | { | ||
332 | if (is_addr (address) || is_hostname (address)) | 330 | if (is_addr (address) || is_hostname (address)) |
333 | return (TRUE); | 331 | return (true); |
334 | 332 | ||
335 | return (FALSE); | 333 | return (false); |
336 | } | 334 | } |
337 | 335 | ||
338 | void | 336 | void |
@@ -342,20 +340,18 @@ host_or_die(const char *str) | |||
342 | usage_va(_("Invalid hostname/address - %s"), str); | 340 | usage_va(_("Invalid hostname/address - %s"), str); |
343 | } | 341 | } |
344 | 342 | ||
345 | int | 343 | bool is_addr (const char *address) { |
346 | is_addr (const char *address) | ||
347 | { | ||
348 | #ifdef USE_IPV6 | 344 | #ifdef USE_IPV6 |
349 | if (address_family == AF_INET && is_inet_addr (address)) | 345 | if (address_family == AF_INET && is_inet_addr (address)) |
350 | return TRUE; | 346 | return true; |
351 | else if (address_family == AF_INET6 && is_inet6_addr (address)) | 347 | else if (address_family == AF_INET6 && is_inet6_addr (address)) |
352 | return TRUE; | 348 | return true; |
353 | #else | 349 | #else |
354 | if (is_inet_addr (address)) | 350 | if (is_inet_addr (address)) |
355 | return (TRUE); | 351 | return (true); |
356 | #endif | 352 | #endif |
357 | 353 | ||
358 | return (FALSE); | 354 | return (false); |
359 | } | 355 | } |
360 | 356 | ||
361 | int | 357 | int |
@@ -370,10 +366,10 @@ dns_lookup (const char *in, struct sockaddr_storage *ss, int family) | |||
370 | 366 | ||
371 | retval = getaddrinfo (in, NULL, &hints, &res); | 367 | retval = getaddrinfo (in, NULL, &hints, &res); |
372 | if (retval != 0) | 368 | if (retval != 0) |
373 | return FALSE; | 369 | return false; |
374 | 370 | ||
375 | if (ss != NULL) | 371 | if (ss != NULL) |
376 | memcpy (ss, res->ai_addr, res->ai_addrlen); | 372 | memcpy (ss, res->ai_addr, res->ai_addrlen); |
377 | freeaddrinfo (res); | 373 | freeaddrinfo (res); |
378 | return TRUE; | 374 | return true; |
379 | } | 375 | } |
diff --git a/plugins/netutils.h b/plugins/netutils.h index ea653e72..a95057e0 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -73,8 +73,8 @@ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, | |||
73 | 73 | ||
74 | 74 | ||
75 | /* "is_*" wrapper macros and functions */ | 75 | /* "is_*" wrapper macros and functions */ |
76 | int is_host (const char *); | 76 | bool is_host (const char *); |
77 | int is_addr (const char *); | 77 | bool is_addr (const char *); |
78 | int dns_lookup (const char *, struct sockaddr_storage *, int); | 78 | int dns_lookup (const char *, struct sockaddr_storage *, int); |
79 | void host_or_die(const char *str); | 79 | void host_or_die(const char *str); |
80 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) | 80 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) |
@@ -89,7 +89,7 @@ void host_or_die(const char *str); | |||
89 | extern unsigned int socket_timeout; | 89 | extern unsigned int socket_timeout; |
90 | extern unsigned int socket_timeout_state; | 90 | extern unsigned int socket_timeout_state; |
91 | extern int econn_refuse_state; | 91 | extern int econn_refuse_state; |
92 | extern int was_refused; | 92 | extern bool was_refused; |
93 | extern int address_family; | 93 | extern int address_family; |
94 | 94 | ||
95 | void socket_timeout_alarm_handler (int) __attribute__((noreturn)); | 95 | void socket_timeout_alarm_handler (int) __attribute__((noreturn)); |