socks.c: Added support for IPv6 connections through SOCKSv5 proxy
This commit is contained in:
@@ -163,7 +163,6 @@ may have been fixed since this was written!
|
|||||||
to what winhttp does. See http://curl.haxx.se/bug/view.cgi?id=1281867
|
to what winhttp does. See http://curl.haxx.se/bug/view.cgi?id=1281867
|
||||||
|
|
||||||
23. SOCKS-related problems:
|
23. SOCKS-related problems:
|
||||||
A) libcurl doesn't support SOCKS for IPv6.
|
|
||||||
B) libcurl doesn't support FTPS over a SOCKS proxy.
|
B) libcurl doesn't support FTPS over a SOCKS proxy.
|
||||||
E) libcurl doesn't support active FTP over a SOCKS proxy
|
E) libcurl doesn't support active FTP over a SOCKS proxy
|
||||||
|
|
||||||
|
|||||||
65
lib/socks.c
65
lib/socks.c
@@ -371,6 +371,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
|
|||||||
bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
|
bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
|
||||||
const size_t hostname_len = strlen(hostname);
|
const size_t hostname_len = strlen(hostname);
|
||||||
ssize_t packetsize = 0;
|
ssize_t packetsize = 0;
|
||||||
|
int len;
|
||||||
|
|
||||||
/* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
|
/* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
|
||||||
if(!socks5_resolve_local && hostname_len > 255) {
|
if(!socks5_resolve_local && hostname_len > 255) {
|
||||||
@@ -474,7 +475,6 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
|
|||||||
else if(socksreq[1] == 2) {
|
else if(socksreq[1] == 2) {
|
||||||
/* Needs user name and password */
|
/* Needs user name and password */
|
||||||
size_t userlen, pwlen;
|
size_t userlen, pwlen;
|
||||||
int len;
|
|
||||||
if(proxy_name && proxy_password) {
|
if(proxy_name && proxy_password) {
|
||||||
userlen = strlen(proxy_name);
|
userlen = strlen(proxy_name);
|
||||||
pwlen = strlen(proxy_password);
|
pwlen = strlen(proxy_password);
|
||||||
@@ -554,31 +554,22 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Authentication is complete, now specify destination to the proxy */
|
/* Authentication is complete, now specify destination to the proxy */
|
||||||
socksreq[0] = 5; /* version (SOCKS5) */
|
len = 0;
|
||||||
socksreq[1] = 1; /* connect */
|
socksreq[len++] = 5; /* version (SOCKS5) */
|
||||||
socksreq[2] = 0; /* must be zero */
|
socksreq[len++] = 1; /* connect */
|
||||||
|
socksreq[len++] = 0; /* must be zero */
|
||||||
|
|
||||||
if(!socks5_resolve_local) {
|
if(!socks5_resolve_local) {
|
||||||
packetsize = (ssize_t)(5 + hostname_len + 2);
|
socksreq[len++] = 3; /* ATYP: domain name = 3 */
|
||||||
|
socksreq[len++] = (char) hostname_len; /* address length */
|
||||||
socksreq[3] = 3; /* ATYP: domain name = 3 */
|
memcpy(&socksreq[len], hostname, hostname_len); /* address bytes w/o NULL */
|
||||||
socksreq[4] = (char) hostname_len; /* address length */
|
len += hostname_len;
|
||||||
memcpy(&socksreq[5], hostname, hostname_len); /* address bytes w/o NULL */
|
|
||||||
|
|
||||||
/* PORT MSB */
|
|
||||||
socksreq[hostname_len+5] = (unsigned char)((remote_port >> 8) & 0xff);
|
|
||||||
/* PORT LSB */
|
|
||||||
socksreq[hostname_len+6] = (unsigned char)(remote_port & 0xff);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct Curl_dns_entry *dns;
|
struct Curl_dns_entry *dns;
|
||||||
Curl_addrinfo *hp=NULL;
|
Curl_addrinfo *hp = NULL;
|
||||||
int rc = Curl_resolv(conn, hostname, remote_port, &dns);
|
int rc = Curl_resolv(conn, hostname, remote_port, &dns);
|
||||||
|
|
||||||
packetsize = 10;
|
|
||||||
|
|
||||||
socksreq[3] = 1; /* IPv4 = 1 */
|
|
||||||
|
|
||||||
if(rc == CURLRESOLV_ERROR)
|
if(rc == CURLRESOLV_ERROR)
|
||||||
return CURLE_COULDNT_RESOLVE_HOST;
|
return CURLE_COULDNT_RESOLVE_HOST;
|
||||||
|
|
||||||
@@ -596,16 +587,26 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
|
|||||||
if(dns)
|
if(dns)
|
||||||
hp=dns->addr;
|
hp=dns->addr;
|
||||||
if(hp) {
|
if(hp) {
|
||||||
char buf[64];
|
struct sockaddr_in *saddr_in;
|
||||||
unsigned short ip[4];
|
struct sockaddr_in6 *saddr_in6;
|
||||||
Curl_printable_address(hp, buf, sizeof(buf));
|
int i;
|
||||||
|
|
||||||
if(4 == sscanf( buf, "%hu.%hu.%hu.%hu",
|
if(hp->ai_family == AF_INET) {
|
||||||
&ip[0], &ip[1], &ip[2], &ip[3])) {
|
socksreq[len++] = 1; /* IPv4 = 1 */
|
||||||
socksreq[4] = (unsigned char)ip[0];
|
|
||||||
socksreq[5] = (unsigned char)ip[1];
|
saddr_in = (struct sockaddr_in*)hp->ai_addr;
|
||||||
socksreq[6] = (unsigned char)ip[2];
|
for(i = 0; i < 4; i++) {
|
||||||
socksreq[7] = (unsigned char)ip[3];
|
socksreq[len++] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[i];
|
||||||
|
infof(data, "%d\n", socksreq[len-1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(hp->ai_family == AF_INET6) {
|
||||||
|
socksreq[len++] = 4; /* IPv6 = 4 */
|
||||||
|
|
||||||
|
saddr_in6 = (struct sockaddr_in6*)hp->ai_addr;
|
||||||
|
for(i = 0; i < 16; i++) {
|
||||||
|
socksreq[len++] = ((unsigned char*)&saddr_in6->sin6_addr.s6_addr)[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hp = NULL; /* fail! */
|
hp = NULL; /* fail! */
|
||||||
@@ -617,11 +618,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
|
|||||||
hostname);
|
hostname);
|
||||||
return CURLE_COULDNT_RESOLVE_HOST;
|
return CURLE_COULDNT_RESOLVE_HOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
socksreq[8] = (unsigned char)((remote_port >> 8) & 0xff); /* PORT MSB */
|
|
||||||
socksreq[9] = (unsigned char)(remote_port & 0xff); /* PORT LSB */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socksreq[len++] = (unsigned char)((remote_port >> 8) & 0xff); /* PORT MSB */
|
||||||
|
socksreq[len++] = (unsigned char)(remote_port & 0xff); /* PORT LSB */
|
||||||
|
|
||||||
|
packetsize = len;
|
||||||
|
|
||||||
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
|
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
|
||||||
if(conn->socks5_gssapi_enctype) {
|
if(conn->socks5_gssapi_enctype) {
|
||||||
failf(data, "SOCKS5 gssapi protection not yet implemented.");
|
failf(data, "SOCKS5 gssapi protection not yet implemented.");
|
||||||
|
|||||||
Reference in New Issue
Block a user