From 6e4835c795996ee92ac1aa78733f23a089f310a5 Mon Sep 17 00:00:00 2001 From: Jason Glasgow <jglasgow@chromium.org> Date: Fri, 4 Nov 2011 16:48:05 -0400 Subject: 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. --- lib/connect.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/connect.c') diff --git a/lib/connect.c b/lib/connect.c index af225ab83..906fd9d18 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -240,6 +240,10 @@ static CURLcode bindlocal(struct connectdata *conn, int error; char myhost[256] = ""; int done = 0; /* -1 for error, 1 for address found */ + int is_interface = FALSE; + int is_host = FALSE; + static const char *if_prefix = "if!"; + static const char *host_prefix = "host!"; /************************************************************* * Select device to bind socket to @@ -251,9 +255,20 @@ static CURLcode bindlocal(struct connectdata *conn, memset(&sa, 0, sizeof(struct Curl_sockaddr_storage)); if(dev && (strlen(dev)<255) ) { + if(strncmp(if_prefix, dev, strlen(if_prefix)) == 0) { + dev += strlen(if_prefix); + is_interface = TRUE; + } + else if(strncmp(host_prefix, dev, strlen(host_prefix)) == 0) { + dev += strlen(host_prefix); + is_host = TRUE; + } /* interface */ - if(Curl_if2ip(af, dev, myhost, sizeof(myhost))) { + if(!is_host && (is_interface || 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 */ -- cgit v1.2.1