diff options
author | Marc Hoersken <info@marc-hoersken.de> | 2016-08-20 21:12:34 +0200 |
---|---|---|
committer | Marc Hoersken <info@marc-hoersken.de> | 2016-08-20 21:15:00 +0200 |
commit | 213c27e487a4953a4b8006a8c520012b25ee22ae (patch) | |
tree | 5e394535f2423bb23553060e47a21ab32ef03408 /lib | |
parent | c6b869ec79fb1a6a4882cef9f2697ee14fb78026 (diff) |
socks.c: align SOCKS4 connection sequence with SOCKS5
Calling sscanf is not required since the raw IPv4 address is
available and the protocol can be detected using ai_family.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/socks.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/socks.c b/lib/socks.c index bee43ac2b..7c9632671 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -170,24 +170,26 @@ CURLcode Curl_SOCKS4(const char *proxy_name, hp=dns->addr; if(hp) { char buf[64]; - unsigned short ip[4]; Curl_printable_address(hp, buf, sizeof(buf)); - if(4 == sscanf(buf, "%hu.%hu.%hu.%hu", - &ip[0], &ip[1], &ip[2], &ip[3])) { - /* Set DSTIP */ - socksreq[4] = (unsigned char)ip[0]; - socksreq[5] = (unsigned char)ip[1]; - socksreq[6] = (unsigned char)ip[2]; - socksreq[7] = (unsigned char)ip[3]; + if(hp->ai_family == AF_INET) { + struct sockaddr_in *saddr_in; + + saddr_in = (struct sockaddr_in*)(void*)hp->ai_addr; + socksreq[4] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[0]; + socksreq[5] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[1]; + socksreq[6] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[2]; + socksreq[7] = ((unsigned char*)&saddr_in->sin_addr.s_addr)[3]; + + infof(data, "SOCKS4 connect to IPv4 %s (locally resolved)\n", buf); } - else + else { hp = NULL; /* fail! */ - infof(data, "SOCKS4 connect to %s (locally resolved)\n", buf); + failf(data, "SOCKS4 connection to %s not supported\n", buf); + } Curl_resolv_unlock(data, dns); /* not used anymore from now on */ - } if(!hp) { failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.", |