summaryrefslogtreecommitdiffstats
path: root/plugins/utils.c
diff options
context:
space:
mode:
authorJeremy T. Bouse <undrgrid@users.sourceforge.net>2003-03-08 02:26:22 (GMT)
committerJeremy T. Bouse <undrgrid@users.sourceforge.net>2003-03-08 02:26:22 (GMT)
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 aaa9fe5..0d25067 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -17,6 +17,8 @@
17#include <stdarg.h> 17#include <stdarg.h>
18#include <limits.h> 18#include <limits.h>
19 19
20#include <arpa/inet.h>
21
20extern int timeout_interval; 22extern int timeout_interval;
21extern const char *progname; 23extern const char *progname;
22 24
@@ -27,7 +29,10 @@ void terminate (int, const char *fmt, ...);
27RETSIGTYPE timeout_alarm_handler (int); 29RETSIGTYPE timeout_alarm_handler (int);
28 30
29int is_host (char *); 31int is_host (char *);
30int is_dotted_quad (char *); 32int is_addr (char *);
33int resolve_host_or_addr (char *, int);
34int is_inet_addr (char *);
35int is_inet6_addr (char *);
31int is_hostname (char *); 36int is_hostname (char *);
32 37
33int is_integer (char *); 38int is_integer (char *);
@@ -58,7 +63,7 @@ char *strpcat (char *dest, const char *src, const char *str);
58#define TXTBLK 128 63#define TXTBLK 128
59 64
60/* ************************************************************************** 65/* **************************************************************************
61 * max_state(STATE_x, STATE_y) 66 /* max_state(STATE_x, STATE_y)
62 * compares STATE_x to STATE_y and returns result based on the following 67 * compares STATE_x to STATE_y and returns result based on the following
63 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL 68 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL
64 * 69 *
@@ -167,28 +172,50 @@ timeout_alarm_handler (int signo)
167int 172int
168is_host (char *address) 173is_host (char *address)
169{ 174{
170 if (is_dotted_quad (address) || is_hostname (address)) 175 if (is_addr (address) || is_hostname (address))
171 return (TRUE); 176 return (TRUE);
177
172 return (FALSE); 178 return (FALSE);
173} 179}
174 180
175int 181int
176is_dotted_quad (char *address) 182is_addr (char *address)
177{ 183{
178 int o1, o2, o3, o4; 184 if (is_inet_addr (address) || is_inet6_addr (address))
179 char c[1]; 185 return (TRUE);
180 186
181 if (!address) 187 return (FALSE);
182 return FALSE; 188}
183 189
184 if (sscanf (address, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, c) != 4) 190int
185 return FALSE; 191resolve_host_or_addr (char *address, int family)
186 else if (o1 > 255 || o2 > 255 || o3 > 255 || o4 > 255) 192{
187 return FALSE; 193 struct addrinfo hints;
188 else if (o1 < 0 || o2 < 0 || o3 < 0 || o4 < 0) 194 struct addrinfo *res;
195 int retval;
196
197 memset (&hints, 0, sizeof (hints));
198 hints.ai_family = family;
199 retval = getaddrinfo (address, NULL, &hints, &res);
200
201 if (retval != 0)
189 return FALSE; 202 return FALSE;
190 else 203 else {
204 freeaddrinfo (res);
191 return TRUE; 205 return TRUE;
206 }
207}
208
209int
210is_inet_addr (char *address)
211{
212 return resolve_host_or_addr (address, AF_INET);
213}
214
215int
216is_inet6_addr (char *address)
217{
218 return resolve_host_or_addr (address, AF_INET6);
192} 219}
193 220
194/* from RFC-1035 221/* from RFC-1035
@@ -201,22 +228,7 @@ is_dotted_quad (char *address)
201int 228int
202is_hostname (char *s1) 229is_hostname (char *s1)
203{ 230{
204 if (!s1 || strlen (s1) > 63) { 231 return resolve_host_or_addr (s1, AF_UNSPEC);
205 return FALSE;
206 }
207 if (strcspn (s1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") != 0) {
208 return FALSE;
209 }
210 if (strspn (s1, "0123456789-.") == 1) {
211 return FALSE;
212 }
213 while ((s1 = index (s1, '.'))) {
214 s1++;
215 if (strspn (s1, "0123456789-.") == 1) {
216 return FALSE;
217 }
218 }
219 return TRUE;
220} 232}
221 233
222int 234int