Re: [Nagios-devel] [Patch] IPv6 capable check_* for nagios

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

Re: [Nagios-devel] [Patch] IPv6 capable check_* for nagios

Post by Guest »

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

A look at the CVS HEAD of the nagios plugins would find that
full AF-independent support is already available at this time.

Regards,
Jeremy

On Fri, Aug 08, 2003 at 04:36:38PM +0100, Colm MacCarthaigh wrote:
>=20
> 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=20
> plugins/netutils.c to be ipv6 compatible. Patch is attached :)
>=20
> This makes many of the check_ plugins for netsaint/nagios work with
> ipv6/v4 , it also handles things like round-robin DNS more properly.
>=20
> Please CC on any mails, I'm not on the list :)
>=20
> --=20
> Colm MacC?rthaigh / HEAnet, Teach Brooklawn, / Innealt?ir Ghr?as?in
> +353 1 6609040 / B?thar Shelbourne, B?C, IE / http://www.hea.net/

> diff -ru nagios-plugins-1.3.1/plugins/netutils.c nagios-plugins-1.3.1.hea=
net/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 20=
03
> @@ -48,8 +48,6 @@
> int my_udp_connect (char *, int, int *);
> int my_connect (char *, int, int *, char *);
> =20
> -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 =3D PF_UNSPEC;
> + hints.ai_socktype =3D (!strcmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STRE=
AM;
> + snprintf(str_port, sizeof(str_port), "%d", port);
> =20
> - bzero ((char *) &servaddr, sizeof (servaddr));
> - servaddr.sin_family =3D AF_INET;
> - servaddr.sin_port =3D htons (port);
> + /* map transport protocol name to protocol number */
> + if (getprotobyname (proto) =3D=3D NULL) {
> + printf ("Cannot map \"%s\" to protocol number\n", proto);
> + return STATE_UNKNOWN;
> + }
> =20
> /* 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 =3D gethostbyname ((const char *) host_name);
> - if (hp =3D=3D NULL) {
> + hints.ai_flags =3D AI_NUMERICHOST;
> + if ( getaddrinfo( host_name, str_port, &hints, &res ) + =09
> + hints.ai_flags =3D 0x0;
> + =09
> + if (getaddrinfo( host_name, str_port, &hints, &res) 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 =3D getprotobyname (proto)) =3D=3D NULL) {
> - printf ("Cannot map \"%s\" to protocol number\n", proto);
> - return STATE_UNKNOWN;
> }
> =20
> /* create a socket */
> - *sd =3D
> - socket (PF_INET, (!strcmp (proto, "udp")) ? SOCK_DGRAM : SOCK_STREAM,
> - ptrp->p_proto);
> - if (*sd - printf ("Socket creation failed\n");
> - return STATE_UNKNOWN;
> - }
> + do {
> + *sd =3D socket (res->ai_family, res->ai_socktype, res->ai_protocol);
> +
> + if (*sd + printf ("Socket creation failed\n");
> + return STATE_UNKNOWN;
> + }
> +
> + /* open a connection */
> + if ( (result =3D connect (*sd, (struct sockaddr *) res->ai_addr,=20
> + res->ai_addrlen )) >=3D 0) {
> + /* Success */
> + break;
> + }
> +
> + res =3D res->ai_next;
> + } while (res);
> =20
> - /* open a connection */
> - result =3D connect (*sd, (struct sockaddr *) &servaddr, sizeof (servadd=
r));
> + /* None of the records matched */
> if (result switch (errno) {
> case ECONNREFUSED:
> @@ -323,109 +329,4 @@
> }
> =20
> return STATE_OK;
> -}
> -
> -
> -
> -/* This code was taken fro

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked