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 @@ | |||
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 | ||
37 | extern int socket_timeout; | 34 | int socket_timeout = DEFAULT_SOCKET_TIMEOUT; |
38 | RETSIGTYPE socket_timeout_alarm_handler (int); | ||
39 | |||
40 | int process_tcp_request2 (char *, int, char *, char *, int); | ||
41 | int process_tcp_request (char *, int, char *, char *, int); | ||
42 | int process_udp_request (char *, int, char *, char *, int); | ||
43 | int process_request (char *, int, int, char *, char *, int); | ||
44 | |||
45 | int my_tcp_connect (char *, int, int *); | ||
46 | int my_udp_connect (char *, int, int *); | ||
47 | int my_connect (char *, int, int *, int); | ||
48 | 35 | ||
49 | /* handles socket timeouts */ | 36 | /* handles socket timeouts */ |
50 | void | 37 | void |
@@ -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 | |||
295 | int | ||
296 | is_host (char *address) | ||
297 | { | ||
298 | if (is_addr (address) || is_hostname (address)) | ||
299 | return (TRUE); | ||
300 | |||
301 | return (FALSE); | ||
302 | } | ||
303 | |||
304 | int | ||
305 | is_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 | |||
317 | int | ||
318 | resolve_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 | |||
336 | int | ||
337 | is_inet_addr (char *address) | ||
338 | { | ||
339 | return resolve_host_or_addr (address, AF_INET); | ||
340 | } | ||
341 | |||
342 | #ifdef USE_IPV6 | ||
343 | int | ||
344 | is_inet6_addr (char *address) | ||
345 | { | ||
346 | return resolve_host_or_addr (address, AF_INET6); | ||
347 | } | ||
348 | #endif | ||
349 | |||
350 | int | ||
351 | is_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 | |||