c-ares specifying network interface for the DNS resolves(c-ares 为 DNS 解析指定网络接口)
问题描述
有没有办法设置DNS请求可以绑定到的网络接口.
Is there a way in which you can set the network interface to which the DNS requests can be bound to.
我们有一个项目需要使用高优先级流会话通过一个接口,所有其他请求通过第二个接口.
We have a project which requires to use a highpriority streaming session go through one interface and all the other requests channeled through the second one.
示例:设置 'eth0' 以便所有 ares 请求都通过 'eth0' 而不是在 'wlan0' 上.
example: setting 'eth0' so that all the ares requests will go through 'eth0' and not on 'wlan0'.
我在 c-ares(在 ares_init_options() API 中)找不到任何提供此设置界面选项的 API.
I was not able to find any API in c-ares (in ares_init_options() API) that gives this option of setting interface.
如果有什么方法可以做到这一点,或者我错过了什么,请告诉我.
Can you please let me know if there is some way to achive this or if I missed something.
谢谢,阿俊
推荐答案
如果你有一个相当新的 c-ares (c-ares >= 1.7.4),请查看 ares.h(这是我唯一的地方实际上发现它被引用了).
If you have a fairly new c-ares (c-ares >= 1.7.4), check out ares.h (It's the only place I've actually found it referenced).
/* These next 3 configure local binding for the out-going socket
* connection. Use these to specify source IP and/or network device
* on multi-homed systems.
*/
CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip);
/* local_ip6 should be 16 bytes in length */
CARES_EXTERN void ares_set_local_ip6(ares_channel channel,
const unsigned char* local_ip6);
/* local_dev_name should be null terminated. */
CARES_EXTERN void ares_set_local_dev(ares_channel channel,
const char* local_dev_name);
这篇关于c-ares 为 DNS 解析指定网络接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c-ares 为 DNS 解析指定网络接口


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01