diff options
Diffstat (limited to 'web/attachments/37325-nagiosplugins-utils-20021210.diff')
| -rw-r--r-- | web/attachments/37325-nagiosplugins-utils-20021210.diff | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/web/attachments/37325-nagiosplugins-utils-20021210.diff b/web/attachments/37325-nagiosplugins-utils-20021210.diff new file mode 100644 index 0000000..3295f2e --- /dev/null +++ b/web/attachments/37325-nagiosplugins-utils-20021210.diff | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | Index: utils.c | ||
| 2 | =================================================================== | ||
| 3 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v | ||
| 4 | retrieving revision 1.13 | ||
| 5 | diff -u -r1.13 utils.c | ||
| 6 | --- utils.c 18 Nov 2002 07:22:28 -0000 1.13 | ||
| 7 | +++ utils.c 11 Dec 2002 02:39:17 -0000 | ||
| 8 | @@ -16,6 +16,9 @@ | ||
| 9 | #include "version.h" | ||
| 10 | #include <stdarg.h> | ||
| 11 | #include <limits.h> | ||
| 12 | +#include <sys/socket.h> | ||
| 13 | +#include <arpa/inet.h> | ||
| 14 | +#include <netdb.h> | ||
| 15 | |||
| 16 | extern int timeout_interval; | ||
| 17 | |||
| 18 | @@ -27,7 +30,9 @@ | ||
| 19 | RETSIGTYPE timeout_alarm_handler (int); | ||
| 20 | |||
| 21 | int is_host (char *); | ||
| 22 | -int is_dotted_quad (char *); | ||
| 23 | +int resolve_host_or_addr (char *, int); | ||
| 24 | +int is_ipv4_addr (char *); | ||
| 25 | +int is_ipv6_addr (char *); | ||
| 26 | int is_hostname (char *); | ||
| 27 | |||
| 28 | int is_integer (char *); | ||
| 29 | @@ -154,53 +159,49 @@ | ||
| 30 | int | ||
| 31 | is_host (char *address) | ||
| 32 | { | ||
| 33 | - if (is_dotted_quad (address) || is_hostname (address)) | ||
| 34 | + if (is_ipv4_addr (address) || is_ipv6_addr (address) || | ||
| 35 | + is_hostname (address)) | ||
| 36 | return (TRUE); | ||
| 37 | + | ||
| 38 | return (FALSE); | ||
| 39 | } | ||
| 40 | |||
| 41 | int | ||
| 42 | -is_dotted_quad (char *address) | ||
| 43 | +resolve_host_or_addr (char *address, int family) | ||
| 44 | { | ||
| 45 | - int o1, o2, o3, o4; | ||
| 46 | - char c[1]; | ||
| 47 | + struct addrinfo hints; | ||
| 48 | + struct addrinfo *res; | ||
| 49 | + int retval; | ||
| 50 | |||
| 51 | - if (sscanf (address, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, c) != 4) | ||
| 52 | - return FALSE; | ||
| 53 | - else if (o1 > 255 || o2 > 255 || o3 > 255 || o4 > 255) | ||
| 54 | - return FALSE; | ||
| 55 | - else if (o1 < 0 || o2 < 0 || o3 < 0 || o4 < 0) | ||
| 56 | + memset (&hints, 0, sizeof (hints)); | ||
| 57 | + hints.ai_family = family; | ||
| 58 | + retval = getaddrinfo (address, NULL, &hints, &res); | ||
| 59 | + | ||
| 60 | + if (retval != 0) | ||
| 61 | return FALSE; | ||
| 62 | else | ||
| 63 | + { | ||
| 64 | + freeaddrinfo (res); | ||
| 65 | return TRUE; | ||
| 66 | + } | ||
| 67 | } | ||
| 68 | |||
| 69 | -/* from RFC-1035 | ||
| 70 | - * | ||
| 71 | - * The labels must follow the rules for ARPANET host names. They must | ||
| 72 | - * start with a letter, end with a letter or digit, and have as interior | ||
| 73 | - * characters only letters, digits, and hyphen. There are also some | ||
| 74 | - * restrictions on the length. Labels must be 63 characters or less. */ | ||
| 75 | +int | ||
| 76 | +is_ipv4_addr (char *address) | ||
| 77 | +{ | ||
| 78 | + return resolve_host_or_addr (address, AF_INET); | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +int | ||
| 82 | +is_ipv6_addr (char *address) | ||
| 83 | +{ | ||
| 84 | + return resolve_host_or_addr (address, AF_INET6); | ||
| 85 | +} | ||
| 86 | |||
| 87 | int | ||
| 88 | is_hostname (char *s1) | ||
| 89 | { | ||
| 90 | - if (strlen (s1) > 63) | ||
| 91 | - return FALSE; | ||
| 92 | - if (strcspn | ||
| 93 | - (s1, | ||
| 94 | - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") != | ||
| 95 | - 0) return FALSE; | ||
| 96 | - if (strspn (s1, "0123456789-.") == 1) | ||
| 97 | - return FALSE; | ||
| 98 | - while ((s1 = index (s1, '.'))) { | ||
| 99 | - s1++; | ||
| 100 | - if (strspn (s1, "0123456789-.") == 1) { | ||
| 101 | - printf ("%s\n", s1); | ||
| 102 | - return FALSE; | ||
| 103 | - } | ||
| 104 | - } | ||
| 105 | - return TRUE; | ||
| 106 | + return resolve_host_or_addr (s1, AF_UNSPEC); | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | Index: utils.h.in | ||
| 111 | =================================================================== | ||
| 112 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h.in,v | ||
| 113 | retrieving revision 1.7 | ||
| 114 | diff -u -r1.7 utils.h.in | ||
| 115 | --- utils.h.in 9 Nov 2002 03:39:35 -0000 1.7 | ||
| 116 | +++ utils.h.in 11 Dec 2002 02:39:17 -0000 | ||
| 117 | @@ -28,7 +28,8 @@ | ||
| 118 | /* Test input types */ | ||
| 119 | |||
| 120 | int is_host (char *); | ||
| 121 | -int is_dotted_quad (char *); | ||
| 122 | +int is_ipv4_addr (char *); | ||
| 123 | +int is_ipv6_addr (char *); | ||
| 124 | int is_hostname (char *); | ||
| 125 | |||
| 126 | int is_integer (char *); | ||
