summaryrefslogtreecommitdiffstats
path: root/web/attachments/135799-nagiosplug-wrapper-macros.diff
blob: ce0a0c5a435539dad6ad46c3432669d5eb8ab0fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
diff -urN ../nagiosplug.orig/plugins/netutils.c ./plugins/netutils.c
--- ../nagiosplug.orig/plugins/netutils.c	2005-01-05 21:53:22.000000000 +0100
+++ ./plugins/netutils.c	2005-05-24 09:25:09.000000000 +0200
@@ -39,7 +39,6 @@
 int was_refused = FALSE;
 int address_family = AF_UNSPEC;
 
-static int my_connect(const char *address, int port, int *sd, int proto);
 /* handles socket timeouts */
 void
 socket_timeout_alarm_handler (int sig)
@@ -53,37 +52,6 @@
 }
 
 
-/* connects to a host on a specified TCP port, sends a string,
-   and gets a response */
-int
-process_tcp_request (const char *server_address, int server_port,
-	const char *send_buffer, char *recv_buffer, int recv_size)
-{
-	int result;
-
-	result = process_request (server_address, server_port,
-			IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
-
-	return result;
-}
-
-
-/* connects to a host on a specified UDP port, sends a string, and gets a
-    response */
-int
-process_udp_request (const char *server_address, int server_port,
-	const char *send_buffer, char *recv_buffer, int recv_size)
-{
-	int result;
-
-	result = process_request (server_address, server_port,
-			IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
-
-	return result;
-}
-
-
-
 /* connects to a host on a specified tcp port, sends a string, and gets a 
 	 response. loops on select-recv until timeout or eof to get all of a 
 	 multi-packet answer */
@@ -163,6 +131,7 @@
 	return result;
 }
 
+
 /* connects to a host on a specified port, sends a string, and gets a 
    response */
 int
@@ -186,32 +155,8 @@
 }
 
 
-/* opens a connection to a remote host/tcp port */
-int
-my_tcp_connect (const char *host_name, int port, int *sd)
-{
-	int result;
-
-	result = my_connect (host_name, port, sd, IPPROTO_TCP);
-
-	return result;
-}
-
-
-/* opens a connection to a remote host/udp port */
-int
-my_udp_connect (const char *host_name, int port, int *sd)
-{
-	int result;
-
-	result = my_connect (host_name, port, sd, IPPROTO_UDP);
-
-	return result;
-}
-
-
 /* opens a tcp or udp connection to a remote host */
-static int
+int
 my_connect (const char *host_name, int port, int *sd, int proto)
 {
 	struct addrinfo hints;
@@ -291,20 +236,6 @@
 
 
 int
-send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
-{
-	return send_request (sd, IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
-}
-
-
-int
-send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
-{
-	return send_request (sd, IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
-}
-
-
-int
 send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)
 {
 	int result = STATE_OK;
@@ -397,28 +328,3 @@
 		return TRUE;
 	}
 }
-
-int
-is_inet_addr (const char *address)
-{
-	return resolve_host_or_addr (address, AF_INET);
-}
-
-#ifdef USE_IPV6
-int
-is_inet6_addr (const char *address)
-{
-	return resolve_host_or_addr (address, AF_INET6);
-}
-#endif
-
-int
-is_hostname (const char *s1)
-{
-#ifdef USE_IPV6
-	return resolve_host_or_addr (s1, address_family);
-#else
-	return resolve_host_or_addr (s1, AF_INET);
-#endif
-}
-
diff -urN ../nagiosplug.orig/plugins/netutils.h ./plugins/netutils.h
--- ../nagiosplug.orig/plugins/netutils.h	2004-12-02 00:54:51.000000000 +0100
+++ ./plugins/netutils.h	2005-05-24 09:25:35.000000000 +0200
@@ -38,30 +38,40 @@
 
 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
 
+/* process_request and wrapper macros */
+#define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
+	process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
+#define process_udp_request(addr, port, sbuf, rbuf, rsize) \
+	process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
 int process_tcp_request2 (const char *address, int port,
   const char *sbuffer, char *rbuffer, int rsize);
-int process_tcp_request (const char *address, int port,
-  const char *sbuffer, char *rbuffer, int rsize);
-int process_udp_request (const char *address, int port,
-  const char *sbuffer, char *rbuffer, int rsize);
 int process_request (const char *address, int port, int proto,
   const char *sbuffer, char *rbuffer, int rsize);
 
-int my_tcp_connect (const char *address, int port, int *sd);
-int my_udp_connect (const char *address, int port, int *sd);
-
-int send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
-int send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
+/* my_connect and wrapper macros */
+#define my_tcp_connect(addr, port, s) my_connect(addr, port, s, IPPROTO_TCP)
+#define my_udp_connect(addr, port, s) my_connect(addr, port, s, IPPROTO_UDP)
+int my_connect(const char *address, int port, int *sd, int proto);
+
+/* send_request and wrapper macros */
+#define send_tcp_request(s, sbuf, rbuf, rsize) \
+	send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
+#define send_udp_request(s, sbuf, rbuf, rsize) \
+	send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
 int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
 
+
+/* "is_*" wrapper macros and functions */
 int is_host (const char *);
 int is_addr (const char *);
 int resolve_host_or_addr (const char *, int);
-int is_inet_addr (const char *);
+#define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
 #ifdef USE_IPV6
-int is_inet6_addr (const char *);
+#  define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
+#  define is_hostname(addr) resolve_host_or_addr(addr, address_family)
+#else
+#  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
 #endif
-int is_hostname (const char *);
 
 extern unsigned int socket_timeout;
 extern int econn_refuse_state;