[hackers] [ii] [PATCH] Fix traversal of addrinfo list

From: Michael Forney <mforney_AT_mforney.org>
Date: Sat, 25 May 2019 19:27:36 -0700

Although the loop is executed once for every result, in each iteration
it connects to the first result.
---
 ii.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ii.c b/ii.c
index 6d2bd36..55d5f52 100644
--- a/ii.c
+++ b/ii.c
_AT_@ -377,10 +377,10 @@ tcpopen(const char *host, const char *service)
 	}
 
 	for (rp = res; rp; rp = rp->ai_next) {
-		fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+		fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
 		if (fd == -1)
 			continue;
-		if (connect(fd, res->ai_addr, res->ai_addrlen) == -1) {
+		if (connect(fd, rp->ai_addr, rp->ai_addrlen) == -1) {
 			close(fd);
 			fd = -1;
 			continue;
-- 
2.20.1
Received on Sun May 26 2019 - 04:27:36 CEST

This archive was generated by hypermail 2.3.0 : Sun May 26 2019 - 12:12:24 CEST