summaryrefslogtreecommitdiffstats
path: root/plugins/netutils.c
diff options
context:
space:
mode:
authorJeremy T. Bouse <undrgrid@users.sourceforge.net>2003-03-15 01:25:35 (GMT)
committerJeremy T. Bouse <undrgrid@users.sourceforge.net>2003-03-15 01:25:35 (GMT)
commit11b35b92e3195d230bef359f6a0679ae4414716b (patch)
treef4911e5804c1f3037dcf63bbbf0b823c5ac19e5f /plugins/netutils.c
parent6cf5fc3c74c0bdfef6c4cc1b627578378ad3a407 (diff)
downloadmonitoring-plugins-11b35b92e3195d230bef359f6a0679ae4414716b.tar.gz
Spent the day working on backwards compatability using getaddrinfo()
Moved getaddrinfo.? and gethostbyname.? from lib/ to plugins/ due to problems with compiling into the libnagiosplug.a as it required linking against socket libraries which are unneeded except for network based plugins. This code should hopefully happily work for all systems and has been tested prior to commit on Debian GNU/Linux, SPARC Solaris 7 and SPARC Solaris 9. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@424 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c83
1 files changed, 68 insertions, 15 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index c0e82da..4234c43 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -29,22 +29,9 @@
29* 29*
30****************************************************************************/ 30****************************************************************************/
31 31
32#include "config.h" 32#include "netutils.h"
33#include "common.h"
34#include <netinet/in.h>
35#include <arpa/inet.h>
36 33
37extern int socket_timeout; 34int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
38RETSIGTYPE socket_timeout_alarm_handler (int);
39
40int process_tcp_request2 (char *, int, char *, char *, int);
41int process_tcp_request (char *, int, char *, char *, int);
42int process_udp_request (char *, int, char *, char *, int);
43int process_request (char *, int, int, char *, char *, int);
44
45int my_tcp_connect (char *, int, int *);
46int my_udp_connect (char *, int, int *);
47int my_connect (char *, int, int *, int);
48 35
49/* handles socket timeouts */ 36/* handles socket timeouts */
50void 37void
@@ -304,3 +291,69 @@ my_connect (char *host_name, int port, int *sd, int proto)
304 return STATE_CRITICAL; 291 return STATE_CRITICAL;
305 } 292 }
306} 293}
294
295int
296is_host (char *address)
297{
298 if (is_addr (address) || is_hostname (address))
299 return (TRUE);
300
301 return (FALSE);
302}
303
304int
305is_addr (char *address)
306{
307#ifdef USE_IPV6
308 if (is_inet_addr (address) || is_inet6_addr (address))
309#else
310 if (is_inet_addr (address))
311#endif
312 return (TRUE);
313
314 return (FALSE);
315}
316
317int
318resolve_host_or_addr (char *address, int family)
319{
320 struct addrinfo hints;
321 struct addrinfo *res;
322 int retval;
323
324 memset (&hints, 0, sizeof (hints));
325 hints.ai_family = family;
326 retval = getaddrinfo (address, NULL, &hints, &res);
327
328 if (retval != 0)
329 return FALSE;
330 else {
331 freeaddrinfo (res);
332 return TRUE;
333 }
334}
335
336int
337is_inet_addr (char *address)
338{
339 return resolve_host_or_addr (address, AF_INET);
340}
341
342#ifdef USE_IPV6
343int
344is_inet6_addr (char *address)
345{
346 return resolve_host_or_addr (address, AF_INET6);
347}
348#endif
349
350int
351is_hostname (char *s1)
352{
353#ifdef USE_IPV6
354 return resolve_host_or_addr (s1, AF_UNSPEC);
355#else
356 return resolve_host_or_addr (s1, AF_INET);
357#endif
358}
359