Code

1041571: -D option processing corrected (Eric Chen). Changed process_arguments()...
[nagiosplug.git] / plugins / netutils.c
index c99983f03bd9e68a2cbeb348efce2d0b0a1ed1e3..6702b13f25250439416549681e85f5aa98a8d316 100644 (file)
@@ -27,6 +27,8 @@
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
+* $Id$
+*
 ****************************************************************************/
 
 #include "common.h"
@@ -104,7 +106,7 @@ process_tcp_request2 (const char *server_address, int server_port,
 
        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");
+               printf ("Send failed\n");
                result = STATE_WARNING;
        }
 
@@ -213,7 +215,7 @@ static int
 my_connect (const char *host_name, int port, int *sd, int proto)
 {
        struct addrinfo hints;
-       struct addrinfo *res;
+       struct addrinfo *res, *res0;
        char port_str[6];
        int result;
 
@@ -223,13 +225,14 @@ my_connect (const char *host_name, int port, int *sd, int proto)
        hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
 
        snprintf (port_str, sizeof (port_str), "%d", port);
-       result = getaddrinfo (host_name, port_str, &hints, &res);
+       result = getaddrinfo (host_name, port_str, &hints, &res0);
 
        if (result != 0) {
                printf ("%s\n", gai_strerror (result));
                return STATE_UNKNOWN;
        }
        else {
+               res = res0;
                while (res) {
                        /* attempt to create a socket */
                        *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
@@ -260,7 +263,7 @@ my_connect (const char *host_name, int port, int *sd, int proto)
                        close (*sd);
                        res = res->ai_next;
                }
-               freeaddrinfo (res);
+               freeaddrinfo (res0);
        }
 
        if (result == 0)
@@ -312,7 +315,7 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int
 
        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");
+               printf ("Send failed\n");
                result = STATE_WARNING;
        }
 
@@ -336,7 +339,7 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int
                if (recv_result == -1) {
                        strcpy (recv_buffer, "");
                        if (proto != IPPROTO_TCP)
-                               printf ("recv() failed\n");
+                               printf ("Receive failed\n");
                        result = STATE_WARNING;
                }
                else