summaryrefslogtreecommitdiff
path: root/net-mgmt/nagios-plugins/files/patch-plugins_netutils.c
blob: b211deaf46153d2e03252b271268a6c9e70f4c42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--- plugins/netutils.c.orig	2016-08-01 16:27:46 UTC
+++ plugins/netutils.c
@@ -179,7 +179,7 @@ int
 np_net_connect (const char *host_name, int port, int *sd, int proto)
 {
 	struct addrinfo hints;
-	struct addrinfo *res;
+	struct addrinfo *res, *res0;
 	struct sockaddr_un su;
 	char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
 	size_t len;
@@ -206,7 +206,7 @@ np_net_connect (const char *host_name, i
 		memcpy (host, host_name, len);
 		host[len] = '\0';
 		snprintf (port_str, sizeof (port_str), "%d", port);
-		result = getaddrinfo (host, port_str, &hints, &res);
+		result = getaddrinfo (host, port_str, &hints, &res0);
 
 		if (result != 0) {
 			if (result == EAI_NONAME)
@@ -215,6 +215,7 @@ np_net_connect (const char *host_name, i
 				printf ("%s\n", gai_strerror (result));
 			return STATE_UNKNOWN;
 		}
+		res = res0;
 
 		while (res) {
 			/* attempt to create a socket */
@@ -222,7 +223,7 @@ np_net_connect (const char *host_name, i
 
 			if (*sd < 0) {
 				printf ("%s\n", _("Socket creation failed"));
-				freeaddrinfo (res);
+				freeaddrinfo (res0);
 				return STATE_UNKNOWN;
 			}
 
@@ -245,7 +246,7 @@ np_net_connect (const char *host_name, i
 			close (*sd);
 			res = res->ai_next;
 		}
-		freeaddrinfo (res);
+		freeaddrinfo (res0);
 	}
 	/* else the hostname is interpreted as a path to a unix socket */
 	else {