diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-10 13:40:21 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-10 13:40:21 +0200 |
commit | c7274d56274fa1a38837510b1cbde447e73e9b63 (patch) | |
tree | 4fe23baf3a813a68e5b86e6fe64d36ede53071b1 | |
parent | 0926e73e0e3e125555ca4b06510334f98e57646a (diff) | |
download | monitoring-plugins-c7274d56274fa1a38837510b1cbde447e73e9b63.tar.gz |
netutils.h: clang-format
-rw-r--r-- | plugins/netutils.h | 131 |
1 files changed, 65 insertions, 66 deletions
diff --git a/plugins/netutils.h b/plugins/netutils.h index a95057e0..0ca524f2 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -1,63 +1,64 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring Plugins net utilities include file | 3 | * Monitoring Plugins net utilities include file |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | 6 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) |
7 | * Copyright (c) 2003-2007 Monitoring Plugins Development Team | 7 | * Copyright (c) 2003-2007 Monitoring Plugins Development Team |
8 | * | 8 | * |
9 | * Description: | 9 | * Description: |
10 | * | 10 | * |
11 | * This file contains common include files and function definitions | 11 | * This file contains common include files and function definitions |
12 | * used in many of the plugins. | 12 | * used in many of the plugins. |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | #ifndef _NETUTILS_H_ | 31 | #ifndef _NETUTILS_H_ |
32 | #define _NETUTILS_H_ | 32 | #define _NETUTILS_H_ |
33 | 33 | ||
34 | #include "common.h" | 34 | #include "common.h" |
35 | #include "states.h" | ||
35 | #include "utils.h" | 36 | #include "utils.h" |
36 | #include <netinet/in.h> | 37 | #include <netinet/in.h> |
37 | #include <arpa/inet.h> | 38 | #include <arpa/inet.h> |
38 | #include <netdb.h> | 39 | #include <netdb.h> |
39 | 40 | ||
40 | #ifdef HAVE_SYS_UN_H | 41 | #ifdef HAVE_SYS_UN_H |
41 | # include <sys/un.h> | 42 | # include <sys/un.h> |
42 | # ifndef UNIX_PATH_MAX | 43 | # ifndef UNIX_PATH_MAX |
43 | /* linux uses this, on sun it's hard-coded at 108 without a define, on BSD at 104 */ | 44 | /* linux uses this, on sun it's hard-coded at 108 without a define, on BSD at 104 */ |
44 | # define UNIX_PATH_MAX 104 | 45 | # define UNIX_PATH_MAX 104 |
45 | # endif /* UNIX_PATH_MAX */ | 46 | # endif /* UNIX_PATH_MAX */ |
46 | #endif /* HAVE_SYS_UN_H */ | 47 | #endif /* HAVE_SYS_UN_H */ |
47 | 48 | ||
48 | #ifndef HOST_MAX_BYTES | 49 | #ifndef HOST_MAX_BYTES |
49 | # define HOST_MAX_BYTES 255 | 50 | # define HOST_MAX_BYTES 255 |
50 | #endif | 51 | #endif |
51 | 52 | ||
52 | /* process_request and wrapper macros */ | 53 | /* process_request and wrapper macros */ |
53 | #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \ | 54 | #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \ |
54 | process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize) | 55 | process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize) |
55 | #define process_udp_request(addr, port, sbuf, rbuf, rsize) \ | 56 | #define process_udp_request(addr, port, sbuf, rbuf, rsize) \ |
56 | process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize) | 57 | process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize) |
57 | int process_tcp_request2 (const char *address, int port, | 58 | int process_tcp_request2(const char *address, int port, const char *sbuffer, char *rbuffer, |
58 | const char *sbuffer, char *rbuffer, int rsize); | 59 | int rsize); |
59 | int process_request (const char *address, int port, int proto, | 60 | int process_request(const char *address, int port, int proto, const char *sbuffer, char *rbuffer, |
60 | const char *sbuffer, char *rbuffer, int rsize); | 61 | int rsize); |
61 | 62 | ||
62 | /* my_connect and wrapper macros */ | 63 | /* my_connect and wrapper macros */ |
63 | #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP) | 64 | #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP) |
@@ -65,25 +66,22 @@ int process_request (const char *address, int port, int proto, | |||
65 | int np_net_connect(const char *address, int port, int *sd, int proto); | 66 | int np_net_connect(const char *address, int port, int *sd, int proto); |
66 | 67 | ||
67 | /* send_request and wrapper macros */ | 68 | /* send_request and wrapper macros */ |
68 | #define send_tcp_request(s, sbuf, rbuf, rsize) \ | 69 | #define send_tcp_request(s, sbuf, rbuf, rsize) send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize) |
69 | send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize) | 70 | #define send_udp_request(s, sbuf, rbuf, rsize) send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize) |
70 | #define send_udp_request(s, sbuf, rbuf, rsize) \ | 71 | int send_request(int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size); |
71 | send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize) | ||
72 | int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size); | ||
73 | |||
74 | 72 | ||
75 | /* "is_*" wrapper macros and functions */ | 73 | /* "is_*" wrapper macros and functions */ |
76 | bool is_host (const char *); | 74 | bool is_host(const char *); |
77 | bool is_addr (const char *); | 75 | bool is_addr(const char *); |
78 | int dns_lookup (const char *, struct sockaddr_storage *, int); | 76 | int dns_lookup(const char *, struct sockaddr_storage *, int); |
79 | void host_or_die(const char *str); | 77 | void host_or_die(const char *str); |
80 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) | 78 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) |
81 | #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET) | 79 | #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET) |
82 | #ifdef USE_IPV6 | 80 | #ifdef USE_IPV6 |
83 | # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6) | 81 | # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6) |
84 | # define is_hostname(addr) resolve_host_or_addr(addr, address_family) | 82 | # define is_hostname(addr) resolve_host_or_addr(addr, address_family) |
85 | #else | 83 | #else |
86 | # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET) | 84 | # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET) |
87 | #endif | 85 | #endif |
88 | 86 | ||
89 | extern unsigned int socket_timeout; | 87 | extern unsigned int socket_timeout; |
@@ -92,25 +90,26 @@ extern int econn_refuse_state; | |||
92 | extern bool was_refused; | 90 | extern bool was_refused; |
93 | extern int address_family; | 91 | extern int address_family; |
94 | 92 | ||
95 | void socket_timeout_alarm_handler (int) __attribute__((noreturn)); | 93 | void socket_timeout_alarm_handler(int) __attribute__((noreturn)); |
96 | 94 | ||
97 | /* SSL-Related functionality */ | 95 | /* SSL-Related functionality */ |
98 | #ifdef HAVE_SSL | 96 | #ifdef HAVE_SSL |
99 | # define MP_SSLv2 1 | 97 | # define MP_SSLv2 1 |
100 | # define MP_SSLv3 2 | 98 | # define MP_SSLv3 2 |
101 | # define MP_TLSv1 3 | 99 | # define MP_TLSv1 3 |
102 | # define MP_TLSv1_1 4 | 100 | # define MP_TLSv1_1 4 |
103 | # define MP_TLSv1_2 5 | 101 | # define MP_TLSv1_2 5 |
104 | # define MP_SSLv2_OR_NEWER 6 | 102 | # define MP_SSLv2_OR_NEWER 6 |
105 | # define MP_SSLv3_OR_NEWER 7 | 103 | # define MP_SSLv3_OR_NEWER 7 |
106 | # define MP_TLSv1_OR_NEWER 8 | 104 | # define MP_TLSv1_OR_NEWER 8 |
107 | # define MP_TLSv1_1_OR_NEWER 9 | 105 | # define MP_TLSv1_1_OR_NEWER 9 |
108 | # define MP_TLSv1_2_OR_NEWER 10 | 106 | # define MP_TLSv1_2_OR_NEWER 10 |
109 | /* maybe this could be merged with the above np_net_connect, via some flags */ | 107 | /* maybe this could be merged with the above np_net_connect, via some flags */ |
110 | int np_net_ssl_init(int sd); | 108 | int np_net_ssl_init(int sd); |
111 | int np_net_ssl_init_with_hostname(int sd, char *host_name); | 109 | int np_net_ssl_init_with_hostname(int sd, char *host_name); |
112 | int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int version); | 110 | int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int version); |
113 | int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey); | 111 | int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, |
112 | char *privkey); | ||
114 | void np_net_ssl_cleanup(); | 113 | void np_net_ssl_cleanup(); |
115 | int np_net_ssl_write(const void *buf, int num); | 114 | int np_net_ssl_write(const void *buf, int num); |
116 | int np_net_ssl_read(void *buf, int num); | 115 | int np_net_ssl_read(void *buf, int num); |