From 614071738f0edeedfa9731c5e3dd63e158bfbc7a Mon Sep 17 00:00:00 2001
From: Karl DeBisschop <kdebisschop@users.sourceforge.net>
Date: Thu, 17 Apr 2003 05:36:20 +0000
Subject: code cleanup to clear strict compiler warnings

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@495 f882894a-f735-0410-b71e-b25c423dba1c

diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 8eb2b9b..f80a9dc 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -1,37 +1,49 @@
-/******************************************************************************
- *
- * 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.
- *****************************************************************************/
+/*****************************************************************************
+*
+* 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@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"
 #include "common.h"
 #include "utils.h"
 #include "popen.h"
 
-const char *progname = "check_dig";
-#define REVISION "$Revision$"
-#define COPYRIGHT "2000-2002"
-#define AUTHOR "Karl DeBisschop"
-#define EMAIL "karl@debisschop.net"
-#define SUMMARY "Test the DNS service on the specified host using dig\n"
-
 int process_arguments (int, char **);
 int validate_arguments (void);
 void print_help (void);
@@ -210,7 +222,7 @@ process_arguments (int argc, char **argv)
 			}
 		}
 		else {
-			asprintf (&dns_server, "127.0.0.1");
+			dns_server = strdup ("127.0.0.1");
 		}
 	}
 
@@ -234,25 +246,13 @@ validate_arguments (void)
 void
 print_help (void)
 {
-	print_revision (progname, "$Revision$");
+	print_revision (progname, revision);
 	printf
 		("Copyright (c) %s %s <%s>\n\n%s\n",
-		 COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
+		 copyright, authors, 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);
+	printf ("\nOptions:\n");
+	printf (options, DEFAULT_SOCKET_TIMEOUT);
 	support ();
 }
 
@@ -263,8 +263,7 @@ print_help (void)
 void
 print_usage (void)
 {
-	printf
-		("Usage: %s -H host -l lookup [-t timeout] [-v]\n"
-		 "       %s --help\n"
-		 "       %s --version\n", progname, progname, progname);
+	printf ("Usage: %s %s\n", progname, option_summary);
+	printf ("       %s (-h|--help)\n", progname);
+	printf ("       %s (-V|--version)\n", progname);
 }
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 5bec291..62efc8c 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,4 +1,4 @@
-/******************************************************************************
+/*****************************************************************************
 *
 * 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
@@ -51,7 +51,9 @@ const char *options = "\
  -r, --refuse=ok|warn|crit\n\
     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\
+    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\
  -V, --version\n\
@@ -63,21 +65,21 @@ const char *options = "\
 #include "utils.h"
 
 #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>
+#  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
 
 #ifdef HAVE_SSL
@@ -134,8 +136,8 @@ main (int argc, char **argv)
 	struct timeval tv;
 
 	if (strstr (argv[0], "check_udp")) {
-		asprintf (&progname, "check_udp");
-		asprintf (&SERVICE, "UDP");
+		progname = strdup ("check_udp");
+		SERVICE = strdup ("UDP");
 		SEND = NULL;
 		EXPECT = NULL;
 		QUIT = NULL;
@@ -143,8 +145,8 @@ main (int argc, char **argv)
 		PORT = 0;
 	}
 	else if (strstr (argv[0], "check_tcp")) {
-		asprintf (&progname, "check_tcp");
-		asprintf (&SERVICE, "TCP");
+		progname = strdup ("check_tcp");
+		SERVICE = strdup ("TCP");
 		SEND = NULL;
 		EXPECT = NULL;
 		QUIT = NULL;
@@ -152,66 +154,66 @@ main (int argc, char **argv)
 		PORT = 0;
 	}
 	else if (strstr (argv[0], "check_ftp")) {
-		asprintf (&progname, "check_ftp");
-		asprintf (&SERVICE, "FTP");
+		progname = strdup ("check_ftp");
+		SERVICE = strdup ("FTP");
 		SEND = NULL;
-		asprintf (&EXPECT, "220");
-		asprintf (&QUIT, "QUIT\r\n");
+		EXPECT = strdup ("220");
+		QUIT = strdup ("QUIT\r\n");
 		PROTOCOL = TCP_PROTOCOL;
 		PORT = 21;
 	}
 	else if (strstr (argv[0], "check_smtp")) {
-		asprintf (&progname, "check_smtp");
-		asprintf (&SERVICE, "SMTP");
+		progname = strdup ("check_smtp");
+		SERVICE = strdup ("SMTP");
 		SEND = NULL;
-		asprintf (&EXPECT, "220");
-		asprintf (&QUIT, "QUIT\r\n");
+		EXPECT = strdup ("220");
+		QUIT = strdup ("QUIT\r\n");
 		PROTOCOL = TCP_PROTOCOL;
 		PORT = 25;
 	}
 	else if (strstr (argv[0], "check_pop")) {
-		asprintf (&progname, "check_pop");
-		asprintf (&SERVICE, "POP");
+		progname = strdup ("check_pop");
+		SERVICE = strdup ("POP");
 		SEND = NULL;
-		asprintf (&EXPECT, "+OK");
-		asprintf (&QUIT, "QUIT\r\n");
+		EXPECT = strdup ("+OK");
+		QUIT = strdup ("QUIT\r\n");
 		PROTOCOL = TCP_PROTOCOL;
 		PORT = 110;
 	}
 	else if (strstr (argv[0], "check_imap")) {
-		asprintf (&progname, "check_imap");
-		asprintf (&SERVICE, "IMAP");
+		progname = strdup ("check_imap");
+		SERVICE = strdup ("IMAP");
 		SEND = NULL;
-		asprintf (&EXPECT, "* OK");
-		asprintf (&QUIT, "a1 LOGOUT\r\n");
+		EXPECT = strdup ("* OK");
+		QUIT = strdup ("a1 LOGOUT\r\n");
 		PROTOCOL = TCP_PROTOCOL;
 		PORT = 143;
 	}
 #ifdef HAVE_SSL
 	else if (strstr(argv[0],"check_simap")) {
-		asprintf (&progname, "check_simap");
-		asprintf (&SERVICE, "SIMAP");
+		progname = strdup ("check_simap");
+		SERVICE = strdup ("SIMAP");
 		SEND=NULL;
-		asprintf (&EXPECT, "* OK");
-		asprintf (&QUIT, "a1 LOGOUT\r\n");
+		EXPECT = strdup ("* OK");
+		QUIT = strdup ("a1 LOGOUT\r\n");
 		PROTOCOL=TCP_PROTOCOL;
 		use_ssl=TRUE;
 		PORT=993;
 	}
 	else if (strstr(argv[0],"check_spop")) {
-		asprintf (&progname, "check_spop");
-		asprintf (&SERVICE, "SPOP");
+		progname = strdup ("check_spop");
+		SERVICE = strdup ("SPOP");
 		SEND=NULL;
-		asprintf (&EXPECT, "+OK");
-		asprintf (&QUIT, "QUIT\r\n");
+		EXPECT = strdup ("+OK");
+		QUIT = strdup ("QUIT\r\n");
 		PROTOCOL=TCP_PROTOCOL;
 		use_ssl=TRUE;
 		PORT=995;
 	}
 #endif
 	else if (strstr (argv[0], "check_nntp")) {
-		asprintf (&progname, "check_nntp");
-		asprintf (&SERVICE, "NNTP");
+		progname = strdup ("check_nntp");
+		SERVICE = strdup ("NNTP");
 		SEND = NULL;
 		EXPECT = NULL;
 		server_expect = realloc (server_expect, ++server_expect_count);
@@ -226,7 +228,7 @@ main (int argc, char **argv)
 		usage ("ERROR: Generic check_tcp called with unknown service\n");
 	}
 
-	asprintf (&server_address, "127.0.0.1");
+	server_address = strdup ("127.0.0.1");
 	server_port = PORT;
 	server_send = SEND;
 	server_quit = QUIT;
@@ -312,17 +314,21 @@ main (int argc, char **argv)
 		}
 	}
 
-	if (server_quit != NULL)
+	if (server_quit != NULL) {
 #ifdef HAVE_SSL
 		if (use_ssl) {
-			SSL_write (ssl, QUIT, strlen (QUIT));
+			SSL_write (ssl, server_quit, strlen (server_quit));
 			SSL_shutdown (ssl);
  			SSL_free (ssl);
  			SSL_CTX_free (ctx);
 		}
-		else
+		else {
+#endif
+			send (sd, server_quit, strlen (server_quit), 0);
+#ifdef HAVE_SSL
+		}
 #endif
-  		send (sd, server_quit, strlen (server_quit), 0);
+	}
 
 	/* close the connection */
 	if (sd)
