cURL / Mailing Lists / curl-library / Single Mail

curl-library

SOCKS4 proxy and multi interface

From: Dmitri Shubin <sbn_at_tbricks.com>
Date: Wed, 20 Apr 2011 20:44:59 +0400

Hello all!

I have a problem downloading file with FTP protocol using SOCKS4 proxy.
It perfectly works with easy interface but fails when using multi one.

Verbose output is as follows:

$ ./multi-single
* About to connect() to proxy localhost port 2121 (#0)
* Trying 127.0.0.1... * connected
* SOCKS4 request granted.
* Connected to localhost (127.0.0.1) port 2121 (#0)
* SOCKS4 reply has wrong version, version should be 4.
* Closing connection #0

strace shows that it tries to connect to proxy twice:

socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
...
connect(3, {sa_family=AF_INET, sin_port=htons(2121),
sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in
progress)
...
sendto(3, "\4\1\0\25\177\0\0\1\0", 9, MSG_NOSIGNAL, NULL, 0) = 9
<------------- ask proxy to connect
...
recvfrom(3, "\0Z\0\0\0\0\0\0", 8, 0, NULL, NULL) = 8
<------------------- proxy ACK's
...
sendto(3, "\4\1\0\25\177\0\0\1\0", 9, MSG_NOSIGNAL, NULL, 0) = 9
<--------- ask proxy again !!!!!
...
recvfrom(3, "220 (vsF", 8, 0, NULL, NULL) = 8 <------- hello from FTP
but ACK from proxy is expected

I use SSH (OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008) to
create SOCKS4 proxy:
$ ssh -N -D localhost:2121 localhost

To test I used modified version of multi-single.c example
(docs/examples/multi-single.c) from curl-7.21.5 distribution:
Here is diff:

diff -Nru curl-7.21.5/docs/examples/multi-single.c
curl-7.21.5.new/docs/examples/multi-single.c
--- curl-7.21.5/docs/examples/multi-single.c 2011-03-19
18:17:12.000000000 +0300
+++ curl-7.21.5.new/docs/examples/multi-single.c 2011-04-20
20:19:20.000000000 +0400
@@ -44,7 +44,11 @@
   http_handle = curl_easy_init();

   /* set the options (I left out a few, you'll get the point anyway) */
- curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/");
+ /*curl_easy_setopt(http_handle, CURLOPT_URL,
"http://www.example.com/");*/
+ curl_easy_setopt(http_handle, CURLOPT_URL, "ftp://localhost/dd.txt");
+ curl_easy_setopt(http_handle, CURLOPT_PROXY, "localhost:2121");
+ curl_easy_setopt(http_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ curl_easy_setopt(http_handle, CURLOPT_VERBOSE, (long)1);

   /* init a multi stack */
   multi_handle = curl_multi_init();

Thanks!
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-20