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 | |
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
-rw-r--r-- | configure.in | 7 | ||||
-rw-r--r-- | lib/Makefile.am | 6 | ||||
-rw-r--r-- | plugins/Makefile.am | 53 | ||||
-rw-r--r-- | plugins/getaddrinfo.c (renamed from lib/getaddrinfo.c) | 27 | ||||
-rw-r--r-- | plugins/getaddrinfo.h (renamed from lib/getaddrinfo.h) | 1 | ||||
-rw-r--r-- | plugins/gethostbyname.c (renamed from lib/gethostbyname.c) | 0 | ||||
-rw-r--r-- | plugins/gethostbyname.h (renamed from lib/gethostbyname.h) | 0 | ||||
-rw-r--r-- | plugins/netutils.c | 83 | ||||
-rw-r--r-- | plugins/netutils.h | 13 | ||||
-rw-r--r-- | plugins/utils.c | 81 | ||||
-rw-r--r-- | plugins/utils.h | 8 |
11 files changed, 123 insertions, 156 deletions
diff --git a/configure.in b/configure.in index ec3606e1..eea01da4 100644 --- a/configure.in +++ b/configure.in | |||
@@ -386,7 +386,7 @@ else | |||
386 | if test x$enable_emulate_getaddrinfo != xyes ; then | 386 | if test x$enable_emulate_getaddrinfo != xyes ; then |
387 | AC_MSG_ERROR([getaddrinfo not found: try --with-lwres or --enable-emulate-getaddrinfo]) | 387 | AC_MSG_ERROR([getaddrinfo not found: try --with-lwres or --enable-emulate-getaddrinfo]) |
388 | fi | 388 | fi |
389 | LIBOBJS="$LIBOBJS getaddrinfo.o" | 389 | EXTRA_NETOBJS="$EXTRA_NETOBJS getaddrinfo.o" |
390 | fi | 390 | fi |
391 | 391 | ||
392 | if test x"$enable_emulate_getaddrinfo" != xno ; then | 392 | if test x"$enable_emulate_getaddrinfo" != xno ; then |
@@ -414,7 +414,8 @@ if test x"$enable_emulate_getaddrinfo" != xno ; then | |||
414 | AC_SEARCH_LIBS(gethostbyname, resolv bind nsl, , | 414 | AC_SEARCH_LIBS(gethostbyname, resolv bind nsl, , |
415 | [AC_MSG_ERROR([cannot find gethostbyname])]) | 415 | [AC_MSG_ERROR([cannot find gethostbyname])]) |
416 | fi | 416 | fi |
417 | LIBOBJS="$LIBOBJS gethostbyname.o" | 417 | EXTRA_NETOBJS="$EXTRA_NETOBJS gethostbyname.o" |
418 | AC_DEFINE(EMULATE_GETADDRINFO,1,[Define if emulating getaddrinfo]) | ||
418 | 419 | ||
419 | fi | 420 | fi |
420 | 421 | ||
@@ -1451,7 +1452,7 @@ AC_TRY_COMPILE([#ifdef __STDC__ | |||
1451 | [NEED_VA_LIST=-DNEED_VA_LIST AC_SUBST(NEED_VA_LIST) AC_MSG_RESULT(no)]) | 1452 | [NEED_VA_LIST=-DNEED_VA_LIST AC_SUBST(NEED_VA_LIST) AC_MSG_RESULT(no)]) |
1452 | 1453 | ||
1453 | AC_SUBST(EXTRAS) | 1454 | AC_SUBST(EXTRAS) |
1454 | AC_SUBST(LIBOBJS) | 1455 | AC_SUBST(EXTRA_NETOBJS) |
1455 | AC_SUBST(DEPLIBS) | 1456 | AC_SUBST(DEPLIBS) |
1456 | 1457 | ||
1457 | AC_DEFINE_UNQUOTED(PACKAGE_VERSION,"${VERSION}",[package version]) | 1458 | AC_DEFINE_UNQUOTED(PACKAGE_VERSION,"${VERSION}",[package version]) |
diff --git a/lib/Makefile.am b/lib/Makefile.am index b24bc407..9a26e419 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -2,12 +2,8 @@ | |||
2 | 2 | ||
3 | noinst_LIBRARIES = libnagiosplug.a | 3 | noinst_LIBRARIES = libnagiosplug.a |
4 | 4 | ||
5 | noinst_HEADERS = getopt.h getaddrinfo.h gethostbyname.h | 5 | noinst_HEADERS = getopt.h |
6 | 6 | ||
7 | libnagiosplug_a_SOURCES = getopt.c getopt1.c getloadavg.c snprintf.c | 7 | libnagiosplug_a_SOURCES = getopt.c getopt1.c getloadavg.c snprintf.c |
8 | 8 | ||
9 | libnagiosplug_a_DEPENDENCIES = @LIBOBJS@ | ||
10 | |||
11 | INCLUDES = -I$(srcdir) | 9 | INCLUDES = -I$(srcdir) |
12 | |||
13 | EXTRA_DIST = getaddrinfo.c gethostbyname.c | ||
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2524e1ac..a884b451 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -14,14 +14,15 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | |||
14 | check_swap check_fping check_ldap check_game check_dig \ | 14 | check_swap check_fping check_ldap check_game check_dig \ |
15 | check_nagios check_by_ssh check_dns check_nt | 15 | check_nagios check_by_ssh check_dns check_nt |
16 | 16 | ||
17 | check_tcp_programs = check_ftp check_imap check_nntp check_pop | 17 | check_tcp_programs = check_ftp check_imap check_nntp check_pop check_udp2 |
18 | 18 | ||
19 | EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h | 19 | EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h \ |
20 | getaddrinfo.c getaddrinfo.h gethostbyname.c gethostbyname.h | ||
20 | 21 | ||
21 | PLUGINHDRS = common.h config.h | 22 | PLUGINHDRS = common.h config.h |
22 | 23 | ||
23 | BASEOBJS = utils.o ../lib/libnagiosplug.a | 24 | BASEOBJS = utils.o ../lib/libnagiosplug.a |
24 | NETOBJS = netutils.o $(BASEOBJS) | 25 | NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) |
25 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | 26 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) |
26 | 27 | ||
27 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) | 28 | TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) |
@@ -36,27 +37,27 @@ AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@ | |||
36 | ############################################################################## | 37 | ############################################################################## |
37 | # the actual targets | 38 | # the actual targets |
38 | 39 | ||
39 | check_dig_LDADD = $(BASEOBJS) popen.o | 40 | check_dig_LDADD = $(NETLIBS) popen.o |
40 | check_disk_LDADD = $(BASEOBJS) popen.o | 41 | check_disk_LDADD = $(BASEOBJS) popen.o |
41 | check_dns_LDADD = $(BASEOBJS) popen.o | 42 | check_dns_LDADD = $(NETLIBS) popen.o |
42 | check_dummy_LDADD = $(BASEOBJS) | 43 | check_dummy_LDADD = $(BASEOBJS) |
43 | check_fping_LDADD = $(BASEOBJS) popen.o | 44 | check_fping_LDADD = $(NETLIBS) popen.o |
44 | check_game_LDADD = $(BASEOBJS) | 45 | check_game_LDADD = $(BASEOBJS) |
45 | check_http_LDADD = $(NETLIBS) $(SSLLIBS) | 46 | check_http_LDADD = $(NETLIBS) $(SSLLIBS) |
46 | check_hpjd_LDADD = $(BASEOBJS) popen.o | 47 | check_hpjd_LDADD = $(NETLIBS) popen.o |
47 | check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS) | 48 | check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS) |
48 | check_load_LDADD = $(BASEOBJS) popen.o | 49 | check_load_LDADD = $(BASEOBJS) popen.o |
49 | check_mrtg_LDADD = $(BASEOBJS) | 50 | check_mrtg_LDADD = $(BASEOBJS) |
50 | check_mrtgtraf_LDADD = $(BASEOBJS) | 51 | check_mrtgtraf_LDADD = $(BASEOBJS) |
51 | check_mysql_LDADD = $(BASEOBJS) $(MYSQLLIBS) | 52 | check_mysql_LDADD = $(NETLIBS) $(MYSQLLIBS) |
52 | check_nagios_LDADD = $(BASEOBJS) popen.o | 53 | check_nagios_LDADD = $(BASEOBJS) popen.o |
53 | check_nt_LDADD = $(NETLIBS) | 54 | check_nt_LDADD = $(NETLIBS) |
54 | check_nwstat_LDADD = $(NETLIBS) | 55 | check_nwstat_LDADD = $(NETLIBS) |
55 | check_overcr_LDADD = $(NETLIBS) | 56 | check_overcr_LDADD = $(NETLIBS) |
56 | check_pgsql_LDADD = $(BASEOBJS) $(PGLIBS) | 57 | check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) |
57 | check_ping_LDADD = $(BASEOBJS) popen.o | 58 | check_ping_LDADD = $(NETLIBS) popen.o |
58 | check_procs_LDADD = $(BASEOBJS) popen.o | 59 | check_procs_LDADD = $(BASEOBJS) popen.o |
59 | check_radius_LDADD = $(BASEOBJS) $(RADIUSLIBS) | 60 | check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) |
60 | check_real_LDADD = $(NETLIBS) | 61 | check_real_LDADD = $(NETLIBS) |
61 | check_snmp_LDADD = $(BASEOBJS) popen.o | 62 | check_snmp_LDADD = $(BASEOBJS) popen.o |
62 | check_smtp_LDADD = $(NETLIBS) | 63 | check_smtp_LDADD = $(NETLIBS) |
@@ -68,31 +69,31 @@ check_udp_LDADD = $(NETLIBS) | |||
68 | check_ups_LDADD = $(NETLIBS) | 69 | check_ups_LDADD = $(NETLIBS) |
69 | check_users_LDADD = $(BASEOBJS) popen.o | 70 | check_users_LDADD = $(BASEOBJS) popen.o |
70 | check_vsz_LDADD = $(BASEOBJS) popen.o | 71 | check_vsz_LDADD = $(BASEOBJS) popen.o |
71 | check_by_ssh_LDADD = $(BASEOBJS) popen.o | 72 | check_by_ssh_LDADD = $(NETLIBS) popen.o |
72 | negate_LDADD = $(BASEOBJS) popen.o | 73 | negate_LDADD = $(BASEOBJS) popen.o |
73 | urlize_LDADD = $(BASEOBJS) popen.o | 74 | urlize_LDADD = $(BASEOBJS) popen.o |
74 | 75 | ||
75 | check_dig_DEPENDENCIES = check_dig.c $(BASEOBJS) popen.o $(DEPLIBS) | 76 | check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) popen.o $(DEPLIBS) |
76 | check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) | 77 | check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) |
77 | check_dns_DEPENDENCIES = check_dns.c $(BASEOBJS) popen.o $(DEPLIBS) | 78 | check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) popen.o $(DEPLIBS) |
78 | check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS) | 79 | check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS) |
79 | check_fping_DEPENDENCIES = check_fping.c $(BASEOBJS) popen.o $(DEPLIBS) | 80 | check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS) |
80 | check_game_DEPENDENCIES = check_game.c $(DEPLIBS) | 81 | check_game_DEPENDENCIES = check_game.c $(DEPLIBS) |
81 | check_http_DEPENDENCIES = check_http.c $(NETOBJS) $(DEPLIBS) | 82 | check_http_DEPENDENCIES = check_http.c $(NETOBJS) $(DEPLIBS) |
82 | check_hpjd_DEPENDENCIES = check_hpjd.c $(BASEOBJS) popen.o $(DEPLIBS) | 83 | check_hpjd_DEPENDENCIES = check_hpjd.c $(NETOBJS) popen.o $(DEPLIBS) |
83 | check_ldap_DEPENDENCIES = check_ldap.c $(NETOBJS) $(DEPLIBS) | 84 | check_ldap_DEPENDENCIES = check_ldap.c $(NETOBJS) $(DEPLIBS) |
84 | check_load_DEPENDENCIES = check_load.c $(BASEOBJS) popen.o $(DEPLIBS) | 85 | check_load_DEPENDENCIES = check_load.c $(BASEOBJS) popen.o $(DEPLIBS) |
85 | check_mrtg_DEPENDENCIES = check_mrtg.c $(DEPLIBS) | 86 | check_mrtg_DEPENDENCIES = check_mrtg.c $(DEPLIBS) |
86 | check_mrtgtraf_DEPENDENCIES = check_mrtgtraf.c $(DEPLIBS) | 87 | check_mrtgtraf_DEPENDENCIES = check_mrtgtraf.c $(DEPLIBS) |
87 | check_mysql_DEPENDENCIES = check_mysql.c $(DEPLIBS) | 88 | check_mysql_DEPENDENCIES = check_mysql.c $(NETOBJS) $(DEPLIBS) |
88 | check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) popen.o $(DEPLIBS) | 89 | check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) popen.o $(DEPLIBS) |
89 | check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS) | 90 | check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS) |
90 | check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS) | 91 | check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS) |
91 | check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) | 92 | check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) |
92 | check_pgsql_DEPENDENCIES = check_pgsql.c $(DEPLIBS) | 93 | check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) |
93 | check_ping_DEPENDENCIES = check_ping.c $(BASEOBJS) popen.o $(DEPLIBS) | 94 | check_ping_DEPENDENCIES = check_ping.c $(NETOBJS) popen.o $(DEPLIBS) |
94 | check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS) | 95 | check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS) |
95 | check_radius_DEPENDENCIES = check_radius.c $(DEPLIBS) | 96 | check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS) |
96 | check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS) | 97 | check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS) |
97 | check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) popen.o $(DEPLIBS) | 98 | check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) popen.o $(DEPLIBS) |
98 | check_smtp_DEPENDENCIES = check_smtp.c $(NETOBJS) $(DEPLIBS) | 99 | check_smtp_DEPENDENCIES = check_smtp.c $(NETOBJS) $(DEPLIBS) |
@@ -104,7 +105,7 @@ check_udp_DEPENDENCIES = check_udp.c $(NETOBJS) $(DEPLIBS) | |||
104 | check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS) | 105 | check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS) |
105 | check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS) | 106 | check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS) |
106 | check_vsz_DEPENDENCIES = check_vsz.c $(BASEOBJS) popen.o $(DEPLIBS) | 107 | check_vsz_DEPENDENCIES = check_vsz.c $(BASEOBJS) popen.o $(DEPLIBS) |
107 | check_by_ssh_DEPENDENCIES = check_by_ssh.c $(BASEOBJS) popen.o $(DEPLIBS) | 108 | check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) popen.o $(DEPLIBS) |
108 | negate_DEPENDENCIES = negate.c $(BASEOBJS) popen.o $(DEPLIBS) | 109 | negate_DEPENDENCIES = negate.c $(BASEOBJS) popen.o $(DEPLIBS) |
109 | urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS) | 110 | urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS) |
110 | 111 | ||
@@ -117,6 +118,10 @@ utils.o: utils.c utils.h $(PLUGINHDRS) | |||
117 | 118 | ||
118 | netutils.o: netutils.c netutils.h $(PLUGINHDRS) | 119 | netutils.o: netutils.c netutils.h $(PLUGINHDRS) |
119 | 120 | ||
121 | getaddrinfo.o: getaddrinfo.h $(PLUGINHDRS) | ||
122 | |||
123 | gethostbyname.o: gethostbyname.h $(PLUGINHDRS) | ||
124 | |||
120 | all-local: $(check_tcp_programs) | 125 | all-local: $(check_tcp_programs) |
121 | 126 | ||
122 | $(check_tcp_programs): check_tcp | 127 | $(check_tcp_programs): check_tcp |
diff --git a/lib/getaddrinfo.c b/plugins/getaddrinfo.c index c958da6c..12ac67d6 100644 --- a/lib/getaddrinfo.c +++ b/plugins/getaddrinfo.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * This file is part of libESMTP, a library for submission of RFC 2822 | 2 | * This file is part of libESMTP, a library for submission of RFC 2822 |
3 | * formatted electronic mail messages using the SMTP protocol described | 3 | * formatted electronic mail messages using the SMTP protocol described |
4 | * in RFC 2821. | 4 | * in RFC 2821. |
5 | * Modified by Jeremy T. Bouse for use in Nagios plugins | ||
5 | * | 6 | * |
6 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | 7 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> |
7 | * | 8 | * |
@@ -89,26 +90,17 @@ getaddrinfo (const char *nodename, const char *servname, | |||
89 | hints = &hint; | 90 | hints = &hint; |
90 | } | 91 | } |
91 | 92 | ||
92 | /* servname must not be NULL in this implementation */ | ||
93 | if (servname == NULL) | ||
94 | return EAI_NONAME; | ||
95 | |||
96 | /* check for tcp or udp sockets only */ | ||
97 | if (hints->ai_socktype == SOCK_STREAM) | ||
98 | socktype = "tcp"; | ||
99 | else if (hints->ai_socktype == SOCK_DGRAM) | ||
100 | socktype = "udp"; | ||
101 | else | ||
102 | return EAI_SERVICE; | ||
103 | result.ai_socktype = hints->ai_socktype; | 93 | result.ai_socktype = hints->ai_socktype; |
104 | 94 | ||
105 | /* Note: maintain port in host byte order to make debugging easier */ | 95 | /* Note: maintain port in host byte order to make debugging easier */ |
106 | if (isdigit (*servname)) | 96 | if (servname != NULL) { |
107 | port = strtol (servname, NULL, 10); | 97 | if (isdigit (*servname)) |
108 | else if ((servent = getservbyname (servname, socktype)) != NULL) | 98 | port = strtol (servname, NULL, 10); |
109 | port = ntohs (servent->s_port); | 99 | else if ((servent = getservbyname (servname, socktype)) != NULL) |
110 | else | 100 | port = ntohs (servent->s_port); |
111 | return EAI_NONAME; | 101 | else |
102 | return EAI_NONAME; | ||
103 | } | ||
112 | 104 | ||
113 | /* if nodename == NULL refer to the local host for a client or any | 105 | /* if nodename == NULL refer to the local host for a client or any |
114 | for a server */ | 106 | for a server */ |
@@ -309,4 +301,3 @@ gai_strerror (int ecode) | |||
309 | return "unknown error"; | 301 | return "unknown error"; |
310 | return eai_descr[ecode]; | 302 | return eai_descr[ecode]; |
311 | } | 303 | } |
312 | |||
diff --git a/lib/getaddrinfo.h b/plugins/getaddrinfo.h index c474d3bc..5bcc8844 100644 --- a/lib/getaddrinfo.h +++ b/plugins/getaddrinfo.h | |||
@@ -4,6 +4,7 @@ | |||
4 | * This file is part of libESMTP, a library for submission of RFC 2822 | 4 | * This file is part of libESMTP, a library for submission of RFC 2822 |
5 | * formatted electronic mail messages using the SMTP protocol described | 5 | * formatted electronic mail messages using the SMTP protocol described |
6 | * in RFC 2821. | 6 | * in RFC 2821. |
7 | * Modified by Jeremy T. Bouse for use in Nagios plugins | ||
7 | * | 8 | * |
8 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> | 9 | * Copyright (C) 2001,2002 Brian Stafford <brian@stafford.uklinux.net> |
9 | * | 10 | * |
diff --git a/lib/gethostbyname.c b/plugins/gethostbyname.c index d151606d..d151606d 100644 --- a/lib/gethostbyname.c +++ b/plugins/gethostbyname.c | |||
diff --git a/lib/gethostbyname.h b/plugins/gethostbyname.h index 2b963997..2b963997 100644 --- a/lib/gethostbyname.h +++ b/plugins/gethostbyname.h | |||
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 | |||
diff --git a/plugins/netutils.h b/plugins/netutils.h index 3ea51663..6c8eed36 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -43,11 +43,20 @@ int process_tcp_request (char *address, int port, char *sbuffer, | |||
43 | char *rbuffer, int rsize); | 43 | char *rbuffer, int rsize); |
44 | int process_udp_request (char *address, int port, char *sbuffer, | 44 | int process_udp_request (char *address, int port, char *sbuffer, |
45 | char *rbuffer, int rsize); | 45 | char *rbuffer, int rsize); |
46 | int process_request (char *address, int port, char *proto, char *sbuffer, | 46 | int process_request (char *address, int port, int proto, char *sbuffer, |
47 | char *rbuffer, int rsize); | 47 | char *rbuffer, int rsize); |
48 | 48 | ||
49 | int my_tcp_connect (char *address, int port, int *sd); | 49 | int my_tcp_connect (char *address, int port, int *sd); |
50 | int my_udp_connect (char *address, int port, int *sd); | 50 | int my_udp_connect (char *address, int port, int *sd); |
51 | int my_connect (char *address, int port, int *sd, int proto); | 51 | int my_connect (char *address, int port, int *sd, int proto); |
52 | 52 | ||
53 | int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | 53 | int is_host (char *); |
54 | int is_addr (char *); | ||
55 | int resolve_host_or_addr (char *, int); | ||
56 | int is_inet_addr (char *); | ||
57 | #ifdef USE_IPV6 | ||
58 | int is_inet6_addr (char *); | ||
59 | #endif | ||
60 | int is_hostname (char *); | ||
61 | |||
62 | extern int socket_timeout; | ||
diff --git a/plugins/utils.c b/plugins/utils.c index 7361323f..e204e238 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -27,15 +27,6 @@ void print_revision (const char *, const char *); | |||
27 | void terminate (int, const char *fmt, ...); | 27 | void terminate (int, const char *fmt, ...); |
28 | RETSIGTYPE timeout_alarm_handler (int); | 28 | RETSIGTYPE timeout_alarm_handler (int); |
29 | 29 | ||
30 | int is_host (char *); | ||
31 | int is_addr (char *); | ||
32 | int resolve_host_or_addr (char *, int); | ||
33 | int is_inet_addr (char *); | ||
34 | #ifdef USE_IPV6 | ||
35 | int is_inet6_addr (char *); | ||
36 | #endif | ||
37 | int is_hostname (char *); | ||
38 | |||
39 | int is_integer (char *); | 30 | int is_integer (char *); |
40 | int is_intpos (char *); | 31 | int is_intpos (char *); |
41 | int is_intneg (char *); | 32 | int is_intneg (char *); |
@@ -171,78 +162,6 @@ timeout_alarm_handler (int signo) | |||
171 | } | 162 | } |
172 | 163 | ||
173 | int | 164 | int |
174 | is_host (char *address) | ||
175 | { | ||
176 | if (is_addr (address) || is_hostname (address)) | ||
177 | return (TRUE); | ||
178 | |||
179 | return (FALSE); | ||
180 | } | ||
181 | |||
182 | int | ||
183 | is_addr (char *address) | ||
184 | { | ||
185 | #ifdef USE_IPV6 | ||
186 | if (is_inet_addr (address) || is_inet6_addr (address)) | ||
187 | #else | ||
188 | if (is_inet_addr (address)) | ||
189 | #endif | ||
190 | return (TRUE); | ||
191 | |||
192 | return (FALSE); | ||
193 | } | ||
194 | |||
195 | int | ||
196 | resolve_host_or_addr (char *address, int family) | ||
197 | { | ||
198 | struct addrinfo hints; | ||
199 | struct addrinfo *res; | ||
200 | int retval; | ||
201 | |||
202 | memset (&hints, 0, sizeof (hints)); | ||
203 | hints.ai_family = family; | ||
204 | retval = getaddrinfo (address, NULL, &hints, &res); | ||
205 | |||
206 | if (retval != 0) | ||
207 | return FALSE; | ||
208 | else { | ||
209 | freeaddrinfo (res); | ||
210 | return TRUE; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | int | ||
215 | is_inet_addr (char *address) | ||
216 | { | ||
217 | return resolve_host_or_addr (address, AF_INET); | ||
218 | } | ||
219 | |||
220 | #ifdef USE_IPV6 | ||
221 | int | ||
222 | is_inet6_addr (char *address) | ||
223 | { | ||
224 | return resolve_host_or_addr (address, AF_INET6); | ||
225 | } | ||
226 | #endif | ||
227 | |||
228 | /* from RFC-1035 | ||
229 | * | ||
230 | * The labels must follow the rules for ARPANET host names. They must | ||
231 | * start with a letter, end with a letter or digit, and have as interior | ||
232 | * characters only letters, digits, and hyphen. There are also some | ||
233 | * restrictions on the length. Labels must be 63 characters or less. */ | ||
234 | |||
235 | int | ||
236 | is_hostname (char *s1) | ||
237 | { | ||
238 | #ifdef USE_IPV6 | ||
239 | return resolve_host_or_addr (s1, AF_UNSPEC); | ||
240 | #else | ||
241 | return resolve_host_or_addr (s1, AF_INET); | ||
242 | #endif | ||
243 | } | ||
244 | |||
245 | int | ||
246 | is_numeric (char *number) | 165 | is_numeric (char *number) |
247 | { | 166 | { |
248 | char tmp[1]; | 167 | char tmp[1]; |
diff --git a/plugins/utils.h b/plugins/utils.h index 89ada6f0..43b612c1 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -27,14 +27,6 @@ int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | |||
27 | 27 | ||
28 | /* Test input types */ | 28 | /* Test input types */ |
29 | 29 | ||
30 | int is_host (char *); | ||
31 | int is_addr (char *); | ||
32 | int is_inet_addr (char *); | ||
33 | #ifdef USE_IPV6 | ||
34 | int is_inet6_addr (char *); | ||
35 | #endif | ||
36 | int is_hostname (char *); | ||
37 | |||
38 | int is_integer (char *); | 30 | int is_integer (char *); |
39 | int is_intpos (char *); | 31 | int is_intpos (char *); |
40 | int is_intneg (char *); | 32 | int is_intneg (char *); |