summaryrefslogtreecommitdiff
path: root/ares_init.c
diff options
context:
space:
mode:
authorBen Greear <greearb@candelatech.com>2010-07-18 23:58:39 +0200
committerDaniel Stenberg <daniel@haxx.se>2010-07-18 23:58:39 +0200
commite3b04e5a4796215d2483aba3cb75c72ba337ac14 (patch)
tree3671ebcef566e0e32f00a50b0557b88bd8b67475 /ares_init.c
parent45a09b7efba9665bdc08e227f4baf51fab3862ae (diff)
downloadc-ares-e3b04e5a4796215d2483aba3cb75c72ba337ac14.tar.gz
c-ares-e3b04e5a4796215d2483aba3cb75c72ba337ac14.tar.bz2
c-ares-e3b04e5a4796215d2483aba3cb75c72ba337ac14.zip
local-bind: Support binding to local interface/IPs
Add 3 new functions to set the local binding for the out-going socket connection, and add ares_set_servers_csv() to set a list of servers at once as a comma-separated string. Signed-off-by: Ben Greear <greearb@candelatech.com>
Diffstat (limited to 'ares_init.c')
-rw-r--r--ares_init.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/ares_init.c b/ares_init.c
index a812b2d..718d552 100644
--- a/ares_init.c
+++ b/ares_init.c
@@ -172,6 +172,10 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
channel->last_server = 0;
channel->last_timeout_processed = (time_t)now.tv_sec;
+ memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name));
+ channel->local_ip4 = 0;
+ memset(&channel->local_ip6, 0, sizeof(channel->local_ip6));
+
/* Initialize our lists of queries */
ares__init_list_head(&(channel->all_queries));
for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
@@ -286,6 +290,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
(*dest)->sock_create_cb = src->sock_create_cb;
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
+ strncpy((*dest)->local_dev_name, src->local_dev_name, sizeof(src->local_dev_name));
+ (*dest)->local_ip4 = src->local_ip4;
+ memcpy((*dest)->local_ip6, src->local_ip6, sizeof(src->local_ip6));
+
/* Full name server cloning required when not all are IPv4 */
for (i = 0; i < src->nservers; i++)
{
@@ -1604,6 +1612,28 @@ unsigned short ares__generate_new_id(rc4_key* key)
return r;
}
+void ares_set_local_ip4(ares_channel channel, uint32_t local_ip)
+{
+ channel->local_ip4 = local_ip;
+}
+
+/* local_ip6 should be 16 bytes in length */
+void ares_set_local_ip6(ares_channel channel,
+ const unsigned char* local_ip6)
+{
+ memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
+}
+
+/* local_dev_name should be null terminated. */
+void ares_set_local_dev(ares_channel channel,
+ const char* local_dev_name)
+{
+ strncpy(channel->local_dev_name, local_dev_name,
+ sizeof(channel->local_dev_name));
+ channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0;
+}
+
+
void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback cb,
void *data)