blob: 39c3a3baf51c9e51bf90faaef1d1b66a70a9dbbb [file] [log] [blame]
From 1909c8096fc8ab5083e929e5b721d74d35bfe414 Mon Sep 17 00:00:00 2001
From: Jason Glasgow <jglasgow@chromium.org>
Date: Fri, 4 Nov 2011 16:48:05 -0400
Subject: [PATCH] Do not try to do DNS name resolution on interface names
Do not try to do DNS name resolution on interface names because it can
block and that is no desirable when using multi interfaces.
---
lib/connect.c | 5 ++++-
lib/if2ip.c | 31 +++++++++++++++++++++++++++++++
lib/if2ip.h | 1 +
3 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/lib/connect.c b/lib/connect.c
index 56a57b1..4305864 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -265,7 +265,10 @@ static CURLcode bindlocal(struct connectdata *conn,
if(dev && (strlen(dev)<255) ) {
/* interface */
- if(Curl_if2ip(af, dev, myhost, sizeof(myhost))) {
+ if(Curl_if_is_interface_name(dev)) {
+ if(Curl_if2ip(af, dev, myhost, sizeof(myhost)) == NULL)
+ return CURLE_INTERFACE_FAILED;
+
/*
* We now have the numerical IP address in the 'myhost' buffer
*/
diff --git a/lib/if2ip.c b/lib/if2ip.c
index 4924f73..0ae375b 100644
--- a/lib/if2ip.c
+++ b/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;
diff --git a/lib/if2ip.h b/lib/if2ip.h
index cdf2638..678e3a5 100644
--- a/lib/if2ip.h
+++ b/lib/if2ip.h
@@ -23,6 +23,7 @@
***************************************************************************/
#include "setup.h"
+extern bool Curl_if_is_interface_name(const char *interface);
extern char *Curl_if2ip(int af, const char *interf, char *buf, int buf_size);
#ifdef __INTERIX
--
1.7.3.1