summaryrefslogtreecommitdiffstats
path: root/plugins/netutils.c
diff options
context:
space:
mode:
authorM. Sean Finney <seanius@users.sourceforge.net>2005-05-24 20:25:19 +0000
committerM. Sean Finney <seanius@users.sourceforge.net>2005-05-24 20:25:19 +0000
commit35f2cfd6e82407eb64e80ef3311fbc1e86829112 (patch)
treef594fa7064ffe9ecb17ada8f479ecc52781e41f1 /plugins/netutils.c
parent9d0badbb5002ae72c5ffba30be371939a30a0f68 (diff)
downloadmonitoring-plugins-35f2cfd6e82407eb64e80ef3311fbc1e86829112.tar.gz
optimizations and cleanup from andreas
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1173 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c98
1 files changed, 2 insertions, 96 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 1231c1ef..e7d5ba78 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -39,7 +39,6 @@ int econn_refuse_state = STATE_CRITICAL;
39int was_refused = FALSE; 39int was_refused = FALSE;
40int address_family = AF_UNSPEC; 40int address_family = AF_UNSPEC;
41 41
42static int my_connect(const char *address, int port, int *sd, int proto);
43/* handles socket timeouts */ 42/* handles socket timeouts */
44void 43void
45socket_timeout_alarm_handler (int sig) 44socket_timeout_alarm_handler (int sig)
@@ -53,37 +52,6 @@ socket_timeout_alarm_handler (int sig)
53} 52}
54 53
55 54
56/* connects to a host on a specified TCP port, sends a string,
57 and gets a response */
58int
59process_tcp_request (const char *server_address, int server_port,
60 const char *send_buffer, char *recv_buffer, int recv_size)
61{
62 int result;
63
64 result = process_request (server_address, server_port,
65 IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
66
67 return result;
68}
69
70
71/* connects to a host on a specified UDP port, sends a string, and gets a
72 response */
73int
74process_udp_request (const char *server_address, int server_port,
75 const char *send_buffer, char *recv_buffer, int recv_size)
76{
77 int result;
78
79 result = process_request (server_address, server_port,
80 IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
81
82 return result;
83}
84
85
86
87/* connects to a host on a specified tcp port, sends a string, and gets a 55/* connects to a host on a specified tcp port, sends a string, and gets a
88 response. loops on select-recv until timeout or eof to get all of a 56 response. loops on select-recv until timeout or eof to get all of a
89 multi-packet answer */ 57 multi-packet answer */
@@ -163,6 +131,7 @@ process_tcp_request2 (const char *server_address, int server_port,
163 return result; 131 return result;
164} 132}
165 133
134
166/* connects to a host on a specified port, sends a string, and gets a 135/* connects to a host on a specified port, sends a string, and gets a
167 response */ 136 response */
168int 137int
@@ -186,32 +155,8 @@ process_request (const char *server_address, int server_port, int proto,
186} 155}
187 156
188 157
189/* opens a connection to a remote host/tcp port */
190int
191my_tcp_connect (const char *host_name, int port, int *sd)
192{
193 int result;
194
195 result = my_connect (host_name, port, sd, IPPROTO_TCP);
196
197 return result;
198}
199
200
201/* opens a connection to a remote host/udp port */
202int
203my_udp_connect (const char *host_name, int port, int *sd)
204{
205 int result;
206
207 result = my_connect (host_name, port, sd, IPPROTO_UDP);
208
209 return result;
210}
211
212
213/* opens a tcp or udp connection to a remote host */ 158/* opens a tcp or udp connection to a remote host */
214static int 159int
215my_connect (const char *host_name, int port, int *sd, int proto) 160my_connect (const char *host_name, int port, int *sd, int proto)
216{ 161{
217 struct addrinfo hints; 162 struct addrinfo hints;
@@ -291,20 +236,6 @@ my_connect (const char *host_name, int port, int *sd, int proto)
291 236
292 237
293int 238int
294send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
295{
296 return send_request (sd, IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
297}
298
299
300int
301send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
302{
303 return send_request (sd, IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
304}
305
306
307int
308send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size) 239send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)
309{ 240{
310 int result = STATE_OK; 241 int result = STATE_OK;
@@ -397,28 +328,3 @@ resolve_host_or_addr (const char *address, int family)
397 return TRUE; 328 return TRUE;
398 } 329 }
399} 330}
400
401int
402is_inet_addr (const char *address)
403{
404 return resolve_host_or_addr (address, AF_INET);
405}
406
407#ifdef USE_IPV6
408int
409is_inet6_addr (const char *address)
410{
411 return resolve_host_or_addr (address, AF_INET6);
412}
413#endif
414
415int
416is_hostname (const char *s1)
417{
418#ifdef USE_IPV6
419 return resolve_host_or_addr (s1, address_family);
420#else
421 return resolve_host_or_addr (s1, AF_INET);
422#endif
423}
424