aboutsummaryrefslogtreecommitdiff
path: root/lib/curl_addrinfo.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2010-11-05 22:31:40 +0100
committerDaniel Stenberg <daniel@haxx.se>2010-11-08 08:56:21 +0100
commit1b24b89cca3c06e36b69969af8edeeaca659515b (patch)
treebaa8fdb1a290d28e7bf7ca54ca8fd482dc98c3dc /lib/curl_addrinfo.c
parentdc3e7df1c99c2ee9dae06453adbb94fe9584bf75 (diff)
CURLOPT_RESOLVE: added
CURLOPT_RESOLVE is a new option that sends along a curl_slist with name:port:address sets that will populate the DNS cache with entries so that request can be "fooled" to use another host than what otherwise would've been used. Previously we've encouraged the use of Host: for that when dealing with HTTP, but this new feature has the added bonus that it allows the name from the URL to be used for TLS SNI and server certificate name checks as well. This is a first change. Surely more will follow to make it decent.
Diffstat (limited to 'lib/curl_addrinfo.c')
-rw-r--r--lib/curl_addrinfo.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c
index 5098fa431..cfb858c6b 100644
--- a/lib/curl_addrinfo.c
+++ b/lib/curl_addrinfo.c
@@ -49,6 +49,7 @@
#endif
#include "curl_addrinfo.h"
+#include "inet_pton.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -434,6 +435,26 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port)
return ai;
}
+/*
+ * Given an IPv4 or IPv6 dotted string address, this converts it to a proper
+ * allocated Curl_addrinfo struct and returns it.
+ */
+Curl_addrinfo *Curl_str2addr(char *address, int port)
+{
+ struct in_addr in;
+ if(Curl_inet_pton(AF_INET, address, &in) > 0)
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(AF_INET, &in, address, port);
+#ifdef ENABLE_IPV6
+ else {
+ struct in6_addr in6;
+ if(Curl_inet_pton(AF_INET6, address, &in6) > 0)
+ /* This is a dotted IPv6 address ::1-style */
+ return Curl_ip2addr(AF_INET6, &in6, address, port);
+ }
+#endif
+ return NULL; /* bad input format */
+}
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
/*