[evolution-data-server/camel-socks-proxy] Try all the struct addrinfo when connecting to a proxy, not just the first one



commit 8ce14563d05a4f1085b6ef828b9e03cc80a4d4dd
Author: Federico Mena Quintero <federico novell com>
Date:   Thu Jul 22 15:20:21 2010 -0500

    Try all the struct addrinfo when connecting to a proxy, not just the first one
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-raw.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index d191efc..3609639 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -680,7 +680,7 @@ socket_connect(struct addrinfo *host)
 static PRFileDesc *
 connect_to_proxy (CamelTcpStreamRaw *raw, const char *proxy_host, gint proxy_port, CamelException *ex)
 {
-	struct addrinfo *ai, hints;
+	struct addrinfo *addr, *ai, hints;
 	gchar serv[16];
 	PRFileDesc *fd;
 	gint save_errno;
@@ -694,18 +694,27 @@ connect_to_proxy (CamelTcpStreamRaw *raw, const char *proxy_host, gint proxy_por
 	memset (&hints, 0, sizeof (hints));
 	hints.ai_socktype = SOCK_STREAM;
 
-	ai = camel_getaddrinfo (proxy_host, serv, &hints, ex);
-	if (!ai) {
+	addr = camel_getaddrinfo (proxy_host, serv, &hints, ex);
+	if (!addr) {
 		d (g_print ("  camel_getaddrinfo() for the proxy failed\n}\n"));
 		return NULL;
 	}
 
 	d (g_print ("  creating socket and connecting\n"));
 
-	fd = socket_connect (ai);
+	ai = addr;
+	while (ai) {
+		fd = socket_connect (ai);
+		if (fd)
+			goto out;
+
+		ai = ai->ai_next;
+	}
+
+out:
 	save_errno = errno;
 
-	camel_freeaddrinfo (ai);
+	camel_freeaddrinfo (addr);
 
 	if (!fd) {
 		errno = save_errno;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]