@@ -511,23 +517,23 @@ process_arguments (int argc, char **argv)
 void
 print_help (void)
 {
-        print_revision (progname, revision);
-        printf ("Copyright (c) %s %s\n\t<%s>\n\n",
-                 copyright, authors, email);
+	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 ();
+	print_usage ();
+	printf ("\nOptions:\n");
+	printf (options, DEFAULT_SOCKET_TIMEOUT);
+	printf (standard_options);
+	support ();
 }
 
 void
 print_usage (void)
 {
-        printf
-                ("Usage: %s %s\n"
-                 "       %s (-h|--help)\n"
-                 "       %s (-V|--version)\n", progname, option_summary, progname, progname);
+	printf ("Usage: %s %s\n", progname, option_summary);
+	printf ("       %s (-h|--help)\n", progname);
+	printf ("       %s (-V|--version)\n", progname);
 }
 
 #ifdef HAVE_SSL
diff --git a/plugins/netutils.c b/plugins/netutils.c
index ce8b428..926547e 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -40,8 +40,10 @@ int was_refused = FALSE;
 void
 socket_timeout_alarm_handler (int sig)
 {
-
-	printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
+	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);
 }
@@ -99,7 +101,7 @@ process_tcp_request2 (char *server_address, int server_port,
 		return STATE_CRITICAL;
 
 	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
-	if (send_result != strlen (send_buffer)) {
+	if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
 		printf ("send() failed\n");
 		result = STATE_WARNING;
 	}
@@ -177,7 +179,7 @@ process_request (char *server_address, int server_port, int proto,
 		return STATE_CRITICAL;
 
 	send_result = send (sd, send_buffer, strlen (send_buffer), 0);
-	if (send_result != strlen (send_buffer)) {
+	if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
 		printf ("send() failed\n");
 		result = STATE_WARNING;
 	}
@@ -248,7 +250,6 @@ my_connect (char *host_name, int port, int *sd, int proto)
 {
 	struct addrinfo hints;
 	struct addrinfo *res;
-	struct addrinfo *ptrp;
 	char port_str[6];
 	int result;
 
@@ -267,7 +268,7 @@ my_connect (char *host_name, int port, int *sd, int proto)
 		while (res) {
 			/* attempt to create a socket */
 			*sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
-				SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
+			              SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
 
 			if (*sd < 0) {
 				printf ("Socket creation failed\n");
@@ -285,13 +286,13 @@ my_connect (char *host_name, int port, int *sd, int proto)
 
 			if (result < 0) {
 				switch (errno) {
-					case ECONNREFUSED:
-						switch (econn_refuse_state) {
-							case STATE_OK:
-							case STATE_WARNING:
-								was_refused = TRUE;
-						}
-						break;
+				case ECONNREFUSED:
+					switch (econn_refuse_state) {
+					case STATE_OK:
+					case STATE_WARNING:
+						was_refused = TRUE;
+					}
+					break;
 				}
 			}
 
@@ -314,55 +315,56 @@ my_connect (char *host_name, int port, int *sd, int proto)
 int
 is_host (char *address)
 {
-        if (is_addr (address) || is_hostname (address))
-                return (TRUE);
+	if (is_addr (address) || is_hostname (address))
+		return (TRUE);
 
-        return (FALSE);
+	return (FALSE);
 }
 
 int
 is_addr (char *address)
 {
+	if (is_inet_addr (address))
+		return (TRUE);
+
 #ifdef USE_IPV6
-        if (is_inet_addr (address) || is_inet6_addr (address))
-#else
-        if (is_inet_addr (address))
+	if (is_inet6_addr (address))
+		return (TRUE);
 #endif
-                return (TRUE);
 
-        return (FALSE);
+	return (FALSE);
 }
 
 int
 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;
-        }
+	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;
+	}
 }
 
 int
 is_inet_addr (char *address)
 {
-        return resolve_host_or_addr (address, AF_INET);
+	return resolve_host_or_addr (address, AF_INET);
 }
 
 #ifdef USE_IPV6
 int
 is_inet6_addr (char *address)
 {
-        return resolve_host_or_addr (address, AF_INET6);
+	return resolve_host_or_addr (address, AF_INET6);
 }
 #endif
 
@@ -370,9 +372,9 @@ int
 is_hostname (char *s1)
 {
 #ifdef USE_IPV6
-        return resolve_host_or_addr (s1, AF_UNSPEC);
+	return resolve_host_or_addr (s1, AF_UNSPEC);
 #else
-        return resolve_host_or_addr (s1, AF_INET);
+	return resolve_host_or_addr (s1, AF_INET);
 #endif
 }
 
-- 
cgit v0.10-9-g596f

