cURL / Mailing Lists / curl-library / Single Mail

curl-library

[dns-local-bind 28/28] dns: Support binding DNS to local interface/IP

From: Ben Greear <greearb_at_candelatech.com>
Date: Tue, 25 May 2010 12:44:18 -0700

Add options to pass proper config off to c-ares
for local interface and/or IP binding.

Add option to configure DNS servers that c-ares
will use.

Signed-off-by: Ben Greear <greearb_at_candelatech.com>

---
:100644 100644 83ba078... 9dd396e... M	include/curl/curl.h
:100644 100644 4fe2173... d01fd71... M	lib/url.c
 include/curl/curl.h |   21 +++++++++++++++++++++
 lib/url.c           |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/include/curl/curl.h b/include/curl/curl.h
index 83ba078..9dd396e 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1435,6 +1435,27 @@ typedef enum {
   /* FNMATCH_FUNCTION user pointer */
   CINIT(FNMATCH_DATA, OBJECTPOINT, 202),
 
+  /* Set the interface string for c-ares (DNS)
+   * to use as outgoing network interface */
+  CINIT(DNS_INTERFACE, OBJECTPOINT, 203),
+
+  /* Set the local IPv4 address for c-ares (DNS)
+   * to use for outgoing connections.
+   * Host-byte-order.
+   */
+  CINIT(DNS_LOCAL_IP4, LONG, 204),
+
+  /* Set the local IPv6 address for c-ares (DNS)
+   * to use for outgoing connections.
+   * 16-byte unsigned char*
+   */
+  CINIT(DNS_LOCAL_IP6, OBJECTPOINT, 205),
+
+  /* Set the DNS servers for c-ares to use.
+   * comma separated list of host[:port] entries.
+   */
+  CINIT(DNS_SERVERS, OBJECTPOINT, 206),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/lib/url.c b/lib/url.c
index 4fe2173..d01fd71 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -884,6 +884,45 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     data->set.global_dns_cache = (bool)(0 != use_cache);
   }
   break;
+  
+#ifdef USE_ARES
+  case CURLOPT_DNS_INTERFACE:
+    /*
+     * Set what interface or address/hostname to bind the socket to when
+     * performing DNS operations.
+     */
+    ares_set_local_dev(data->state.areschannel, va_arg(param, char *));
+    break;
+  case CURLOPT_DNS_LOCAL_IP4:
+    /*
+     * Set the IPv4 source address for DNS operations.
+     */
+    ares_set_local_ip4(data->state.areschannel, va_arg(param, uint32_t));
+    break;
+  case CURLOPT_DNS_LOCAL_IP6:
+    /*
+     * Set the IPv6 source address for DNS operations.
+     */
+    ares_set_local_ip6(data->state.areschannel, va_arg(param, unsigned char*));
+    break;
+  case CURLOPT_DNS_SERVERS:
+    /*
+     * Set the DNS servers for c-ares.
+     */
+    /* Incomming string format: host[:port][,host[:port]]... */
+    ares_set_servers_csv(data->state.areschannel, va_arg(param, const char*));
+    break;
+#else
+  case CURLOPT_DNS_INTERFACE:
+  case CURLOPT_DNS_LOCAL_IP4:
+  case CURLOPT_DNS_LOCAL_IP6:
+  case CURLOPT_DNS_SERVERS:
+    /* TODO:  Enable other DNS backends?? */
+    /* TODO:  Should we return an error here, or just silently do nothing? */
+    result = CURLE_FAILED_INIT;
+    break;    
+#endif
+    
   case CURLOPT_SSL_CIPHER_LIST:
     /* set a list of cipher we want to use in the SSL connection */
     result = setstropt(&data->set.str[STRING_SSL_CIPHER_LIST],
-- 
1.6.2.5
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-25