Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
I don't know if a patch exists already, but since the version of nagios
plugins I downloaded today (1.3.1) doesnt support IPv6 I've patched
plugins/netutils.c to be ipv6 compatible. Patch is attached
This makes many of the check_ plugins for netsaint/nagios work with
ipv6/v4 , it also handles things like round-robin DNS more properly.
Please CC on any mails, I'm not on the list
--
Colm MacCárthaigh / HEAnet, Teach Brooklawn, / Innealtóir Ghréasáin
+353 1 6609040 / Bóthar Shelbourne, BÁC, IE / http://www.hea.net/
--WIyZ46R2i8wDzkSu
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: attachment; filename="ipv6.patch"
diff -ru nagios-plugins-1.3.1/plugins/netutils.c nagios-plugins-1.3.1.heanet/plugins/netutils.c
--- nagios-plugins-1.3.1/plugins/netutils.c Thu Feb 28 06:42:59 2002
+++ nagios-plugins-1.3.1.heanet/plugins/netutils.c Fri Aug 8 16:28:22 2003
@@ -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,45 +263,53 @@
int
my_connect (char *host_name, int port, int *sd, char *proto)
{
- struct sockaddr_in servaddr;
- struct hostent *hp;
- struct protoent *ptrp;
- int result;
+ struct addrinfo * res, hints;
+ char str_port[6];
+ int result;
+
+ bzero ((char *) &hints, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = (!strcmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM;
+ snprintf(str_port, sizeof(str_port), "%d", port);
- bzero ((char *) &servaddr, sizeof (servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_port = htons (port);
+ /* map transport protocol name to protocol number */
+ if (getprotobyname (proto) == NULL) {
+ printf ("Cannot map \"%s\" to protocol number\n", proto);
+ return STATE_UNKNOWN;
+ }
/* 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) {
+ hints.ai_flags = AI_NUMERICHOST;
+ if ( getaddrinfo( host_name, str_port, &hints, &res ) 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 ai_family, res->ai_socktype, res->ai_protocol);
+
+ if (*sd ai_addr,
+ res->ai_addrlen )) >= 0) {
+ /* Success */
+ break;
+ }
+
+ res = res->ai_next;
+ } while (res);
- /* open a connection */
- result = connect (*sd, (struct sockaddr *) &servaddr, sizeof (servaddr));
+ /* None of the records matched */
if (result < 0) {
switch (errno) {
case ECONNREFUSED:
@@ -323,109 +329,4 @@
}
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
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]