CURLOPT_INTERFACE: avoid resolving interfaces names
Do not try to resolve interfaces names via DNS by recognizing interface names in a few ways. If the interface option argument has a prefix of "if!" then treat the argument as only an interface. Similarly, if the interface argument is the name of an interface (even if it does not have an IP address assigned), treat it as an interface name. Finally, if the interface argument is prefixed by "host!" treat it as a hostname that must be resolved by /etc/hosts or DNS. These changes allow a client using the multi interfaces to avoid blocking on name resolution if the interface loses its IP address or disappears.
This commit is contained in:

committed by
Daniel Stenberg

parent
ba057c2e19
commit
6e4835c795
31
lib/if2ip.c
31
lib/if2ip.c
@@ -71,6 +71,24 @@
|
||||
|
||||
#if defined(HAVE_GETIFADDRS)
|
||||
|
||||
bool Curl_if_is_interface_name(const char *interface)
|
||||
{
|
||||
bool result = FALSE;
|
||||
|
||||
struct ifaddrs *iface, *head;
|
||||
|
||||
if(getifaddrs(&head) >= 0) {
|
||||
for(iface=head; iface != NULL; iface=iface->ifa_next) {
|
||||
if(curl_strequal(iface->ifa_name, interface)) {
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
freeifaddrs(head);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char *Curl_if2ip(int af, const char *interface, char *buf, int buf_size)
|
||||
{
|
||||
struct ifaddrs *iface, *head;
|
||||
@@ -109,6 +127,14 @@ char *Curl_if2ip(int af, const char *interface, char *buf, int buf_size)
|
||||
|
||||
#elif defined(HAVE_IOCTL_SIOCGIFADDR)
|
||||
|
||||
bool Curl_if_is_interface_name(const char *interface)
|
||||
{
|
||||
/* This is here just to support the old interfaces */
|
||||
char buf[256];
|
||||
|
||||
return (Curl_if2ip(AF_INET, interface, buf, sizeof(buf)) != NULL);
|
||||
}
|
||||
|
||||
char *Curl_if2ip(int af, const char *interface, char *buf, int buf_size)
|
||||
{
|
||||
struct ifreq req;
|
||||
@@ -148,6 +174,11 @@ char *Curl_if2ip(int af, const char *interface, char *buf, int buf_size)
|
||||
|
||||
#else
|
||||
|
||||
bool Curl_if_is_interface_name(const char *interface)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char *Curl_if2ip(int af, const char *interf, char *buf, int buf_size)
|
||||
{
|
||||
(void) af;
|
||||
|
Reference in New Issue
Block a user