summaryrefslogtreecommitdiff
path: root/mail/libetpan/patches/patch-af
blob: 2eaec72d53f2a190e93cbc127dfcd9c5349059a1 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$NetBSD: patch-af,v 1.1 2008/01/25 18:26:32 smb Exp $

--- src/data-types/connect.c.orig	2007-08-06 17:32:30.000000000 -0400
+++ src/data-types/connect.c	2008-01-25 13:15:13.000000000 -0500
@@ -88,6 +88,21 @@
   return 0;
 }
 
+#ifdef HAVE_IPV6
+static int verify_sock_errors(int s)
+{
+  uint len;
+  int val;
+  len = sizeof(val);
+  if (getsockopt(s, SOL_SOCKET, SO_ERROR, &val, &len) < 0) {
+    return -1;
+  } else if (val != 0) {
+    return -1;
+  }
+  return 0;
+}
+#endif
+
 static int wait_connect(int s, int r)
 {
   fd_set fds;
@@ -206,6 +221,7 @@
 
   for (ai = res; ai != NULL; ai = ai->ai_next) {
     s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+
     if (s == -1)
       continue;
     
@@ -239,9 +255,23 @@
     
     r = connect(s, ai->ai_addr, ai->ai_addrlen);
     r = wait_connect(s, r);
+    
+    if (r != -1) {
+      r = verify_sock_errors(s);
+    }
+
     if (r == -1) {
+      if (ai->ai_next) {
+#ifdef WIN32
+	  closesocket(s);
+#else
+	  close(s);
+#endif
+	  continue;
+      } else {
       goto close_socket;
     }
+    }
     /* if we're here, we're good */
     break;
   }
@@ -252,7 +282,6 @@
   if (ai == NULL)
     goto err;
 #endif
-  
   return s;
   
  close_socket: