【问题标题】:c-ares specifying network interface for the DNS resolvesc-ares 为 DNS 解析指定网络接口
【发布时间】:2011-09-30 14:03:37
【问题描述】:

有没有一种方法可以设置 DNS 请求可以绑定到的网络接口。

我们有一个项目需要使用高优先级流会话通过一个接口,而所有其他请求都通过第二个接口。

示例:设置“eth0”,以便所有 ares 请求都通过“eth0”而不是“wlan0”。

我无法在 c-ares(在 ares_init_options() API 中)找到任何提供此设置界面选项的 API。

如果有什么方法可以实现这一点,或者我错过了什么,请告诉我。

谢谢, 阿琼

【问题讨论】:

  • 不幸的是,要让 c-ares 做到这一点并不容易。删除了我的答案

标签: c++ c network-programming dns c-ares


【解决方案1】:

如果您有一个相当新的 c-ares (c-ares >= 1.7.4),请查看 ares.h(这是我实际发现它引用的唯一地方)。

/* 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-19
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多