aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Hoersken <info@marc-hoersken.de>2016-08-20 21:14:46 +0200
committerMarc Hoersken <info@marc-hoersken.de>2016-08-20 21:15:00 +0200
commitd6bf400e9f9480509c7356b814842477563a87e4 (patch)
tree33d0dac5f9382292d148f87ff32267393dcac4f4
parent213c27e487a4953a4b8006a8c520012b25ee22ae (diff)
socks.c: use Curl_printable_address in SOCKS5 connection sequence
Replace custom string formatting with Curl_printable_address. Add additional debug and error output in case of failures.
-rw-r--r--lib/socks.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/lib/socks.c b/lib/socks.c
index 7c9632671..01607bbaf 100644
--- a/lib/socks.c
+++ b/lib/socks.c
@@ -431,6 +431,8 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
(void)curlx_nonblock(sock, FALSE);
+ infof(data, "SOCKS5 communication to %s:%d\n", hostname, remote_port);
+
code = Curl_write_plain(conn, sock, (char *)socksreq, (2 + (int)socksreq[1]),
&written);
if(code || (written != (2 + (int)socksreq[1]))) {
@@ -596,33 +598,40 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
if(dns)
hp=dns->addr;
if(hp) {
- struct sockaddr_in *saddr_in;
-#ifdef ENABLE_IPV6
- struct sockaddr_in6 *saddr_in6;
-#endif
int i;
+ char buf[64];
+ Curl_printable_address(hp, buf, sizeof(buf));
if(hp->ai_family == AF_INET) {
+ struct sockaddr_in *saddr_in;
socksreq[len++] = 1; /* ATYP: IPv4 = 1 */
saddr_in = (struct sockaddr_in*)(void*)hp->ai_addr;
for(i = 0; i < 4; i++) {
socksreq[len++] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[i];
}
+
+ infof(data, "SOCKS5 connect to IPv4 %s (locally resolved)\n", buf);
}
#ifdef ENABLE_IPV6
else if(hp->ai_family == AF_INET6) {
+ struct sockaddr_in6 *saddr_in6;
socksreq[len++] = 4; /* ATYP: IPv6 = 4 */
saddr_in6 = (struct sockaddr_in6*)(void*)hp->ai_addr;
for(i = 0; i < 16; i++) {
socksreq[len++] = ((unsigned char*)&saddr_in6->sin6_addr.s6_addr)[i];
}
+
+ infof(data, "SOCKS5 connect to IPv6 %s (locally resolved)\n", buf);
}
#endif
- else
+ else {
hp = NULL; /* fail! */
+ failf(data, "SOCKS5 connection to %s not supported\n", buf);
+ }
+
Curl_resolv_unlock(data, dns); /* not used anymore from now on */
}
if(!hp) {
@@ -630,25 +639,6 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
hostname);
return CURLE_COULDNT_RESOLVE_HOST;
}
- else {
- if(socksreq[3] == 1) {
- infof(data, "SOCKS5 connect to %d.%d.%d.%d (locally resolved)\n",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7]);
- }
- else if(socksreq[3] == 4) {
- infof(data, "SOCKS5 connect to %02x%02x:%02x%02x:%02x%02x:%02x%02x:"
- "%02x%02x:%02x%02x:%02x%02x:%02x%02x (locally resolved)\n",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7],
- (unsigned char)socksreq[8], (unsigned char)socksreq[9],
- (unsigned char)socksreq[10], (unsigned char)socksreq[11],
- (unsigned char)socksreq[12], (unsigned char)socksreq[13],
- (unsigned char)socksreq[14], (unsigned char)socksreq[15],
- (unsigned char)socksreq[16], (unsigned char)socksreq[17],
- (unsigned char)socksreq[18], (unsigned char)socksreq[19]);
- }
- }
}
socksreq[len++] = (unsigned char)((remote_port >> 8) & 0xff); /* PORT MSB */
@@ -769,6 +759,9 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
}
return CURLE_COULDNT_CONNECT;
}
+ else {
+ infof(data, "SOCKS5 request granted.\n");
+ }
(void)curlx_nonblock(sock, TRUE);
return CURLE_OK; /* Proxy was successful! */