aboutsummaryrefslogtreecommitdiff
path: root/plugins/utils.c
diff options
context:
space:
mode:
authorGravatar Jeremy T. Bouse <undrgrid@users.sourceforge.net> 2003-03-08 02:26:22 +0000
committerGravatar Jeremy T. Bouse <undrgrid@users.sourceforge.net> 2003-03-08 02:26:22 +0000
commit4a95946a9b634513494553808b31372060e3c045 (patch)
tree25a976382e9e4812e565599de93e68cb0b2d0a83 /plugins/utils.c
parentc8ba525d6a1f040cb439f3a963cdb32c36c8f2a8 (diff)
downloadmonitoring-plugins-4a95946a9b634513494553808b31372060e3c045.tar.gz
AF indepedent routines introduced.
Modifed process_request() & my_connect() parameters to make 'proto' type 'int' rather than 'char *' and use IPPROTO_* POSIX values. Removed is_dotted_quad() & my_inet_aton() functions Added is_addr(), is_inet_addr(), is_inet6_addr() and resolve_host_or_addr() functions to check whether it is a valid IP address Modified is_host() to call is_addr() and is_hostname() git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@384 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/utils.c')
-rw-r--r--plugins/utils.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/plugins/utils.c b/plugins/utils.c
index aaa9fe5a..0d250677 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -17,6 +17,8 @@
#include <stdarg.h>
#include <limits.h>
+#include <arpa/inet.h>
+
extern int timeout_interval;
extern const char *progname;
@@ -27,7 +29,10 @@ void terminate (int, const char *fmt, ...);
RETSIGTYPE timeout_alarm_handler (int);
int is_host (char *);
-int is_dotted_quad (char *);
+int is_addr (char *);
+int resolve_host_or_addr (char *, int);
+int is_inet_addr (char *);
+int is_inet6_addr (char *);
int is_hostname (char *);
int is_integer (char *);
@@ -58,7 +63,7 @@ char *strpcat (char *dest, const char *src, const char *str);
#define TXTBLK 128
/* **************************************************************************
- * max_state(STATE_x, STATE_y)
+ /* max_state(STATE_x, STATE_y)
* compares STATE_x to STATE_y and returns result based on the following
* STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL
*
@@ -167,28 +172,50 @@ timeout_alarm_handler (int signo)
int
is_host (char *address)
{
- if (is_dotted_quad (address) || is_hostname (address))
+ if (is_addr (address) || is_hostname (address))
return (TRUE);
+
return (FALSE);
}
int
-is_dotted_quad (char *address)
+is_addr (char *address)
{
- int o1, o2, o3, o4;
- char c[1];
+ if (is_inet_addr (address) || is_inet6_addr (address))
+ return (TRUE);
- if (!address)
- return FALSE;
+ return (FALSE);
+}
- if (sscanf (address, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, c) != 4)
- return FALSE;
- else if (o1 > 255 || o2 > 255 || o3 > 255 || o4 > 255)
- return FALSE;
- else if (o1 < 0 || o2 < 0 || o3 < 0 || o4 < 0)
+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
+ else {
+ freeaddrinfo (res);
return TRUE;
+ }
+}
+
+int
+is_inet_addr (char *address)
+{
+ return resolve_host_or_addr (address, AF_INET);
+}
+
+int
+is_inet6_addr (char *address)
+{
+ return resolve_host_or_addr (address, AF_INET6);
}
/* from RFC-1035
@@ -201,22 +228,7 @@ is_dotted_quad (char *address)
int
is_hostname (char *s1)
{
- if (!s1 || strlen (s1) > 63) {
- return FALSE;
- }
- if (strcspn (s1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") != 0) {
- return FALSE;
- }
- if (strspn (s1, "0123456789-.") == 1) {
- return FALSE;
- }
- while ((s1 = index (s1, '.'))) {
- s1++;
- if (strspn (s1, "0123456789-.") == 1) {
- return FALSE;
- }
- }
- return TRUE;
+ return resolve_host_or_addr (s1, AF_UNSPEC);
}
int