if(data->set.ip_version == CURL_IPRESOLVE_V6) {
/* see if we have an IPv6 stack */
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
- if (s < 0)
+ if (s != CURL_SOCKET_BAD)
/* an ipv6 address was requested and we can't get/use one */
return FALSE;
sclose(s);
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
-#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
-#include "inet_ntoa_r.h"
-#endif
+#include "inet_ntop.h"
/* The last #include file should be: */
#ifdef CURLDEBUG
#endif
#ifdef DEBUG_THREADING_GETADDRINFO
-
-/* inet_ntop.c */
-extern const char *Curl_inet_ntop (int af, const void *addr, char *buf, size_t size);
-
static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai)
{
TRACE(("dump_addrinfo:\n"));
for ( ; ai; ai = ai->ai_next) {
char buf [INET6_ADDRSTRLEN];
+
trace_it(" fam %2d, CNAME %s, ",
- af, ai->ai_canonname ? ai->ai_canonname : "<none>");
+ ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
if (Curl_printable_address(ai->ai_family, ai->ai_addr, buf, sizeof(buf)))
trace_it("%s\n", buf);
else
Curl_safefree(conn->async.hostname);
conn->async.hostname = strdup(hostname);
+#ifdef USE_LIBIDN
+ if (conn->ace_hostname)
+ TRACE(("ACE name '%s'\n", conn->ace_hostname));
+#endif
if (!conn->async.hostname) {
free(td);
SetLastError(ENOMEM);
/* see if we have an IPv6 stack */
s = socket(PF_INET6, SOCK_DGRAM, 0);
- if (s < 0) {
+ if (s != CURL_SOCKET_BAD) {
/* Some non-IPv6 stacks have been found to make very slow name resolves
* when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
* the stack seems to be a non-ipv6 one. */
#include "http_negotiate.h"
#include "url.h"
#include "share.h"
+#include "hostip.h"
#include "http.h"
#define _MPRINTF_REPLACE /* use our functions only */
host due to a location-follow, we do some weirdo checks here */
if(!data->state.this_is_a_follow ||
!data->state.auth_host ||
- curl_strequal(data->state.auth_host, conn->hostname) ||
+ curl_strequal(data->state.auth_host, TRUE_HOSTNAME(conn)) ||
data->set.http_disable_hostname_check_before_authentication) {
/* Send proxy authentication header if needed */
/* either HTTPS over proxy, OR explicitly asked for a tunnel */
result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET,
- conn->hostname, conn->remote_port);
+ TRUE_HOSTNAME(conn), conn->remote_port);
if(CURLE_OK != result)
return result;
}
/* Free to avoid leaking memory on multiple requests*/
free(data->state.auth_host);
- data->state.auth_host = strdup(conn->hostname);
+ data->state.auth_host = strdup(TRUE_HOSTNAME(conn));
}
return CURLE_OK;
struct HTTP *http;
struct Cookie *co=NULL; /* no cookies from start */
char *ppath = conn->path;
- char *host = conn->hostname;
+ char *host = TRUE_HOSTNAME(conn);
const char *te = ""; /* tranfer-encoding */
char *ptr;
char *request;
#include "inet_ntop.h"
#include <ca-bundle.h>
-#include <curl/types.h>
-
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
#include "inet_ntoa_r.h"
#endif
static bool safe_strequal(char* str1, char* str2);
#ifdef USE_LIBIDN
-static bool is_ASCII_name (const char *hostname);
-static bool is_ACE_name (const char *hostname);
+static bool is_ASCII_name(const char *hostname);
#endif
#ifndef USE_ARES
Curl_safefree(conn->newurl);
Curl_safefree(conn->pathbuffer); /* the URL path buffer */
Curl_safefree(conn->namebuffer); /* the URL host name buffer */
+#ifdef USE_LIBIDN
+ Curl_safefree(conn->ace_hostname);
+#endif
Curl_SSL_Close(conn);
/* close possibly still open sockets */
continue;
if(strequal(needle->protostr, check->protostr) &&
- strequal(needle->hostname, check->hostname) &&
+ strequal(TRUE_HOSTNAME(needle), TRUE_HOSTNAME(check)) &&
(needle->remote_port == check->remote_port) ) {
if(needle->protocol & PROT_SSL) {
/* This is SSL, verify that we're using the same
#ifndef ENABLE_IPV6
struct Curl_dns_entry *dns;
Curl_addrinfo *hp=NULL;
- int rc = Curl_resolv(conn, conn->hostname, conn->remote_port, &dns);
+ int rc = Curl_resolv(conn, TRUE_HOSTNAME(conn), conn->remote_port, &dns);
if(rc == -1)
return 1;
free(conn->namebuffer); /* free the newly allocated name buffer */
conn->namebuffer = old_conn->namebuffer; /* use the old one */
conn->hostname = old_conn->hostname;
+#ifdef USE_LIBIDN
+ Curl_safefree(conn->ace_hostname);
+ conn->ace_hostname = old_conn->ace_hostname;
+#endif
free(conn->pathbuffer); /* free the newly allocated path pointer */
conn->pathbuffer = old_conn->pathbuffer; /* use the old one */
conn->port = conn->remote_port; /* it is the same port */
/* Resolve target host right on */
- rc = Curl_resolv(conn, conn->hostname, conn->port, &hostaddr);
+ rc = Curl_resolv(conn, TRUE_HOSTNAME(conn), conn->port, &hostaddr);
if(rc == 1)
*async = TRUE;
const char *host = conn->hostname;
char *ace_hostname;
- if (!is_ASCII_name(host) && !is_ACE_name(host)) {
- int rc = idna_to_ascii_lz (host, &ace_hostname, 0);
-
- if (rc == IDNA_SUCCESS)
- conn->ace_hostname = ace_hostname;
- else
- infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
+ if (!is_ASCII_name(host)) {
+ int rc = idna_to_ascii_lz (host, &ace_hostname, 0);
+ if (rc == IDNA_SUCCESS)
+ conn->ace_hostname = ace_hostname;
+ else
+ infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
}
}
#endif
}
/*
- * Helpers for IDNA convertions. To do.
+ * Helpers for IDNA convertions.
*/
#ifdef USE_LIBIDN
static bool is_ASCII_name (const char *hostname)
{
- (void) hostname;
- return (TRUE);
-}
+ const unsigned char *ch = (const unsigned char*)hostname;
-static bool is_ACE_name (const char *hostname)
-{
- (void) hostname;
- return (FALSE);
+ while (*ch) {
+ if (*ch++ > 0x80)
+ return FALSE;
+ }
+ return TRUE;
}
#endif
somewhere within the namebuffer[] area */
#ifdef USE_LIBIDN
char *ace_hostname; /* hostname possibly converted to ACE form */
+#define TRUE_HOSTNAME(conn) \
+ (conn->ace_hostname ? conn->ace_hostname : conn->hostname)
+#else
+#define TRUE_HOSTNAME(conn) conn->hostname
#endif
char *pathbuffer;/* allocated buffer to store the URL's path part in */
char *path; /* path to use, points to somewhere within the pathbuffer