diff options
Diffstat (limited to 'web/attachments/37289-nagiosplugins-cvs-20021210-ipv6.diff')
| -rw-r--r-- | web/attachments/37289-nagiosplugins-cvs-20021210-ipv6.diff | 609 |
1 files changed, 609 insertions, 0 deletions
diff --git a/web/attachments/37289-nagiosplugins-cvs-20021210-ipv6.diff b/web/attachments/37289-nagiosplugins-cvs-20021210-ipv6.diff new file mode 100644 index 0000000..bc3a280 --- /dev/null +++ b/web/attachments/37289-nagiosplugins-cvs-20021210-ipv6.diff | |||
| @@ -0,0 +1,609 @@ | |||
| 1 | Index: configure.in | ||
| 2 | =================================================================== | ||
| 3 | RCS file: /cvsroot/nagiosplug/nagiosplug/configure.in,v | ||
| 4 | retrieving revision 1.29 | ||
| 5 | diff -u -r1.29 configure.in | ||
| 6 | --- configure.in 22 Nov 2002 02:46:49 -0000 1.29 | ||
| 7 | +++ configure.in 10 Dec 2002 19:43:09 -0000 | ||
| 8 | @@ -703,6 +703,57 @@ | ||
| 9 | fi | ||
| 10 | AC_DEFINE_UNQUOTED(PING_COMMAND,"$PING_COMMAND",[path and args for ping command]) | ||
| 11 | |||
| 12 | +AC_PATH_PROG(PATH_TO_PING6,ping6) | ||
| 13 | + | ||
| 14 | +AC_ARG_WITH(ping6_command,--with-ping6-command=<syntax> sets syntax for ping,PING6_COMMAND=$withval) | ||
| 15 | +if test -n "$PING6_COMMAND" | ||
| 16 | +then | ||
| 17 | + echo " ping6 syntax... (command-line) $PING6_COMMAND" | ||
| 18 | + if test -n "$PING6_PACKETS_FIRST" | ||
| 19 | + then | ||
| 20 | + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) | ||
| 21 | + fi | ||
| 22 | +elif [ping6 -n -U -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 23 | +then | ||
| 24 | + PING6_COMMAND="$PATH_TO_PING6 -n -U -c %d %s" | ||
| 25 | + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) | ||
| 26 | + echo " ping6 syntax... $PATH_TO_PING6 -n -U -c <count> <host>" | ||
| 27 | +elif [ping6 -n -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 28 | +then | ||
| 29 | + PING6_COMMAND="$PATH_TO_PING6 -n -c %d %s" | ||
| 30 | + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) | ||
| 31 | + echo " ping6 syntax... $PATH_TO_PING6 -n -c <count> <host>" | ||
| 32 | +elif [ping6 -n ::1 -c 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 33 | +then | ||
| 34 | + PING6_COMMAND="$PATH_TO_PING6 -n %s -c %d" | ||
| 35 | + echo " ping6 syntax... $PATH_TO_PING6 -n <host> -c <count>" | ||
| 36 | +elif [ping6 ::1 -n 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 37 | +then | ||
| 38 | + PING6_COMMAND="$PATH_TO_PING6 %s -n %d" | ||
| 39 | + echo " ping6 syntax... $PATH_TO_PING6 <host> -n <count>" | ||
| 40 | +elif [ping6 -n -s ::1 56 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 41 | +then | ||
| 42 | + PING6_COMMAND="$PATH_TO_PING6 -n -s %s 56 %d" | ||
| 43 | + echo " ping6 syntax... $PATH_TO_PING6 -n -s <host> 56 <count>" | ||
| 44 | +elif [ping6 -n -h ::1 -s 56 -c 1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 45 | +then | ||
| 46 | + PING6_COMMAND="$PATH_TO_PING6 -n -h %s -s 56 -c %d" | ||
| 47 | + echo " ping6 syntax... $PATH_TO_PING6 -n -h <host> -s 56 -c <count>" | ||
| 48 | +elif [ping6 -n -s 56 -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 49 | +then | ||
| 50 | + PING6_COMMAND="$PATH_TO_PING6 -n -s 56 -c %d %s" | ||
| 51 | + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) | ||
| 52 | + echo " ping6 syntax... $PATH_TO_PING6 -n -s 56 -c <count> <host>" | ||
| 53 | +elif [ping6 -n -c 1 ::1 2>/dev/null | egrep -i "^round-trip|^rtt" >/dev/null] | ||
| 54 | +then | ||
| 55 | + PING6_COMMAND="$PATH_TO_PING6 -n -c %d %s" | ||
| 56 | + AC_DEFINE_UNQUOTED(PING6_PACKETS_FIRST,"$PING6_COMMAND",[Define if packet count must precede host]) | ||
| 57 | + echo " ping6 syntax... $PATH_TO_PING6 -n -c <count> <host>" | ||
| 58 | +else | ||
| 59 | + AC_MSG_WARN("unable to find usable ping6 syntax") | ||
| 60 | +fi | ||
| 61 | +AC_DEFINE_UNQUOTED(PING6_COMMAND,"$PING6_COMMAND",[path and args for ping command]) | ||
| 62 | + | ||
| 63 | AC_PATH_PROG(PATH_TO_NSLOOKUP,nslookup) | ||
| 64 | if test -n "$ac_cv_path_PATH_TO_NSLOOKUP" | ||
| 65 | then | ||
| 66 | Index: plugins/check_dig.c | ||
| 67 | =================================================================== | ||
| 68 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dig.c,v | ||
| 69 | retrieving revision 1.7 | ||
| 70 | diff -u -r1.7 check_dig.c | ||
| 71 | --- plugins/check_dig.c 21 Nov 2002 12:40:58 -0000 1.7 | ||
| 72 | +++ plugins/check_dig.c 10 Dec 2002 19:43:09 -0000 | ||
| 73 | @@ -57,7 +57,7 @@ | ||
| 74 | usage ("Could not parse arguments\n"); | ||
| 75 | |||
| 76 | /* get the command to run */ | ||
| 77 | - asprintf (&command_line, "%s @%s %s", PATH_TO_DIG, dns_server, query_address); | ||
| 78 | + asprintf (&command_line, "%s -t any @%s %s", PATH_TO_DIG, dns_server, query_address); | ||
| 79 | |||
| 80 | alarm (timeout_interval); | ||
| 81 | time (&start_time); | ||
| 82 | Index: plugins/check_dns.c | ||
| 83 | =================================================================== | ||
| 84 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dns.c,v | ||
| 85 | retrieving revision 1.5 | ||
| 86 | diff -u -r1.5 check_dns.c | ||
| 87 | --- plugins/check_dns.c 14 Nov 2002 02:26:34 -0000 1.5 | ||
| 88 | +++ plugins/check_dns.c 10 Dec 2002 19:43:10 -0000 | ||
| 89 | @@ -308,7 +308,7 @@ | ||
| 90 | timeout_interval = atoi (optarg); | ||
| 91 | break; | ||
| 92 | case 'H': /* hostname */ | ||
| 93 | - if (is_host (optarg) == FALSE) { | ||
| 94 | + if ((is_host (optarg)) == FALSE) { | ||
| 95 | printf ("Invalid host name/address\n\n"); | ||
| 96 | print_usage (); | ||
| 97 | exit (STATE_UNKNOWN); | ||
| 98 | @@ -318,7 +318,7 @@ | ||
| 99 | strcpy (query_address, optarg); | ||
| 100 | break; | ||
| 101 | case 's': /* server name */ | ||
| 102 | - if (is_host (optarg) == FALSE) { | ||
| 103 | + if ((is_host (optarg)) == FALSE) { | ||
| 104 | printf ("Invalid server name/address\n\n"); | ||
| 105 | print_usage (); | ||
| 106 | exit (STATE_UNKNOWN); | ||
| 107 | @@ -328,7 +328,7 @@ | ||
| 108 | strcpy (dns_server, optarg); | ||
| 109 | break; | ||
| 110 | case 'r': /* reverse server name */ | ||
| 111 | - if (is_host (optarg) == FALSE) { | ||
| 112 | + if ((is_host (optarg)) == FALSE) { | ||
| 113 | printf ("Invalid host name/address\n\n"); | ||
| 114 | print_usage (); | ||
| 115 | exit (STATE_UNKNOWN); | ||
| 116 | @@ -338,7 +338,7 @@ | ||
| 117 | strcpy (ptr_server, optarg); | ||
| 118 | break; | ||
| 119 | case 'a': /* expected address */ | ||
| 120 | - if (is_dotted_quad (optarg) == FALSE) { | ||
| 121 | + if ((is_ipv4_addr (optarg)) == FALSE) { | ||
| 122 | printf ("Invalid expected address\n\n"); | ||
| 123 | print_usage (); | ||
| 124 | exit (STATE_UNKNOWN); | ||
| 125 | @@ -352,8 +352,8 @@ | ||
| 126 | } | ||
| 127 | |||
| 128 | c = optind; | ||
| 129 | - if (query_address[0] == 0) { | ||
| 130 | - if (is_host (argv[c]) == FALSE) { | ||
| 131 | + if (query_address== NULL) { | ||
| 132 | + if ((is_host (argv[c])) == FALSE) { | ||
| 133 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 134 | return ERROR; | ||
| 135 | } | ||
| 136 | @@ -362,8 +362,8 @@ | ||
| 137 | strcpy (query_address, argv[c++]); | ||
| 138 | } | ||
| 139 | |||
| 140 | - if (dns_server[0] == 0) { | ||
| 141 | - if (is_host (argv[c]) == FALSE) { | ||
| 142 | + if (dns_server == NULL) { | ||
| 143 | + if ((is_host (argv[c])) == FALSE) { | ||
| 144 | printf ("Invalid name/address: %s\n\n", argv[c]); | ||
| 145 | return ERROR; | ||
| 146 | } | ||
| 147 | Index: plugins/check_ldap.c | ||
| 148 | =================================================================== | ||
| 149 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ldap.c,v | ||
| 150 | retrieving revision 1.2 | ||
| 151 | diff -u -r1.2 check_ldap.c | ||
| 152 | --- plugins/check_ldap.c 14 Nov 2002 02:26:34 -0000 1.2 | ||
| 153 | +++ plugins/check_ldap.c 10 Dec 2002 19:43:10 -0000 | ||
| 154 | @@ -7,7 +7,7 @@ | ||
| 155 | * | ||
| 156 | * Last Modified: $Date: 2002/11/14 02:26:34 $ | ||
| 157 | * | ||
| 158 | - * Command line: check_ldap -h <host> -b <base_dn> -p <port> -w <warn_time> -w <crit_time> | ||
| 159 | + * Command line: check_ldap -H <host> -b <base_dn> -p <port> -w <warn_time> -w <crit_time> | ||
| 160 | * | ||
| 161 | * Description: | ||
| 162 | * | ||
| 163 | @@ -197,7 +197,7 @@ | ||
| 164 | crit_time = atoi (optarg); | ||
| 165 | break; | ||
| 166 | default: | ||
| 167 | - usage ("check_ldap: could not parse arguments\n"); | ||
| 168 | + usage ("check_ldap: could not parse unknown arguments\n"); | ||
| 169 | break; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | @@ -253,6 +253,6 @@ | ||
| 173 | { | ||
| 174 | printf | ||
| 175 | ("Usage: %s -H <host> -b <base_dn> -p <port> [-a <attr>] [-D <binddn>]\n" | ||
| 176 | - " [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]\n" | ||
| 177 | + " [-P <password>] -w <warn_time> -c <crit_time> [-t timeout]\n" | ||
| 178 | "(Note: all times are in seconds.)\n", PROGNAME); | ||
| 179 | } | ||
| 180 | Index: plugins/check_ping.c | ||
| 181 | =================================================================== | ||
| 182 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v | ||
| 183 | retrieving revision 1.10 | ||
| 184 | diff -u -r1.10 check_ping.c | ||
| 185 | --- plugins/check_ping.c 13 Nov 2002 11:50:54 -0000 1.10 | ||
| 186 | +++ plugins/check_ping.c 10 Dec 2002 19:43:10 -0000 | ||
| 187 | @@ -88,9 +88,15 @@ | ||
| 188 | |||
| 189 | /* does the host address of number of packets argument come first? */ | ||
| 190 | #ifdef PING_PACKETS_FIRST | ||
| 191 | - asprintf (&command_line, PING_COMMAND, max_packets, server_address); | ||
| 192 | + if (is_ipv6_addr (server_address)) | ||
| 193 | + asprintf (&command_line, PING6_COMMAND, max_packets, server_address); | ||
| 194 | + else | ||
| 195 | + asprintf (&command_line, PING_COMMAND, max_packets, server_address); | ||
| 196 | #else | ||
| 197 | - asprintf (&command_line, PING_COMMAND, server_address, max_packets); | ||
| 198 | + if (is_ipv6_addr (server_address)) | ||
| 199 | + asprintf (&command_line, PING6_COMMAND, server_address, max_packets); | ||
| 200 | + else | ||
| 201 | + asprintf (&command_line, PING_COMMAND, server_address, max_packets); | ||
| 202 | #endif | ||
| 203 | |||
| 204 | /* Set signal handling and alarm */ | ||
| 205 | Index: plugins/netutils.c | ||
| 206 | =================================================================== | ||
| 207 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.c,v | ||
| 208 | retrieving revision 1.1.1.1 | ||
| 209 | diff -u -r1.1.1.1 netutils.c | ||
| 210 | --- plugins/netutils.c 28 Feb 2002 06:42:59 -0000 1.1.1.1 | ||
| 211 | +++ plugins/netutils.c 10 Dec 2002 19:43:10 -0000 | ||
| 212 | @@ -48,8 +48,6 @@ | ||
| 213 | int my_udp_connect (char *, int, int *); | ||
| 214 | int my_connect (char *, int, int *, char *); | ||
| 215 | |||
| 216 | -int my_inet_aton (register const char *, struct in_addr *); | ||
| 217 | - | ||
| 218 | /* handles socket timeouts */ | ||
| 219 | void | ||
| 220 | socket_timeout_alarm_handler (int sig) | ||
| 221 | @@ -265,167 +263,70 @@ | ||
| 222 | int | ||
| 223 | my_connect (char *host_name, int port, int *sd, char *proto) | ||
| 224 | { | ||
| 225 | - struct sockaddr_in servaddr; | ||
| 226 | - struct hostent *hp; | ||
| 227 | - struct protoent *ptrp; | ||
| 228 | - int result; | ||
| 229 | - | ||
| 230 | - bzero ((char *) &servaddr, sizeof (servaddr)); | ||
| 231 | - servaddr.sin_family = AF_INET; | ||
| 232 | - servaddr.sin_port = htons (port); | ||
| 233 | - | ||
| 234 | - /* try to bypass using a DNS lookup if this is just an IP address */ | ||
| 235 | - if (!my_inet_aton (host_name, &servaddr.sin_addr)) { | ||
| 236 | - | ||
| 237 | - /* else do a DNS lookup */ | ||
| 238 | - hp = gethostbyname ((const char *) host_name); | ||
| 239 | - if (hp == NULL) { | ||
| 240 | - printf ("Invalid host name '%s'\n", host_name); | ||
| 241 | - return STATE_UNKNOWN; | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | - memcpy (&servaddr.sin_addr, hp->h_addr, hp->h_length); | ||
| 245 | - } | ||
| 246 | - | ||
| 247 | - /* map transport protocol name to protocol number */ | ||
| 248 | - if ((ptrp = getprotobyname (proto)) == NULL) { | ||
| 249 | - printf ("Cannot map \"%s\" to protocol number\n", proto); | ||
| 250 | - return STATE_UNKNOWN; | ||
| 251 | - } | ||
| 252 | - | ||
| 253 | - /* create a socket */ | ||
| 254 | - *sd = | ||
| 255 | - socket (PF_INET, (!strcmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM, | ||
| 256 | - ptrp->p_proto); | ||
| 257 | - if (*sd < 0) { | ||
| 258 | - printf ("Socket creation failed\n"); | ||
| 259 | - return STATE_UNKNOWN; | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | - /* open a connection */ | ||
| 263 | - result = connect (*sd, (struct sockaddr *) &servaddr, sizeof (servaddr)); | ||
| 264 | - if (result < 0) { | ||
| 265 | - switch (errno) { | ||
| 266 | - case ECONNREFUSED: | ||
| 267 | - printf ("Connection refused by host\n"); | ||
| 268 | - break; | ||
| 269 | - case ETIMEDOUT: | ||
| 270 | - printf ("Timeout while attempting connection\n"); | ||
| 271 | - break; | ||
| 272 | - case ENETUNREACH: | ||
| 273 | - printf ("Network is unreachable\n"); | ||
| 274 | - break; | ||
| 275 | - default: | ||
| 276 | - printf ("Connection refused or timed out\n"); | ||
| 277 | - } | ||
| 278 | - | ||
| 279 | - return STATE_CRITICAL; | ||
| 280 | - } | ||
| 281 | - | ||
| 282 | - return STATE_OK; | ||
| 283 | -} | ||
| 284 | - | ||
| 285 | - | ||
| 286 | - | ||
| 287 | -/* This code was taken from Fyodor's nmap utility, which was originally | ||
| 288 | - taken from the GLIBC 2.0.6 libraries because Solaris doesn't contain | ||
| 289 | - the inet_aton() funtion. */ | ||
| 290 | -int | ||
| 291 | -my_inet_aton (register const char *cp, struct in_addr *addr) | ||
| 292 | -{ | ||
| 293 | - register unsigned int val; /* changed from u_long --david */ | ||
| 294 | - register int base, n; | ||
| 295 | - register char c; | ||
| 296 | - u_int parts[4]; | ||
| 297 | - register u_int *pp = parts; | ||
| 298 | - | ||
| 299 | - c = *cp; | ||
| 300 | - | ||
| 301 | - for (;;) { | ||
| 302 | - | ||
| 303 | - /* | ||
| 304 | - * Collect number up to ``.''. | ||
| 305 | - * Values are specified as for C: | ||
| 306 | - * 0x=hex, 0=octal, isdigit=decimal. | ||
| 307 | - */ | ||
| 308 | - if (!isdigit ((int) c)) | ||
| 309 | - return (0); | ||
| 310 | - val = 0; | ||
| 311 | - base = 10; | ||
| 312 | - | ||
| 313 | - if (c == '0') { | ||
| 314 | - c = *++cp; | ||
| 315 | - if (c == 'x' || c == 'X') | ||
| 316 | - base = 16, c = *++cp; | ||
| 317 | - else | ||
| 318 | - base = 8; | ||
| 319 | - } | ||
| 320 | - | ||
| 321 | - for (;;) { | ||
| 322 | - if (isascii ((int) c) && isdigit ((int) c)) { | ||
| 323 | - val = (val * base) + (c - '0'); | ||
| 324 | - c = *++cp; | ||
| 325 | - } | ||
| 326 | - else if (base == 16 && isascii ((int) c) && isxdigit ((int) c)) { | ||
| 327 | - val = (val << 4) | (c + 10 - (islower ((int) c) ? 'a' : 'A')); | ||
| 328 | - c = *++cp; | ||
| 329 | - } | ||
| 330 | - else | ||
| 331 | - break; | ||
| 332 | - } | ||
| 333 | - | ||
| 334 | - if (c == '.') { | ||
| 335 | - | ||
| 336 | - /* | ||
| 337 | - * Internet format: | ||
| 338 | - * a.b.c.d | ||
| 339 | - * a.b.c (with c treated as 16 bits) | ||
| 340 | - * a.b (with b treated as 24 bits) | ||
| 341 | - */ | ||
| 342 | - if (pp >= parts + 3) | ||
| 343 | - return (0); | ||
| 344 | - *pp++ = val; | ||
| 345 | - c = *++cp; | ||
| 346 | - } | ||
| 347 | - else | ||
| 348 | - break; | ||
| 349 | - } | ||
| 350 | - | ||
| 351 | - /* Check for trailing characters */ | ||
| 352 | - if (c != '\0' && (!isascii ((int) c) || !isspace ((int) c))) | ||
| 353 | - return (0); | ||
| 354 | - | ||
| 355 | - /* Concoct the address according to the number of parts specified */ | ||
| 356 | - n = pp - parts + 1; | ||
| 357 | - switch (n) { | ||
| 358 | - | ||
| 359 | - case 0: | ||
| 360 | - return (0); /* initial nondigit */ | ||
| 361 | - | ||
| 362 | - case 1: /* a -- 32 bits */ | ||
| 363 | - break; | ||
| 364 | - | ||
| 365 | - case 2: /* a.b -- 8.24 bits */ | ||
| 366 | - if (val > 0xffffff) | ||
| 367 | - return (0); | ||
| 368 | - val |= parts[0] << 24; | ||
| 369 | - break; | ||
| 370 | - | ||
| 371 | - case 3: /* a.b.c -- 8.8.16 bits */ | ||
| 372 | - if (val > 0xffff) | ||
| 373 | - return (0); | ||
| 374 | - val |= (parts[0] << 24) | (parts[1] << 16); | ||
| 375 | - break; | ||
| 376 | - | ||
| 377 | - case 4: /* a.b.c.d -- 8.8.8.8 bits */ | ||
| 378 | - if (val > 0xff) | ||
| 379 | - return (0); | ||
| 380 | - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); | ||
| 381 | - break; | ||
| 382 | + struct addrinfo hints; | ||
| 383 | + struct addrinfo *res; | ||
| 384 | + struct protoent *ptrp; | ||
| 385 | + char port_str[6]; | ||
| 386 | + char nbuf[NI_MAXHOST]; | ||
| 387 | + int result; | ||
| 388 | + | ||
| 389 | + /* map the transport protocol name to protocol number */ | ||
| 390 | + ptrp = getprotobyname ((const char *)proto); | ||
| 391 | + if (ptrp == NULL) | ||
| 392 | + { | ||
| 393 | + printf ("Cannot map %s to protocol number\n", proto); | ||
| 394 | + return STATE_UNKNOWN; | ||
| 395 | + } | ||
| 396 | + | ||
| 397 | + memset (&hints, 0, sizeof (hints)); | ||
| 398 | + hints.ai_family = PF_UNSPEC; | ||
| 399 | + hints.ai_protocol = ptrp->p_proto; | ||
| 400 | + | ||
| 401 | + snprintf(port_str, sizeof(port_str), "%d", port); | ||
| 402 | + /* nice clean AF-independent code doesn't matter if passed hostname or IP address */ | ||
| 403 | + result = getaddrinfo (host_name, port_str, &hints, &res); | ||
| 404 | + | ||
| 405 | + if (result != 0) | ||
| 406 | + { | ||
| 407 | + printf ("%s\n", gai_strerror (result)); | ||
| 408 | + return STATE_UNKNOWN; | ||
| 409 | } | ||
| 410 | - | ||
| 411 | - if (addr) | ||
| 412 | - addr->s_addr = htonl (val); | ||
| 413 | - | ||
| 414 | - return (1); | ||
| 415 | + else | ||
| 416 | + { | ||
| 417 | + while (res) | ||
| 418 | + { | ||
| 419 | + /* attempt to create a socket */ | ||
| 420 | + *sd = socket (res->ai_family, (!strcasecmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM, res->ai_protocol); | ||
| 421 | + | ||
| 422 | + if (*sd < 0) { | ||
| 423 | + printf ("Socket creation failed\n"); | ||
| 424 | + freeaddrinfo (res); | ||
| 425 | + return STATE_UNKNOWN; | ||
| 426 | + } | ||
| 427 | + | ||
| 428 | + /* Little debugging here */ | ||
| 429 | + result = getnameinfo (res->ai_addr, res->ai_addrlen, | ||
| 430 | + nbuf, sizeof (nbuf), NULL, 0, NI_NUMERICHOST); | ||
| 431 | + printf ("Connect attempt on socket %d to %s", | ||
| 432 | + *sd, nbuf); | ||
| 433 | + | ||
| 434 | + /* attempt to open a connection */ | ||
| 435 | + result = connect (*sd, res->ai_addr, res->ai_addrlen); | ||
| 436 | + | ||
| 437 | + if (result == 0) | ||
| 438 | + break; | ||
| 439 | + | ||
| 440 | + close(*sd); | ||
| 441 | + res = res->ai_next; | ||
| 442 | + } | ||
| 443 | + freeaddrinfo (res); | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + if (result == 0) | ||
| 447 | + return STATE_OK; | ||
| 448 | + else | ||
| 449 | + { | ||
| 450 | + printf ("%s\n", strerror(errno)); | ||
| 451 | + return STATE_CRITICAL; | ||
| 452 | + } | ||
| 453 | } | ||
| 454 | Index: plugins/netutils.h.in | ||
| 455 | =================================================================== | ||
| 456 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.h.in,v | ||
| 457 | retrieving revision 1.1.1.1 | ||
| 458 | diff -u -r1.1.1.1 netutils.h.in | ||
| 459 | --- plugins/netutils.h.in 28 Feb 2002 06:42:59 -0000 1.1.1.1 | ||
| 460 | +++ plugins/netutils.h.in 10 Dec 2002 19:43:10 -0000 | ||
| 461 | @@ -54,8 +54,6 @@ | ||
| 462 | int my_udp_connect (char *address, int port, int *sd); | ||
| 463 | int my_connect (char *address, int port, int *sd, char *proto); | ||
| 464 | |||
| 465 | -int my_inet_aton (register const char *cp, struct in_addr *addr); | ||
| 466 | - | ||
| 467 | #ifndef DEFAULT_SOCKET_TIMEOUT | ||
| 468 | #include "config.h" | ||
| 469 | #include "common.h" | ||
| 470 | Index: plugins/utils.c | ||
| 471 | =================================================================== | ||
| 472 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v | ||
| 473 | retrieving revision 1.13 | ||
| 474 | diff -u -r1.13 utils.c | ||
| 475 | --- plugins/utils.c 18 Nov 2002 07:22:28 -0000 1.13 | ||
| 476 | +++ plugins/utils.c 10 Dec 2002 19:43:10 -0000 | ||
| 477 | @@ -16,6 +16,9 @@ | ||
| 478 | #include "version.h" | ||
| 479 | #include <stdarg.h> | ||
| 480 | #include <limits.h> | ||
| 481 | +#include <sys/socket.h> | ||
| 482 | +#include <arpa/inet.h> | ||
| 483 | +#include <netdb.h> | ||
| 484 | |||
| 485 | extern int timeout_interval; | ||
| 486 | |||
| 487 | @@ -27,7 +30,8 @@ | ||
| 488 | RETSIGTYPE timeout_alarm_handler (int); | ||
| 489 | |||
| 490 | int is_host (char *); | ||
| 491 | -int is_dotted_quad (char *); | ||
| 492 | +int is_ipv4_addr (char *); | ||
| 493 | +int is_ipv6_addr (char *); | ||
| 494 | int is_hostname (char *); | ||
| 495 | |||
| 496 | int is_integer (char *); | ||
| 497 | @@ -154,25 +158,51 @@ | ||
| 498 | int | ||
| 499 | is_host (char *address) | ||
| 500 | { | ||
| 501 | - if (is_dotted_quad (address) || is_hostname (address)) | ||
| 502 | + if (is_ipv4_addr (address) || is_ipv6_addr (address) || | ||
| 503 | + is_hostname (address)) | ||
| 504 | return (TRUE); | ||
| 505 | + | ||
| 506 | return (FALSE); | ||
| 507 | } | ||
| 508 | |||
| 509 | int | ||
| 510 | -is_dotted_quad (char *address) | ||
| 511 | +is_ipv4_addr (char *address) | ||
| 512 | { | ||
| 513 | - int o1, o2, o3, o4; | ||
| 514 | - char c[1]; | ||
| 515 | + struct addrinfo hints; | ||
| 516 | + struct addrinfo *res; | ||
| 517 | + int retval; | ||
| 518 | |||
| 519 | - if (sscanf (address, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, c) != 4) | ||
| 520 | - return FALSE; | ||
| 521 | - else if (o1 > 255 || o2 > 255 || o3 > 255 || o4 > 255) | ||
| 522 | + memset (&hints, 0, sizeof (hints)); | ||
| 523 | + hints.ai_family = PF_INET; | ||
| 524 | + retval = getaddrinfo (address, NULL, &hints, &res); | ||
| 525 | + | ||
| 526 | + if (retval != 0) | ||
| 527 | return FALSE; | ||
| 528 | - else if (o1 < 0 || o2 < 0 || o3 < 0 || o4 < 0) | ||
| 529 | + else | ||
| 530 | + { | ||
| 531 | + freeaddrinfo (res); | ||
| 532 | + return TRUE; | ||
| 533 | + } | ||
| 534 | +} | ||
| 535 | + | ||
| 536 | +int | ||
| 537 | +is_ipv6_addr (char *address) | ||
| 538 | +{ | ||
| 539 | + struct addrinfo hints; | ||
| 540 | + struct addrinfo *res; | ||
| 541 | + int retval; | ||
| 542 | + | ||
| 543 | + memset (&hints, 0, sizeof (hints)); | ||
| 544 | + hints.ai_family = PF_INET6; | ||
| 545 | + retval = getaddrinfo (address, NULL, &hints, &res); | ||
| 546 | + | ||
| 547 | + if (retval != 0) | ||
| 548 | return FALSE; | ||
| 549 | else | ||
| 550 | + { | ||
| 551 | + freeaddrinfo (res); | ||
| 552 | return TRUE; | ||
| 553 | + } | ||
| 554 | } | ||
| 555 | |||
| 556 | /* from RFC-1035 | ||
| 557 | @@ -185,22 +215,21 @@ | ||
| 558 | int | ||
| 559 | is_hostname (char *s1) | ||
| 560 | { | ||
| 561 | - if (strlen (s1) > 63) | ||
| 562 | - return FALSE; | ||
| 563 | - if (strcspn | ||
| 564 | - (s1, | ||
| 565 | - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") != | ||
| 566 | - 0) return FALSE; | ||
| 567 | - if (strspn (s1, "0123456789-.") == 1) | ||
| 568 | + struct addrinfo hints; | ||
| 569 | + struct addrinfo *res; | ||
| 570 | + int retval; | ||
| 571 | + | ||
| 572 | + memset (&hints, 0, sizeof (hints)); | ||
| 573 | + hints.ai_family = PF_UNSPEC; | ||
| 574 | + retval = getaddrinfo (s1, NULL, &hints, &res); | ||
| 575 | + | ||
| 576 | + if (retval != 0) | ||
| 577 | return FALSE; | ||
| 578 | - while ((s1 = index (s1, '.'))) { | ||
| 579 | - s1++; | ||
| 580 | - if (strspn (s1, "0123456789-.") == 1) { | ||
| 581 | - printf ("%s\n", s1); | ||
| 582 | - return FALSE; | ||
| 583 | - } | ||
| 584 | + else | ||
| 585 | + { | ||
| 586 | + freeaddrinfo (res); | ||
| 587 | + return TRUE; | ||
| 588 | } | ||
| 589 | - return TRUE; | ||
| 590 | } | ||
| 591 | |||
| 592 | int | ||
| 593 | Index: plugins/utils.h.in | ||
| 594 | =================================================================== | ||
| 595 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h.in,v | ||
| 596 | retrieving revision 1.7 | ||
| 597 | diff -u -r1.7 utils.h.in | ||
| 598 | --- plugins/utils.h.in 9 Nov 2002 03:39:35 -0000 1.7 | ||
| 599 | +++ plugins/utils.h.in 10 Dec 2002 19:43:10 -0000 | ||
| 600 | @@ -28,7 +28,8 @@ | ||
| 601 | /* Test input types */ | ||
| 602 | |||
| 603 | int is_host (char *); | ||
| 604 | -int is_dotted_quad (char *); | ||
| 605 | +int is_ipv4_addr (char *); | ||
| 606 | +int is_ipv6_addr (char *); | ||
| 607 | int is_hostname (char *); | ||
| 608 | |||
| 609 | int is_integer (char *); | ||
