Back in June, I’ve had a use case for Polipo to bind to an
        explicit address when doing outgoing connections.  I’ve
        ended up implementing the feature with the patch MIMEd.

        Unfortunately, around that time the Git repository [1] (which
        still seem to be described as the primary one at [2]) went down,
        leaving me unable to check if my change’s still needed, and I
        dropped the case.

        Now that I’ve fetched the recent Git history from [3] (where the
        development has seem to be moved since) I see that with
        2e2d55d6b391 (which dates back to November), support for a
        similar ‘proxyOutgoingAddress’ option was added to the code.

        Sadly, this new option would be unsuitable for my needs, as it
        provides no support for IPv6, /and/ it provides no support for
        specifying several possible addresses to bind to.  (Which is a
        natural prerequisite for an ambivalent application, as in
        dual-stack environments, it needs at least /two/ addresses – the
        IPv6 one and the IPv4 one – to try to bind to.)

        I have no spare time right now to try and suggest a patch to
        merge the IPv6 and multiple addresses support to the current
        Polipo, but still provide my patch for any interested party to
        consider.

        TIA.

[1] git://git.wifi.pps.univ-paris-diderot.fr/polipo
[2] http://www.pps.univ-paris-diderot.fr/~jch/software/polipo/
[3] git://github.com/jech/polipo.git

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
--- a/io.c	2014-05-14 21:00:59 +0000
+++ b/io.c	2014-06-12 12:57:16 +0000
@@ -31,6 +31,7 @@
 #ifdef HAVE_IPV6_PREFER_TEMPADDR
 int useTemporarySourceAddress = 1;
 #endif
+AtomListPtr ioClientBindIPs = NULL;
 
 void
 preinitIo()
@@ -40,6 +41,9 @@ preinitIo()
                              configIntSetter,
                              "Prefer IPv6 temporary source address.");
 #endif
+    CONFIG_VARIABLE(ioClientBindIPs, CONFIG_ATOM_LIST_LOWER,
+                    ("The IP addresses to use"
+                     " for outgoing connections."));
 
 #ifdef HAVE_WINSOCK
     /* Load the winsock dll */
@@ -486,6 +490,41 @@ do_connect(AtomPtr addr, int index, int port,
         return NULL;
     }
 
+    if (ioClientBindIPs != 0) {
+        const AtomListPtr l = ioClientBindIPs;
+        int i;
+#ifdef HAVE_IPv6
+        if (af == 6) {
+            struct sockaddr_in6 ba = { 0 };
+            ba.sin6_family = AF_INET6;
+            for (i = 0; i < l->length; i++) {
+                if (inet_pton  (AF_INET6, l->list[i]->string,
+                                &(ba.sin6_addr)) == 0) {
+                    continue;
+                } else if (bind (fd, &ba, sizeof (ba)) >= 0) {
+                    break;
+                }
+                do_log_error (L_ERROR, errno, "Couldn't bind");
+            }
+        } else
+#endif
+        {
+            for (i = 0; i < l->length; i++) {
+                struct sockaddr_in ba  = { 0 };
+                ba.sin_family = AF_INET;
+                if (inet_pton  (AF_INET,  l->list[i]->string,
+                                &(ba.sin_addr)) == 0) {
+                    continue;
+                } else if (bind (fd, &ba, sizeof (ba)) >= 0) {
+                    break;
+                }
+                do_log_error (L_ERROR, errno, "Couldn't bind");
+            }
+        }
+        /* FIXME: check if i == l->length and issue a warning if
+           necessary */
+    }
+
     /* POLLIN is apparently needed on Windows */
     event = registerFdEvent(fd, POLLIN | POLLOUT,
                             do_scheduled_connect,
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Polipo-users mailing list
Polipo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to