[Nagiosplug-checkins] CVS: nagiosplug/plugins netutils.c,1.6,1.7 check_dig.c,1.10,1.11 check_tcp.c,1.19,1.20

Karl DeBisschop kdebisschop at users.sourceforge.net
Wed Apr 16 22:37:03 CEST 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv31253

Modified Files:
	netutils.c check_dig.c check_tcp.c 
Log Message:
code cleanup to clear strict compiler warnings

Index: netutils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** netutils.c	18 Mar 2003 07:57:48 -0000	1.6
--- netutils.c	17 Apr 2003 05:36:20 -0000	1.7
***************
*** 41,46 ****
  socket_timeout_alarm_handler (int sig)
  {
! 
! 	printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
  
  	exit (STATE_CRITICAL);
--- 41,48 ----
  socket_timeout_alarm_handler (int sig)
  {
! 	if (sig == SIGALRM)
! 		printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
! 	else
! 		printf ("CRITICAL - Abnormal timeout after %d seconds\n", socket_timeout);
  
  	exit (STATE_CRITICAL);
***************
*** 100,104 ****
  
  	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
! 	if (send_result != strlen (send_buffer)) {
  		printf ("send() failed\n");
  		result = STATE_WARNING;
--- 102,106 ----
  
  	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
! 	if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
  		printf ("send() failed\n");
  		result = STATE_WARNING;
***************
*** 178,182 ****
  
  	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
! 	if (send_result != strlen (send_buffer)) {
  		printf ("send() failed\n");
  		result = STATE_WARNING;
--- 180,184 ----
  
  	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
! 	if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
  		printf ("send() failed\n");
  		result = STATE_WARNING;
***************
*** 249,253 ****
  	struct addrinfo hints;
  	struct addrinfo *res;
- 	struct addrinfo *ptrp;
  	char port_str[6];
  	int result;
--- 251,254 ----
***************
*** 268,272 ****
  			/* attempt to create a socket */
  			*sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
! 				SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
  
  			if (*sd < 0) {
--- 269,273 ----
  			/* attempt to create a socket */
  			*sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
! 			              SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
  
  			if (*sd < 0) {
***************
*** 286,296 ****
  			if (result < 0) {
  				switch (errno) {
! 					case ECONNREFUSED:
! 						switch (econn_refuse_state) {
! 							case STATE_OK:
! 							case STATE_WARNING:
! 								was_refused = TRUE;
! 						}
! 						break;
  				}
  			}
--- 287,297 ----
  			if (result < 0) {
  				switch (errno) {
! 				case ECONNREFUSED:
! 					switch (econn_refuse_state) {
! 					case STATE_OK:
! 					case STATE_WARNING:
! 						was_refused = TRUE;
! 					}
! 					break;
  				}
  			}
***************
*** 315,322 ****
  is_host (char *address)
  {
!         if (is_addr (address) || is_hostname (address))
!                 return (TRUE);
  
!         return (FALSE);
  }
  
--- 316,323 ----
  is_host (char *address)
  {
! 	if (is_addr (address) || is_hostname (address))
! 		return (TRUE);
  
! 	return (FALSE);
  }
  
***************
*** 324,335 ****
  is_addr (char *address)
  {
  #ifdef USE_IPV6
!         if (is_inet_addr (address) || is_inet6_addr (address))
! #else
!         if (is_inet_addr (address))
  #endif
-                 return (TRUE);
  
!         return (FALSE);
  }
  
--- 325,337 ----
  is_addr (char *address)
  {
+ 	if (is_inet_addr (address))
+ 		return (TRUE);
+ 
  #ifdef USE_IPV6
! 	if (is_inet6_addr (address))
! 		return (TRUE);
  #endif
  
! 	return (FALSE);
  }
  
***************
*** 337,354 ****
  resolve_host_or_addr (char *address, int family)
  {
!         struct addrinfo hints;
!         struct addrinfo *res;
!         int retval;
! 
!         memset (&hints, 0, sizeof (hints));
!         hints.ai_family = family;
!         retval = getaddrinfo (address, NULL, &hints, &res);
! 
!         if (retval != 0)
!                 return FALSE;
!         else {
!                 freeaddrinfo (res);
!                 return TRUE;
!         }
  }
  
--- 339,356 ----
  resolve_host_or_addr (char *address, int family)
  {
! 	struct addrinfo hints;
! 	struct addrinfo *res;
! 	int retval;
! 
! 	memset (&hints, 0, sizeof (hints));
! 	hints.ai_family = family;
! 	retval = getaddrinfo (address, NULL, &hints, &res);
! 
! 	if (retval != 0)
! 		return FALSE;
! 	else {
! 		freeaddrinfo (res);
! 		return TRUE;
! 	}
  }
  
***************
*** 356,360 ****
  is_inet_addr (char *address)
  {
!         return resolve_host_or_addr (address, AF_INET);
  }
  
--- 358,362 ----
  is_inet_addr (char *address)
  {
! 	return resolve_host_or_addr (address, AF_INET);
  }
  
***************
*** 363,367 ****
  is_inet6_addr (char *address)
  {
!         return resolve_host_or_addr (address, AF_INET6);
  }
  #endif
--- 365,369 ----
  is_inet6_addr (char *address)
  {
! 	return resolve_host_or_addr (address, AF_INET6);
  }
  #endif
***************
*** 371,377 ****
  {
  #ifdef USE_IPV6
!         return resolve_host_or_addr (s1, AF_UNSPEC);
  #else
!         return resolve_host_or_addr (s1, AF_INET);
  #endif
  }
--- 373,379 ----
  {
  #ifdef USE_IPV6
! 	return resolve_host_or_addr (s1, AF_UNSPEC);
  #else
! 	return resolve_host_or_addr (s1, AF_INET);
  #endif
  }

Index: check_dig.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dig.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** check_dig.c	12 Mar 2003 02:29:48 -0000	1.10
--- check_dig.c	17 Apr 2003 05:36:20 -0000	1.11
***************
*** 1,23 ****
! /******************************************************************************
!  *
!  * Program: SNMP plugin for Nagios
!  * License: GPL
!  *
!  * License Information:
!  *
!  * This program is free software; you can redistribute it and/or modify
!  * it under the terms of the GNU General Public License as published by
!  * the Free Software Foundation; either version 2 of the License, or
!  * (at your option) any later version.
!  *
!  * This program is distributed in the hope that it will be useful,
!  * but WITHOUT ANY WARRANTY; without even the implied warranty of
!  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!  * GNU General Public License for more details.
!  *
!  * You should have received a copy of the GNU General Public License
!  * along with this program; if not, write to the Free Software
!  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!  *****************************************************************************/
  
  #include "config.h"
--- 1,42 ----
! /*****************************************************************************
! *
! * This program is free software; you can redistribute it and/or modify
! * it under the terms of the GNU General Public License as published by
! * the Free Software Foundation; either version 2 of the License, or
! * (at your option) any later version.
! *
! * This program is distributed in the hope that it will be useful,
! * but WITHOUT ANY WARRANTY; without even the implied warranty of
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! * GNU General Public License for more details.
! *
! * You should have received a copy of the GNU General Public License
! * along with this program; if not, write to the Free Software
! * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
! *
! *****************************************************************************/
! 
! const char *progname = "check_dig";
! const char *revision = "$Revision$";
! const char *copyright = "2002-2003";
! const char *authors = "Nagios Plugin Development Team";
! const char *email = "nagiosplug-devel at lists.sourceforge.net";
! const char *summary = "Test the DNS service on the specified host using dig\n";
! 
! const char *option_summary = "-H host -l lookup [-t timeout] [-v]";
! 
! const char *options = "\
!  -H, --hostname=STRING or IPADDRESS\n\
!    Check server on the indicated host\n\
!  -l, --lookup=STRING\n\
!    machine name to lookup\n\
!  -t, --timeout=INTEGER\n\
!    Seconds before connection attempt times out (default: %d)\n\
!  -v, --verbose\n\
!    Print extra information (command-line use only)\n\
!  -h, --help\n\
!    Print detailed help screen\n\
!  -V, --version\n\
!    Print version information\n\n";
  
  #include "config.h"
***************
*** 26,36 ****
  #include "popen.h"
  
- const char *progname = "check_dig";
- #define REVISION "$Revision$"
- #define COPYRIGHT "2000-2002"
- #define AUTHOR "Karl DeBisschop"
- #define EMAIL "karl at debisschop.net"
- #define SUMMARY "Test the DNS service on the specified host using dig\n"
- 
  int process_arguments (int, char **);
  int validate_arguments (void);
--- 45,48 ----
***************
*** 211,215 ****
  		}
  		else {
! 			asprintf (&dns_server, "127.0.0.1");
  		}
  	}
--- 223,227 ----
  		}
  		else {
! 			dns_server = strdup ("127.0.0.1");
  		}
  	}
***************
*** 235,257 ****
  print_help (void)
  {
! 	print_revision (progname, "$Revision$");
  	printf
  		("Copyright (c) %s %s <%s>\n\n%s\n",
! 		 COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
  	print_usage ();
! 	printf
! 		("\nOptions:\n"
! 		 " -H, --hostname=STRING or IPADDRESS\n"
! 		 "   Check server on the indicated host\n"
! 		 " -l, --lookup=STRING\n"
! 		 "   machine name to lookup\n"
! 		 " -t, --timeout=INTEGER\n"
! 		 "   Seconds before connection attempt times out (default: %d)\n"
! 		 " -v, --verbose\n"
! 		 "   Print extra information (command-line use only)\n"
! 		 " -h, --help\n"
! 		 "   Print detailed help screen\n"
! 		 " -V, --version\n"
! 		 "   Print version information\n\n", DEFAULT_SOCKET_TIMEOUT);
  	support ();
  }
--- 247,257 ----
  print_help (void)
  {
! 	print_revision (progname, revision);
  	printf
  		("Copyright (c) %s %s <%s>\n\n%s\n",
! 		 copyright, authors, email, summary);
  	print_usage ();
! 	printf ("\nOptions:\n");
! 	printf (options, DEFAULT_SOCKET_TIMEOUT);
  	support ();
  }
***************
*** 264,270 ****
  print_usage (void)
  {
! 	printf
! 		("Usage: %s -H host -l lookup [-t timeout] [-v]\n"
! 		 "       %s --help\n"
! 		 "       %s --version\n", progname, progname, progname);
  }
--- 264,269 ----
  print_usage (void)
  {
! 	printf ("Usage: %s %s\n", progname, option_summary);
! 	printf ("       %s (-h|--help)\n", progname);
! 	printf ("       %s (-V|--version)\n", progname);
  }

Index: check_tcp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_tcp.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** check_tcp.c	16 Mar 2003 23:28:49 -0000	1.19
--- check_tcp.c	17 Apr 2003 05:36:20 -0000	1.20
***************
*** 1,3 ****
! /******************************************************************************
  *
  * This program is free software; you can redistribute it and/or modify
--- 1,3 ----
! /*****************************************************************************
  *
  * This program is free software; you can redistribute it and/or modify
***************
*** 52,56 ****
      Accept tcp refusals with states ok, warn, crit (default: crit)\n\
   -v\n\
!     Show details for command-line debugging (do not use with nagios server)\n\
   -h, --help\n\
      Print detailed help screen\n\
--- 52,58 ----
      Accept tcp refusals with states ok, warn, crit (default: crit)\n\
   -v\n\
!     Show details for command-line debugging (do not use with nagios server)\n";
! 
! const char *standard_options = "\
   -h, --help\n\
      Print detailed help screen\n\
***************
*** 64,82 ****
  
  #ifdef HAVE_SSL_H
! #include <rsa.h>
! #include <crypto.h>
! #include <x509.h>
! #include <pem.h>
! #include <ssl.h>
! #include <err.h>
! #endif
! 
! #ifdef HAVE_OPENSSL_SSL_H
! #include <openssl/rsa.h>
! #include <openssl/crypto.h>
! #include <openssl/x509.h>
! #include <openssl/pem.h>
! #include <openssl/ssl.h>
! #include <openssl/err.h>
  #endif
  
--- 66,84 ----
  
  #ifdef HAVE_SSL_H
! #  include <rsa.h>
! #  include <crypto.h>
! #  include <x509.h>
! #  include <pem.h>
! #  include <ssl.h>
! #  include <err.h>
! #else
! #  ifdef HAVE_OPENSSL_SSL_H
! #    include <openssl/rsa.h>
! #    include <openssl/crypto.h>
! #    include <openssl/x509.h>
! #    include <openssl/pem.h>
! #    include <openssl/ssl.h>
! #    include <openssl/err.h>
! #  endif
  #endif
  
***************
*** 135,140 ****
  
  	if (strstr (argv[0], "check_udp")) {
! 		asprintf (&progname, "check_udp");
! 		asprintf (&SERVICE, "UDP");
  		SEND = NULL;
  		EXPECT = NULL;
--- 137,142 ----
  
  	if (strstr (argv[0], "check_udp")) {
! 		progname = strdup ("check_udp");
! 		SERVICE = strdup ("UDP");
  		SEND = NULL;
  		EXPECT = NULL;
***************
*** 144,149 ****
  	}
  	else if (strstr (argv[0], "check_tcp")) {
! 		asprintf (&progname, "check_tcp");
! 		asprintf (&SERVICE, "TCP");
  		SEND = NULL;
  		EXPECT = NULL;
--- 146,151 ----
  	}
  	else if (strstr (argv[0], "check_tcp")) {
! 		progname = strdup ("check_tcp");
! 		SERVICE = strdup ("TCP");
  		SEND = NULL;
  		EXPECT = NULL;
***************
*** 153,188 ****
  	}
  	else if (strstr (argv[0], "check_ftp")) {
! 		asprintf (&progname, "check_ftp");
! 		asprintf (&SERVICE, "FTP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "220");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 21;
  	}
  	else if (strstr (argv[0], "check_smtp")) {
! 		asprintf (&progname, "check_smtp");
! 		asprintf (&SERVICE, "SMTP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "220");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 25;
  	}
  	else if (strstr (argv[0], "check_pop")) {
! 		asprintf (&progname, "check_pop");
! 		asprintf (&SERVICE, "POP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "+OK");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 110;
  	}
  	else if (strstr (argv[0], "check_imap")) {
! 		asprintf (&progname, "check_imap");
! 		asprintf (&SERVICE, "IMAP");
  		SEND = NULL;
! 		asprintf (&EXPECT, "* OK");
! 		asprintf (&QUIT, "a1 LOGOUT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 143;
--- 155,190 ----
  	}
  	else if (strstr (argv[0], "check_ftp")) {
! 		progname = strdup ("check_ftp");
! 		SERVICE = strdup ("FTP");
  		SEND = NULL;
! 		EXPECT = strdup ("220");
! 		QUIT = strdup ("QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 21;
  	}
  	else if (strstr (argv[0], "check_smtp")) {
! 		progname = strdup ("check_smtp");
! 		SERVICE = strdup ("SMTP");
  		SEND = NULL;
! 		EXPECT = strdup ("220");
! 		QUIT = strdup ("QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 25;
  	}
  	else if (strstr (argv[0], "check_pop")) {
! 		progname = strdup ("check_pop");
! 		SERVICE = strdup ("POP");
  		SEND = NULL;
! 		EXPECT = strdup ("+OK");
! 		QUIT = strdup ("QUIT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 110;
  	}
  	else if (strstr (argv[0], "check_imap")) {
! 		progname = strdup ("check_imap");
! 		SERVICE = strdup ("IMAP");
  		SEND = NULL;
! 		EXPECT = strdup ("* OK");
! 		QUIT = strdup ("a1 LOGOUT\r\n");
  		PROTOCOL = TCP_PROTOCOL;
  		PORT = 143;
***************
*** 190,198 ****
  #ifdef HAVE_SSL
  	else if (strstr(argv[0],"check_simap")) {
! 		asprintf (&progname, "check_simap");
! 		asprintf (&SERVICE, "SIMAP");
  		SEND=NULL;
! 		asprintf (&EXPECT, "* OK");
! 		asprintf (&QUIT, "a1 LOGOUT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
--- 192,200 ----
  #ifdef HAVE_SSL
  	else if (strstr(argv[0],"check_simap")) {
! 		progname = strdup ("check_simap");
! 		SERVICE = strdup ("SIMAP");
  		SEND=NULL;
! 		EXPECT = strdup ("* OK");
! 		QUIT = strdup ("a1 LOGOUT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
***************
*** 200,208 ****
  	}
  	else if (strstr(argv[0],"check_spop")) {
! 		asprintf (&progname, "check_spop");
! 		asprintf (&SERVICE, "SPOP");
  		SEND=NULL;
! 		asprintf (&EXPECT, "+OK");
! 		asprintf (&QUIT, "QUIT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
--- 202,210 ----
  	}
  	else if (strstr(argv[0],"check_spop")) {
! 		progname = strdup ("check_spop");
! 		SERVICE = strdup ("SPOP");
  		SEND=NULL;
! 		EXPECT = strdup ("+OK");
! 		QUIT = strdup ("QUIT\r\n");
  		PROTOCOL=TCP_PROTOCOL;
  		use_ssl=TRUE;
***************
*** 211,216 ****
  #endif
  	else if (strstr (argv[0], "check_nntp")) {
! 		asprintf (&progname, "check_nntp");
! 		asprintf (&SERVICE, "NNTP");
  		SEND = NULL;
  		EXPECT = NULL;
--- 213,218 ----
  #endif
  	else if (strstr (argv[0], "check_nntp")) {
! 		progname = strdup ("check_nntp");
! 		SERVICE = strdup ("NNTP");
  		SEND = NULL;
  		EXPECT = NULL;
***************
*** 227,231 ****
  	}
  
! 	asprintf (&server_address, "127.0.0.1");
  	server_port = PORT;
  	server_send = SEND;
--- 229,233 ----
  	}
  
! 	server_address = strdup ("127.0.0.1");
  	server_port = PORT;
  	server_send = SEND;
***************
*** 313,327 ****
  	}
  
! 	if (server_quit != NULL)
  #ifdef HAVE_SSL
  		if (use_ssl) {
! 			SSL_write (ssl, QUIT, strlen (QUIT));
  			SSL_shutdown (ssl);
   			SSL_free (ssl);
   			SSL_CTX_free (ctx);
  		}
! 		else
  #endif
!   		send (sd, server_quit, strlen (server_quit), 0);
  
  	/* close the connection */
--- 315,333 ----
  	}
  
! 	if (server_quit != NULL) {
  #ifdef HAVE_SSL
  		if (use_ssl) {
! 			SSL_write (ssl, server_quit, strlen (server_quit));
  			SSL_shutdown (ssl);
   			SSL_free (ssl);
   			SSL_CTX_free (ctx);
  		}
! 		else {
! #endif
! 			send (sd, server_quit, strlen (server_quit), 0);
! #ifdef HAVE_SSL
! 		}
  #endif
! 	}
  
  	/* close the connection */
***************
*** 512,523 ****
  print_help (void)
  {
!         print_revision (progname, revision);
!         printf ("Copyright (c) %s %s\n\t<%s>\n\n",
!                  copyright, authors, email);
  	printf (summary, SERVICE);
!         print_usage ();
!         printf ("\nOptions:\n");
!         printf (options, DEFAULT_SOCKET_TIMEOUT);
!         support ();
  }
  
--- 518,530 ----
  print_help (void)
  {
! 	print_revision (progname, revision);
! 	printf ("Copyright (c) %s %s\n\t<%s>\n\n",
! 	        copyright, authors, email);
  	printf (summary, SERVICE);
! 	print_usage ();
! 	printf ("\nOptions:\n");
! 	printf (options, DEFAULT_SOCKET_TIMEOUT);
! 	printf (standard_options);
! 	support ();
  }
  
***************
*** 525,532 ****
  print_usage (void)
  {
!         printf
!                 ("Usage: %s %s\n"
!                  "       %s (-h|--help)\n"
!                  "       %s (-V|--version)\n", progname, option_summary, progname, progname);
  }
  
--- 532,538 ----
  print_usage (void)
  {
! 	printf ("Usage: %s %s\n", progname, option_summary);
! 	printf ("       %s (-h|--help)\n", progname);
! 	printf ("       %s (-V|--version)\n", progname);
  }
  





More information about the Commits mailing list