Stop proxying connections to localhost by default; should fix
[u/mdw/putty] / proxy.c
diff --git a/proxy.c b/proxy.c
index c1aab15..7c608c9 100644 (file)
--- a/proxy.c
+++ b/proxy.c
@@ -247,6 +247,14 @@ static int proxy_for_destination (SockAddr addr, char * hostname, int port)
     int hostip_len, hostname_len;
     char * exclude_list;
 
+    /*
+     * Check the host name and IP against the hard-coded
+     * representations of `localhost'.
+     */
+    if (!cfg.even_proxy_localhost &&
+       (sk_hostname_is_local(hostname) || sk_address_is_local(addr)))
+       return 0;                      /* do not proxy */
+
     /* we want a string representation of the IP address for comparisons */
     sk_getaddr(addr, hostip, 64);
 
@@ -404,13 +412,13 @@ Socket new_connection(SockAddr addr, char *hostname,
     return sk_new(addr, port, privport, oobinline, nodelay, plug);
 }
 
-Socket new_listener(int port, Plug plug, int local_host_only)
+Socket new_listener(char *srcaddr, int port, Plug plug, int local_host_only)
 {
     /* TODO: SOCKS (and potentially others) support inbound
      * TODO: connections via the proxy. support them.
      */
 
-    return sk_newlistener(port, plug, local_host_only);
+    return sk_newlistener(srcaddr, port, plug, local_host_only);
 }
 
 /* ----------------------------------------------------------------------
@@ -481,7 +489,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
            sk_write(p->sub_socket, buf2, strlen(buf2));
        }
 
-       sk_write(p->sub_socket, "\r\n", strlen(buf));
+       sk_write(p->sub_socket, "\r\n", 2);
 
        p->state = 1;
        return 0;
@@ -594,6 +602,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
            {
                bufchain_consume(&p->pending_input_data, eol);
                datap += eol;
+               len   -= eol;
                eol = get_line_end(datap, len);
            }
 
@@ -929,7 +938,7 @@ int proxy_socks5_negotiate (Proxy_Socket p, int change)
            char command[22];
            int len;
 
-           if (sk_addrtype(p->remote_addr) == ADDRTYPE_IPV6) {
+           if (sk_addrtype(p->remote_addr) == ADDRTYPE_IPV4) {
                len = 10;
                command[3] = 1; /* IPv4 */
            } else {