aboutsummaryrefslogtreecommitdiff
path: root/plugins/netutils.c
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-04-17 05:36:20 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-04-17 05:36:20 +0000
commit614071738f0edeedfa9731c5e3dd63e158bfbc7a (patch)
treef048ef38e5889f78f085574f1db97a8a5ee65c9e /plugins/netutils.c
parente01c91d3a039038c7f6be5a323fadf2b595f1409 (diff)
downloadmonitoring-plugins-614071738f0edeedfa9731c5e3dd63e158bfbc7a.tar.gz
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
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index ce8b428b..926547e4 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
}