Index: configure.in =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/configure.in,v retrieving revision 1.29 diff -u -r1.29 configure.in --- configure.in 22 Nov 2002 02:46:49 -0000 1.29 +++ configure.in 10 Dec 2002 19:43:09 -0000 @@ -703,6 +703,57 @@ fi AC_DEFINE_UNQUOTED(PING_COMMAND,"$PING_COMMAND",[path and args for ping command]) +AC_PATH_PROG(PATH_TO_PING6,ping6) + +AC_ARG_WITH(ping6_command,--with-ping6-command= sets syntax for ping,PING6_COMMAND=$withval) +if test -n "$PING6_COMMAND" +then + echo " ping6 syntax... (command-line) $PING6_COMMAND" + if test -n "$PING6_PACKETS_FIRST" + then + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) + fi +elif [ping6 -n -U -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -U -c %d %s" + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) + echo " ping6 syntax... $PATH_TO_PING6 -n -U -c " +elif [ping6 -n -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -c %d %s" + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) + echo " ping6 syntax... $PATH_TO_PING6 -n -c " +elif [ping6 -n ::1 -c 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n %s -c %d" + echo " ping6 syntax... $PATH_TO_PING6 -n -c " +elif [ping6 ::1 -n 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 %s -n %d" + echo " ping6 syntax... $PATH_TO_PING6 -n " +elif [ping6 -n -s ::1 56 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -s %s 56 %d" + echo " ping6 syntax... $PATH_TO_PING6 -n -s 56 " +elif [ping6 -n -h ::1 -s 56 -c 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -h %s -s 56 -c %d" + echo " ping6 syntax... $PATH_TO_PING6 -n -h -s 56 -c " +elif [ping6 -n -s 56 -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -s 56 -c %d %s" + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) + echo " ping6 syntax... $PATH_TO_PING6 -n -s 56 -c " +elif [ping6 -n -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] +then + PING6_COMMAND="$PATH_TO_PING6 -n -c %d %s" + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) + echo " ping6 syntax... $PATH_TO_PING6 -n -c " +else + AC_MSG_WARN("unable to find usable ping6 syntax") +fi +AC_DEFINE_UNQUOTED(PING6_COMMAND,"$PING6_COMMAND",[path and args for ping command]) + AC_PATH_PROG(PATH_TO_NSLOOKUP,nslookup) if test -n "$ac_cv_path_PATH_TO_NSLOOKUP" then Index: plugins/check_dig.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dig.c,v retrieving revision 1.7 diff -u -r1.7 check_dig.c --- plugins/check_dig.c 21 Nov 2002 12:40:58 -0000 1.7 +++ plugins/check_dig.c 10 Dec 2002 19:43:09 -0000 @@ -57,7 +57,7 @@ usage ("Could not parse arguments\n"); /* get the command to run */ - asprintf (&command_line, "%s @%s %s", PATH_TO_DIG, dns_server, query_address); + asprintf (&command_line, "%s -t any @%s %s", PATH_TO_DIG, dns_server, query_address); alarm (timeout_interval); time (&start_time); Index: plugins/check_dns.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dns.c,v retrieving revision 1.5 diff -u -r1.5 check_dns.c --- plugins/check_dns.c 14 Nov 2002 02:26:34 -0000 1.5 +++ plugins/check_dns.c 10 Dec 2002 19:43:10 -0000 @@ -308,7 +308,7 @@ timeout_interval = atoi (optarg); break; case 'H': /* hostname */ - if (is_host (optarg) == FALSE) { + if ((is_host (optarg)) == FALSE) { printf ("Invalid host name/address\n\n"); print_usage (); exit (STATE_UNKNOWN); @@ -318,7 +318,7 @@ strcpy (query_address, optarg); break; case 's': /* server name */ - if (is_host (optarg) == FALSE) { + if ((is_host (optarg)) == FALSE) { printf ("Invalid server name/address\n\n"); print_usage (); exit (STATE_UNKNOWN); @@ -328,7 +328,7 @@ strcpy (dns_server, optarg); break; case 'r': /* reverse server name */ - if (is_host (optarg) == FALSE) { + if ((is_host (optarg)) == FALSE) { printf ("Invalid host name/address\n\n"); print_usage (); exit (STATE_UNKNOWN); @@ -338,7 +338,7 @@ strcpy (ptr_server, optarg); break; case 'a': /* expected address */ - if (is_dotted_quad (optarg) == FALSE) { + if ((is_ipv4_addr (optarg)) == FALSE) { printf ("Invalid expected address\n\n"); print_usage (); exit (STATE_UNKNOWN); @@ -352,8 +352,8 @@ } c = optind; - if (query_address[0] == 0) { - if (is_host (argv[c]) == FALSE) { + if (query_address== NULL) { + if ((is_host (argv[c])) == FALSE) { printf ("Invalid name/address: %s\n\n", argv[c]); return ERROR; } @@ -362,8 +362,8 @@ strcpy (query_address, argv[c++]); } - if (dns_server[0] == 0) { - if (is_host (argv[c]) == FALSE) { + if (dns_server == NULL) { + if ((is_host (argv[c])) == FALSE) { printf ("Invalid name/address: %s\n\n", argv[c]); return ERROR; } Index: plugins/check_ldap.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ldap.c,v retrieving revision 1.2 diff -u -r1.2 check_ldap.c --- plugins/check_ldap.c 14 Nov 2002 02:26:34 -0000 1.2 +++ plugins/check_ldap.c 10 Dec 2002 19:43:10 -0000 @@ -7,7 +7,7 @@ * * Last Modified: $Date: 2002/11/14 02:26:34 $ * - * Command line: check_ldap -h -b -p -w -w + * Command line: check_ldap -H -b -p -w -w * * Description: * @@ -197,7 +197,7 @@ crit_time = atoi (optarg); break; default: - usage ("check_ldap: could not parse arguments\n"); + usage ("check_ldap: could not parse unknown arguments\n"); break; } } @@ -253,6 +253,6 @@ { printf ("Usage: %s -H -b -p [-a ] [-D ]\n" - " [-P ] [-w ] [-c ] [-t timeout]\n" + " [-P ] -w -c [-t timeout]\n" "(Note: all times are in seconds.)\n", PROGNAME); } Index: plugins/check_ping.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v retrieving revision 1.10 diff -u -r1.10 check_ping.c --- plugins/check_ping.c 13 Nov 2002 11:50:54 -0000 1.10 +++ plugins/check_ping.c 10 Dec 2002 19:43:10 -0000 @@ -88,9 +88,15 @@ /* does the host address of number of packets argument come first? */ #ifdef PING_PACKETS_FIRST - asprintf (&command_line, PING_COMMAND, max_packets, server_address); + if (is_ipv6_addr (server_address)) + asprintf (&command_line, PING6_COMMAND, max_packets, server_address); + else + asprintf (&command_line, PING_COMMAND, max_packets, server_address); #else - asprintf (&command_line, PING_COMMAND, server_address, max_packets); + if (is_ipv6_addr (server_address)) + asprintf (&command_line, PING6_COMMAND, server_address, max_packets); + else + asprintf (&command_line, PING_COMMAND, server_address, max_packets); #endif /* Set signal handling and alarm */ Index: plugins/netutils.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 netutils.c --- plugins/netutils.c 28 Feb 2002 06:42:59 -0000 1.1.1.1 +++ plugins/netutils.c 10 Dec 2002 19:43:10 -0000 @@ -48,8 +48,6 @@ int my_udp_connect (char *, int, int *); int my_connect (char *, int, int *, char *); -int my_inet_aton (register const char *, struct in_addr *); - /* handles socket timeouts */ void socket_timeout_alarm_handler (int sig) @@ -265,167 +263,70 @@ int my_connect (char *host_name, int port, int *sd, char *proto) { - struct sockaddr_in servaddr; - struct hostent *hp; - struct protoent *ptrp; - int result; - - bzero ((char *) &servaddr, sizeof (servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_port = htons (port); - - /* try to bypass using a DNS lookup if this is just an IP address */ - if (!my_inet_aton (host_name, &servaddr.sin_addr)) { - - /* else do a DNS lookup */ - hp = gethostbyname ((const char *) host_name); - if (hp == NULL) { - printf ("Invalid host name '%s'\n", host_name); - return STATE_UNKNOWN; - } - - memcpy (&servaddr.sin_addr, hp->h_addr, hp->h_length); - } - - /* map transport protocol name to protocol number */ - if ((ptrp = getprotobyname (proto)) == NULL) { - printf ("Cannot map \"%s\" to protocol number\n", proto); - return STATE_UNKNOWN; - } - - /* create a socket */ - *sd = - socket (PF_INET, (!strcmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM, - ptrp->p_proto); - if (*sd < 0) { - printf ("Socket creation failed\n"); - return STATE_UNKNOWN; - } - - /* open a connection */ - result = connect (*sd, (struct sockaddr *) &servaddr, sizeof (servaddr)); - if (result < 0) { - switch (errno) { - case ECONNREFUSED: - printf ("Connection refused by host\n"); - break; - case ETIMEDOUT: - printf ("Timeout while attempting connection\n"); - break; - case ENETUNREACH: - printf ("Network is unreachable\n"); - break; - default: - printf ("Connection refused or timed out\n"); - } - - return STATE_CRITICAL; - } - - return STATE_OK; -} - - - -/* This code was taken from Fyodor's nmap utility, which was originally - taken from the GLIBC 2.0.6 libraries because Solaris doesn't contain - the inet_aton() funtion. */ -int -my_inet_aton (register const char *cp, struct in_addr *addr) -{ - register unsigned int val; /* changed from u_long --david */ - register int base, n; - register char c; - u_int parts[4]; - register u_int *pp = parts; - - c = *cp; - - for (;;) { - - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit ((int) c)) - return (0); - val = 0; - base = 10; - - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; - else - base = 8; - } - - for (;;) { - if (isascii ((int) c) && isdigit ((int) c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } - else if (base == 16 && isascii ((int) c) && isxdigit ((int) c)) { - val = (val << 4) | (c + 10 - (islower ((int) c) ? 'a' : 'A')); - c = *++cp; - } - else - break; - } - - if (c == '.') { - - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3) - return (0); - *pp++ = val; - c = *++cp; - } - else - break; - } - - /* Check for trailing characters */ - if (c != '\0' && (!isascii ((int) c) || !isspace ((int) c))) - return (0); - - /* Concoct the address according to the number of parts specified */ - n = pp - parts + 1; - switch (n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if (val > 0xffffff) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if (val > 0xffff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if (val > 0xff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; + struct addrinfo hints; + struct addrinfo *res; + struct protoent *ptrp; + char port_str[6]; + char nbuf[NI_MAXHOST]; + int result; + + /* map the transport protocol name to protocol number */ + ptrp = getprotobyname ((const char *)proto); + if (ptrp == NULL) + { + printf ("Cannot map %s to protocol number\n", proto); + return STATE_UNKNOWN; + } + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_protocol = ptrp->p_proto; + + snprintf(port_str, sizeof(port_str), "%d", port); + /* nice clean AF-independent code doesn't matter if passed hostname or IP address */ + result = getaddrinfo (host_name, port_str, &hints, &res); + + if (result != 0) + { + printf ("%s\n", gai_strerror (result)); + return STATE_UNKNOWN; } - - if (addr) - addr->s_addr = htonl (val); - - return (1); + else + { + while (res) + { + /* attempt to create a socket */ + *sd = socket (res->ai_family, (!strcasecmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM, res->ai_protocol); + + if (*sd < 0) { + printf ("Socket creation failed\n"); + freeaddrinfo (res); + return STATE_UNKNOWN; + } + + /* Little debugging here */ + result = getnameinfo (res->ai_addr, res->ai_addrlen, + nbuf, sizeof (nbuf), NULL, 0, NI_NUMERICHOST); + printf ("Connect attempt on socket %d to %s", + *sd, nbuf); + + /* attempt to open a connection */ + result = connect (*sd, res->ai_addr, res->ai_addrlen); + + if (result == 0) + break; + + close(*sd); + res = res->ai_next; + } + freeaddrinfo (res); + } + + if (result == 0) + return STATE_OK; + else + { + printf ("%s\n", strerror(errno)); + return STATE_CRITICAL; + } } Index: plugins/netutils.h.in =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.h.in,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 netutils.h.in --- plugins/netutils.h.in 28 Feb 2002 06:42:59 -0000 1.1.1.1 +++ plugins/netutils.h.in 10 Dec 2002 19:43:10 -0000 @@ -54,8 +54,6 @@ int my_udp_connect (char *address, int port, int *sd); int my_connect (char *address, int port, int *sd, char *proto); -int my_inet_aton (register const char *cp, struct in_addr *addr); - #ifndef DEFAULT_SOCKET_TIMEOUT #include "config.h" #include "common.h" Index: plugins/utils.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v retrieving revision 1.13 diff -u -r1.13 utils.c --- plugins/utils.c 18 Nov 2002 07:22:28 -0000 1.13 +++ plugins/utils.c 10 Dec 2002 19:43:10 -0000 @@ -16,6 +16,9 @@ #include "version.h" #include #include +#include +#include +#include extern int timeout_interval; @@ -27,7 +30,8 @@ RETSIGTYPE timeout_alarm_handler (int); int is_host (char *); -int is_dotted_quad (char *); +int is_ipv4_addr (char *); +int is_ipv6_addr (char *); int is_hostname (char *); int is_integer (char *); @@ -154,25 +158,51 @@ int is_host (char *address) { - if (is_dotted_quad (address) || is_hostname (address)) + if (is_ipv4_addr (address) || is_ipv6_addr (address) || + is_hostname (address)) return (TRUE); + return (FALSE); } int -is_dotted_quad (char *address) +is_ipv4_addr (char *address) { - int o1, o2, o3, o4; - char c[1]; + struct addrinfo hints; + struct addrinfo *res; + int retval; - 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) + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_INET; + retval = getaddrinfo (address, NULL, &hints, &res); + + if (retval != 0) return FALSE; - else if (o1 < 0 || o2 < 0 || o3 < 0 || o4 < 0) + else + { + freeaddrinfo (res); + return TRUE; + } +} + +int +is_ipv6_addr (char *address) +{ + struct addrinfo hints; + struct addrinfo *res; + int retval; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_INET6; + retval = getaddrinfo (address, NULL, &hints, &res); + + if (retval != 0) return FALSE; else + { + freeaddrinfo (res); return TRUE; + } } /* from RFC-1035 @@ -185,22 +215,21 @@ int is_hostname (char *s1) { - if (strlen (s1) > 63) - return FALSE; - if (strcspn - (s1, - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") != - 0) return FALSE; - if (strspn (s1, "0123456789-.") == 1) + struct addrinfo hints; + struct addrinfo *res; + int retval; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_UNSPEC; + retval = getaddrinfo (s1, NULL, &hints, &res); + + if (retval != 0) return FALSE; - while ((s1 = index (s1, '.'))) { - s1++; - if (strspn (s1, "0123456789-.") == 1) { - printf ("%s\n", s1); - return FALSE; - } + else + { + freeaddrinfo (res); + return TRUE; } - return TRUE; } int Index: plugins/utils.h.in =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h.in,v retrieving revision 1.7 diff -u -r1.7 utils.h.in --- plugins/utils.h.in 9 Nov 2002 03:39:35 -0000 1.7 +++ plugins/utils.h.in 10 Dec 2002 19:43:10 -0000 @@ -28,7 +28,8 @@ /* Test input types */ int is_host (char *); -int is_dotted_quad (char *); +int is_ipv4_addr (char *); +int is_ipv6_addr (char *); int is_hostname (char *); int is_integer (char *);