summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/asyn-ares.c61
-rw-r--r--lib/asyn-thread.c24
-rw-r--r--lib/hostip.h21
-rw-r--r--lib/hostsyn.c36
-rw-r--r--lib/url.c9
5 files changed, 151 insertions, 0 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c
index 081667dc3..fa12f21de 100644
--- a/lib/asyn-ares.c
+++ b/lib/asyn-ares.c
@@ -623,4 +623,65 @@ CURLcode Curl_set_dns_servers(struct SessionHandle *data,
#endif
return result;
}
+
+CURLcode Curl_set_dns_interface(struct SessionHandle *data,
+ const char *interface)
+{
+#if (ARES_VERSION >= 0x010704)
+ if(!interface) interface = "";
+ ares_set_local_dev((ares_channel)data->state.resolver, interface);
+ return CURLE_OK;
+#else /* c-ares version too old! */
+ (void)data;
+ (void)interface;
+ return CURLE_NOT_BUILT_IN;
+#endif
+}
+
+CURLcode Curl_set_dns_local_ip4(struct SessionHandle *data,
+ const char *local_ip4)
+{
+#if (ARES_VERSION >= 0x010704)
+ uint32_t a4;
+
+ if((!local_ip4) || (local_ip4[0] == 0)) {
+ a4 = 0; /* disabled: do not bind to a specific address */
+ }
+ else {
+ if(Curl_inet_pton(AF_INET, local_ip4, &a4) != 1) {
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
+ }
+ ares_set_local_ip4((ares_channel)data->state.resolver, ntohl(a4));
+ return CURLE_OK;
+#else /* c-ares version too old! */
+ (void)data;
+ (void)local_ip4;
+ return CURLE_NOT_BUILT_IN;
+#endif
+}
+
+CURLcode Curl_set_dns_local_ip6(struct SessionHandle *data,
+ const char *local_ip6)
+{
+#if (ARES_VERSION >= 0x010704)
+ unsigned char a6[INET6_ADDRSTRLEN];
+
+ if((!local_ip6) || (local_ip6[0] == 0)) {
+ /* disabled: do not bind to a specific address */
+ memset(a6, 0, sizeof(a6));
+ }
+ else {
+ if(Curl_inet_pton(AF_INET6, local_ip6, a6) != 1) {
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
+ }
+ ares_set_local_ip6((ares_channel)data->state.resolver, a6);
+ return CURLE_OK;
+#else /* c-ares version too old! */
+ (void)data;
+ (void)local_ip6;
+ return CURLE_NOT_BUILT_IN;
+#endif
+}
#endif /* CURLRES_ARES */
diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c
index 81d1d5d5d..206dcdb1f 100644
--- a/lib/asyn-thread.c
+++ b/lib/asyn-thread.c
@@ -635,4 +635,28 @@ CURLcode Curl_set_dns_servers(struct SessionHandle *data,
}
+CURLcode Curl_set_dns_interface(struct SessionHandle *data,
+ const char *interface)
+{
+ (void)data;
+ (void)interface;
+ return CURLE_NOT_BUILT_IN;
+}
+
+CURLcode Curl_set_dns_local_ip4(struct SessionHandle *data,
+ const char *local_ip4)
+{
+ (void)data;
+ (void)local_ip4;
+ return CURLE_NOT_BUILT_IN;
+}
+
+CURLcode Curl_set_dns_local_ip6(struct SessionHandle *data,
+ const char *local_ip6)
+{
+ (void)data;
+ (void)local_ip6;
+ return CURLE_NOT_BUILT_IN;
+}
+
#endif /* CURLRES_THREADED */
diff --git a/lib/hostip.h b/lib/hostip.h
index a38f732a4..997800a88 100644
--- a/lib/hostip.h
+++ b/lib/hostip.h
@@ -201,6 +201,27 @@ extern sigjmp_buf curl_jmpenv;
CURLcode Curl_set_dns_servers(struct SessionHandle *data, char *servers);
/*
+ * Function provided by the resolver backend to set
+ * outgoing interface to use for DNS requests
+ */
+CURLcode Curl_set_dns_interface(struct SessionHandle *data,
+ const char *interface);
+
+/*
+ * Function provided by the resolver backend to set
+ * local IPv4 address to use as source address for DNS requests
+ */
+CURLcode Curl_set_dns_local_ip4(struct SessionHandle *data,
+ const char *local_ip4);
+
+/*
+ * Function provided by the resolver backend to set
+ * local IPv6 address to use as source address for DNS requests
+ */
+CURLcode Curl_set_dns_local_ip6(struct SessionHandle *data,
+ const char *local_ip6);
+
+/*
* Clean off entries from the cache
*/
void Curl_hostcache_clean(struct SessionHandle *data, struct curl_hash *hash);
diff --git a/lib/hostsyn.c b/lib/hostsyn.c
index 65a403545..24f8dd82c 100644
--- a/lib/hostsyn.c
+++ b/lib/hostsyn.c
@@ -72,4 +72,40 @@ CURLcode Curl_set_dns_servers(struct SessionHandle *data,
}
+/*
+ * Function provided by the resolver backend to set
+ * outgoing interface to use for DNS requests
+ */
+CURLcode Curl_set_dns_interface(struct SessionHandle *data,
+ const char *interface)
+{
+ (void)data;
+ (void)interface;
+ return CURLE_NOT_BUILT_IN;
+}
+
+/*
+ * Function provided by the resolver backend to set
+ * local IPv4 address to use as source address for DNS requests
+ */
+CURLcode Curl_set_dns_local_ip4(struct SessionHandle *data,
+ const char *local_ip4)
+{
+ (void)data;
+ (void)local_ip4;
+ return CURLE_NOT_BUILT_IN;
+}
+
+/*
+ * Function provided by the resolver backend to set
+ * local IPv6 address to use as source address for DNS requests
+ */
+CURLcode Curl_set_dns_local_ip6(struct SessionHandle *data,
+ const char *local_ip6)
+{
+ (void)data;
+ (void)local_ip6;
+ return CURLE_NOT_BUILT_IN;
+}
+
#endif /* truly sync */
diff --git a/lib/url.c b/lib/url.c
index 50ce80df4..c1672d08b 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2455,6 +2455,15 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
case CURLOPT_DNS_SERVERS:
result = Curl_set_dns_servers(data, va_arg(param, char *));
break;
+ case CURLOPT_DNS_INTERFACE:
+ result = Curl_set_dns_interface(data, va_arg(param, char *));
+ break;
+ case CURLOPT_DNS_LOCAL_IP4:
+ result = Curl_set_dns_local_ip4(data, va_arg(param, char *));
+ break;
+ case CURLOPT_DNS_LOCAL_IP6:
+ result = Curl_set_dns_local_ip6(data, va_arg(param, char *));
+ break;
case CURLOPT_TCP_KEEPALIVE:
data->set.tcp_keepalive = (0 != va_arg(param, long))?TRUE:FALSE;