Subject: Using ares_gethostbyname() instead of gethostbyname() to use specific local interface

Using ares_gethostbyname() instead of gethostbyname() to use specific local interface

From: Himanshu S <mail2himanshu_at_gmail.com>
Date: Fri, 28 Oct 2016 17:30:43 -0700

Hello,
 I am new to this mailing list. I was looking for a way to do getaddrinfo()
but I am in a multi homed environment most of the time and hence want an
ability to specify the interface that getaddrinfo should use. I couldn't
find a way to do that but while looking around for answer came across a
post which said c-ares library can help.

My requirement is not about non-blocking call. Since I am replacing
getaddrinfo or gethostbyname in an existing application, blocking call is
better. I see that there is ares_gethostbyname() function available.

My questions are:
- Can C-ares library help? Would setting ares_set_local_dev() before
calling ares_gethostbyname() be the right way to do it?

- How do I make call to ares_gethostbyname() synchronous?

- If there are some examples of code using this library, that would help me
reach a decision fast.

Thank in advance

Best
-Himanshu
Received on 2016-10-29