cURL / Mailing Lists / curl-library / Single Mail

curl-library

dns via socks5 failed?

From: <jinglexy_mail-stock_at_yahoo.com.cn>
Date: Mon, 17 Dec 2007 19:17:36 +0800 (CST)

here is my simple demo, the http proxy works well,
  but socks5 can't.
   
  
static size_t receiver(void* ptr,
         size_t size,
         size_t nmemb,
         char* buffer)
{
 int buflen = (int)strlen(buffer);
 int len = (int)size * (int)nmemb;
 if (buflen + len > 4096)
  return 0;
 memcpy(buffer + buflen, (char*)ptr, len);
 buffer[buflen + len] = 0;
 return len;
}
  void test1()
{
 CURL *curl;
 CURLcode result;
   if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) {
  XTRACE("curl_global_init() failed\n");
  return;
 }
 int i = 0;
   curl = curl_easy_init();
 if (curl) {
  char buffer[4096] = "";
  char errorbuffer[CURL_ERROR_SIZE+1] = "";
  result = curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
  result = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuffer);
  #if 0
  result = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  result = curl_easy_setopt(curl, CURLOPT_PROXY, "172.16.0.1:808");
#else
  result = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  result = curl_easy_setopt(curl, CURLOPT_PROXY, "172.16.0.1");
  result = curl_easy_setopt(curl, CURLOPT_PROXYPORT, 1080);
#endif
  result = curl_easy_setopt(curl, CURLOPT_HTTPGET, TRUE);
  result = curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, TRUE);
  result = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "username1:passwrod1");
    result = curl_easy_setopt(curl, CURLOPT_USERAGENT,
   "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
  result = curl_easy_setopt(curl, CURLOPT_URL, "http://jidu2007.baidu.com");
  result = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ::receiver);
  result = curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
    result = curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
  result = curl_easy_perform(curl);
  if(CURLE_OK == result) {
   printf("succ:\n%s\n", buffer);
   return;
  }
  printf("error:\n%s\n", errorbuffer);
 }
}

   
   
  the progrom output:
  ******************************************************************************
  * About to connect() to proxy 172.16.0.1 port 1080
* Trying 172.16.0.1... * connected
* Could not resolve host: jidu2007.baidu.com; No data record of requested type
* Failed to resolve "jidu2007.baidu.com" for SOCKS5 connect.
* Connected to jidu2007.baidu.com (172.16.0.1) port 1080
> GET / HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: jidu2007.baidu.com
Accept: */*
  * Empty reply from server
* Connection #0 to host jidu2007.baidu.com left intact
error:
Could not resolve host: jidu2007.baidu.com; No data record of requested type
   
   
  see the last line:
  it's seem to get hostname via local dns?
  do libcurl support dns via proxy?
   

       
---------------------------------
天生购物狂,狂抢购物券,你还等什么!
Received on 2007-12-17