diff options
author | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | 2003-03-15 01:25:35 +0000 |
---|---|---|
committer | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | 2003-03-15 01:25:35 +0000 |
commit | 11b35b92e3195d230bef359f6a0679ae4414716b (patch) | |
tree | f4911e5804c1f3037dcf63bbbf0b823c5ac19e5f /plugins/netutils.c | |
parent | 6cf5fc3c74c0bdfef6c4cc1b627578378ad3a407 (diff) | |
download | monitoring-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.c | 83 |
1 files changed, 68 insertions, 15 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c index c0e82dad..4234c436 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c @@ -29,22 +29,9 @@ * ****************************************************************************/ -#include "config.h" -#include "common.h" -#include <netinet/in.h> -#include <arpa/inet.h> +#include "netutils.h" -extern int socket_timeout; -RETSIGTYPE socket_timeout_alarm_handler (int); - -int process_tcp_request2 (char *, int, char *, char *, int); -int process_tcp_request (char *, int, char *, char *, int); -int process_udp_request (char *, int, char *, char *, int); -int process_request (char *, int, int, char *, char *, int); - -int my_tcp_connect (char *, int, int *); -int my_udp_connect (char *, int, int *); -int my_connect (char *, int, int *, int); +int socket_timeout = DEFAULT_SOCKET_TIMEOUT; /* handles socket timeouts */ void @@ -304,3 +291,69 @@ my_connect (char *host_name, int port, int *sd, int proto) return STATE_CRITICAL; } } + +int +is_host (char *address) +{ + if (is_addr (address) || is_hostname (address)) + return (TRUE); + + return (FALSE); +} + +int +is_addr (char *address) +{ +#ifdef USE_IPV6 + if (is_inet_addr (address) || is_inet6_addr (address)) +#else + if (is_inet_addr (address)) +#endif + return (TRUE); + + return (FALSE); +} + +int +resolve_host_or_addr (char *address, int family) +{ + struct addrinfo hints; + struct addrinfo *res; + int retval; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = family; + retval = getaddrinfo (address, NULL, &hints, &res); + + if (retval != 0) + return FALSE; + else { + freeaddrinfo (res); + return TRUE; + } +} + +int +is_inet_addr (char *address) +{ + return resolve_host_or_addr (address, AF_INET); +} + +#ifdef USE_IPV6 +int +is_inet6_addr (char *address) +{ + return resolve_host_or_addr (address, AF_INET6); +} +#endif + +int +is_hostname (char *s1) +{ +#ifdef USE_IPV6 + return resolve_host_or_addr (s1, AF_UNSPEC); +#else + return resolve_host_or_addr (s1, AF_INET); +#endif +} + |