aboutsummaryrefslogtreecommitdiff
path: root/net/tinyproxy/patches/120-fix_INET6.patch
blob: 6281a422390746128124b2cbfacff34d690f1391 (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
--- a/src/sock.c
+++ b/src/sock.c
@@ -63,7 +63,7 @@ static const char * family_string (int a
  * to indicate an error.
  */
 static int
-bind_socket (int sockfd, const char *addr, int family)
+bind_socket (int sockfd, const char *addr)
 {
         struct addrinfo hints, *res, *ressave;
         int n;
@@ -72,14 +72,14 @@ bind_socket (int sockfd, const char *add
         assert (addr != NULL && strlen (addr) != 0);
 
         memset (&hints, 0, sizeof (struct addrinfo));
-        hints.ai_family = family;
+        hints.ai_family = AF_UNSPEC;
         hints.ai_socktype = SOCK_STREAM;
 
         /* The local port is not important */
         n = getaddrinfo (addr, NULL, &hints, &res);
         if (n != 0) {
                 log_message (LOG_INFO,
-                        "bind_socket: getaddrinfo failed for %s: %s (af: %s)", addr, get_gai_error (n), family_string(family));
+                        "bind_socket: getaddrinfo failed for %s: %s", addr, get_gai_error (n));
                 return -1;
         }
 
@@ -102,14 +102,14 @@ bind_socket (int sockfd, const char *add
  * Try binding the given socket to supplied addresses, stopping when one succeeds.
  */
 static int
-bind_socket_list (int sockfd, sblist *addresses, int family)
+bind_socket_list (int sockfd, sblist *addresses)
 {
         size_t nb_addresses = sblist_getsize(addresses);
         size_t i;
 
         for (i = 0; i < nb_addresses; i++) {
                 const char *address = *(const char **)sblist_get(addresses, i);
-                if (bind_socket(sockfd, address, family) >= 0) {
+                if (bind_socket(sockfd, address) >= 0) {
                         log_message(LOG_INFO, "Bound to %s", address);
                         return 0;
                 }
@@ -170,14 +170,12 @@ int opensock (const char *host, int port
 
                 /* Bind to the specified address */
                 if (bind_to) {
-                        if (bind_socket (sockfd, bind_to,
-                                         res->ai_family) < 0) {
+                        if (bind_socket (sockfd, bind_to) < 0) {
                                 close (sockfd);
                                 continue;       /* can't bind, so try again */
                         }
                 } else if (config->bind_addrs) {
-                        if (bind_socket_list (sockfd, config->bind_addrs,
-                                              res->ai_family) < 0) {
+                        if (bind_socket_list (sockfd, config->bind_addrs) < 0) {
                                 close (sockfd);
                                 continue;       /* can't bind, so try again */
                         }