2004-04-26 03:20:11 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-01-10 16:38:44 -05:00
|
|
|
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2004-04-26 03:20:11 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-04-26 03:20:11 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2019-10-05 09:41:09 -04:00
|
|
|
#include "socketpair.h"
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2017-05-07 13:02:34 -04:00
|
|
|
/***********************************************************************
|
|
|
|
* Only for threaded name resolves builds
|
|
|
|
**********************************************************************/
|
|
|
|
#ifdef CURLRES_THREADED
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
2009-12-30 12:59:56 -05:00
|
|
|
#ifdef __VMS
|
2004-04-26 03:20:11 -04:00
|
|
|
#include <in.h>
|
|
|
|
#include <inet.h>
|
|
|
|
#endif
|
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
#if defined(USE_THREADS_POSIX)
|
|
|
|
# ifdef HAVE_PTHREAD_H
|
|
|
|
# include <pthread.h>
|
|
|
|
# endif
|
|
|
|
#elif defined(USE_THREADS_WIN32)
|
|
|
|
# ifdef HAVE_PROCESS_H
|
|
|
|
# include <process.h>
|
|
|
|
# endif
|
2004-04-26 03:20:11 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
|
|
|
|
#undef in_addr_t
|
|
|
|
#define in_addr_t unsigned long
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 07:07:49 -04:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
|
|
|
# define RESOLVER_ENOMEM EAI_MEMORY
|
|
|
|
#else
|
|
|
|
# define RESOLVER_ENOMEM ENOMEM
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "hostip.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "share.h"
|
|
|
|
#include "strerror.h"
|
|
|
|
#include "url.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "inet_ntop.h"
|
2010-01-25 18:50:13 -05:00
|
|
|
#include "curl_threads.h"
|
2014-05-21 19:09:11 -04:00
|
|
|
#include "connect.h"
|
2019-10-05 09:41:09 -04:00
|
|
|
#include "socketpair.h"
|
2016-04-29 09:46:40 -04:00
|
|
|
/* The last 3 #include files should be in this order */
|
2015-03-03 06:36:18 -05:00
|
|
|
#include "curl_printf.h"
|
2009-04-21 07:46:16 -04:00
|
|
|
#include "curl_memory.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h"
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2018-03-22 12:59:58 -04:00
|
|
|
struct resdata {
|
|
|
|
struct curltime start;
|
|
|
|
};
|
|
|
|
|
2011-01-29 14:12:10 -05:00
|
|
|
/*
|
2011-01-29 19:00:52 -05:00
|
|
|
* Curl_resolver_global_init()
|
2011-01-29 14:12:10 -05:00
|
|
|
* Called from curl_global_init() to initialize global resolver environment.
|
|
|
|
* Does nothing here.
|
|
|
|
*/
|
2011-01-29 19:00:52 -05:00
|
|
|
int Curl_resolver_global_init(void)
|
2011-01-29 14:12:10 -05:00
|
|
|
{
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-29 19:00:52 -05:00
|
|
|
* Curl_resolver_global_cleanup()
|
2011-01-29 14:12:10 -05:00
|
|
|
* Called from curl_global_cleanup() to destroy global resolver environment.
|
|
|
|
* Does nothing here.
|
|
|
|
*/
|
2011-01-29 19:00:52 -05:00
|
|
|
void Curl_resolver_global_cleanup(void)
|
2011-01-29 14:12:10 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-29 19:00:52 -05:00
|
|
|
* Curl_resolver_init()
|
|
|
|
* Called from curl_easy_init() -> Curl_open() to initialize resolver
|
|
|
|
* URL-state specific environment ('resolver' member of the UrlState
|
2018-03-22 12:59:58 -04:00
|
|
|
* structure).
|
2011-01-29 14:12:10 -05:00
|
|
|
*/
|
2018-11-05 05:01:19 -05:00
|
|
|
CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
|
2011-01-29 14:12:10 -05:00
|
|
|
{
|
2018-11-05 05:01:19 -05:00
|
|
|
(void)easy;
|
2018-03-22 12:59:58 -04:00
|
|
|
*resolver = calloc(1, sizeof(struct resdata));
|
|
|
|
if(!*resolver)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-01-29 14:12:10 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-29 19:00:52 -05:00
|
|
|
* Curl_resolver_cleanup()
|
|
|
|
* Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
|
|
|
|
* URL-state specific environment ('resolver' member of the UrlState
|
2018-03-22 12:59:58 -04:00
|
|
|
* structure).
|
2011-01-29 14:12:10 -05:00
|
|
|
*/
|
|
|
|
void Curl_resolver_cleanup(void *resolver)
|
|
|
|
{
|
2018-03-22 12:59:58 -04:00
|
|
|
free(resolver);
|
2011-01-29 14:12:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-29 19:00:52 -05:00
|
|
|
* Curl_resolver_duphandle()
|
|
|
|
* Called from curl_easy_duphandle() to duplicate resolver URL state-specific
|
2018-03-22 12:59:58 -04:00
|
|
|
* environment ('resolver' member of the UrlState structure).
|
2011-01-29 14:12:10 -05:00
|
|
|
*/
|
2018-11-05 05:01:19 -05:00
|
|
|
CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from)
|
2011-01-29 14:12:10 -05:00
|
|
|
{
|
|
|
|
(void)from;
|
2018-11-05 05:01:19 -05:00
|
|
|
return Curl_resolver_init(easy, to);
|
2011-01-29 14:12:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_async_data(struct Curl_async *);
|
2011-01-30 18:10:35 -05:00
|
|
|
|
2011-01-29 14:12:10 -05:00
|
|
|
/*
|
|
|
|
* Cancel all possibly still on-going resolves for this connection.
|
|
|
|
*/
|
2011-01-30 18:10:35 -05:00
|
|
|
void Curl_resolver_cancel(struct connectdata *conn)
|
2011-01-29 14:12:10 -05:00
|
|
|
{
|
|
|
|
destroy_async_data(&conn->async);
|
|
|
|
}
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
/* This function is used to init a threaded resolve */
|
|
|
|
static bool init_resolve_thread(struct connectdata *conn,
|
|
|
|
const char *hostname, int port,
|
2008-11-01 11:16:47 -04:00
|
|
|
const struct addrinfo *hints);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Data for synchronization between resolver thread and its parent */
|
|
|
|
struct thread_sync_data {
|
2020-05-13 06:56:53 -04:00
|
|
|
curl_mutex_t *mtx;
|
2010-01-25 18:50:13 -05:00
|
|
|
int done;
|
|
|
|
|
2016-11-23 01:53:24 -05:00
|
|
|
char *hostname; /* hostname to resolve, Curl_async.hostname
|
|
|
|
duplicate */
|
2010-01-25 18:50:13 -05:00
|
|
|
int port;
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-08-10 17:20:23 -04:00
|
|
|
struct connectdata *conn;
|
2019-07-26 11:58:41 -04:00
|
|
|
curl_socket_t sock_pair[2]; /* socket pair */
|
|
|
|
#endif
|
2010-01-25 18:50:13 -05:00
|
|
|
int sock_error;
|
2020-05-13 18:05:04 -04:00
|
|
|
struct Curl_addrinfo *res;
|
2010-01-25 18:50:13 -05:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
|
|
|
struct addrinfo hints;
|
|
|
|
#endif
|
2014-08-20 17:31:53 -04:00
|
|
|
struct thread_data *td; /* for thread-self cleanup */
|
2010-01-25 18:50:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct thread_data {
|
|
|
|
curl_thread_t thread_hnd;
|
|
|
|
unsigned int poll_interval;
|
2020-05-28 18:08:03 -04:00
|
|
|
timediff_t interval_end;
|
2010-01-25 18:50:13 -05:00
|
|
|
struct thread_sync_data tsd;
|
2005-08-29 10:23:53 -04:00
|
|
|
};
|
|
|
|
|
2011-01-29 19:00:52 -05:00
|
|
|
static struct thread_sync_data *conn_thread_sync_data(struct connectdata *conn)
|
2010-01-25 18:50:13 -05:00
|
|
|
{
|
|
|
|
return &(((struct thread_data *)conn->async.os_specific)->tsd);
|
|
|
|
}
|
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Destroy resolver thread synchronization data */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2020-05-13 06:56:53 -04:00
|
|
|
void destroy_thread_sync_data(struct thread_sync_data *tsd)
|
2005-08-29 10:23:53 -04:00
|
|
|
{
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tsd->mtx) {
|
2010-01-25 18:50:13 -05:00
|
|
|
Curl_mutex_destroy(tsd->mtx);
|
|
|
|
free(tsd->mtx);
|
|
|
|
}
|
|
|
|
|
2015-03-11 12:41:01 -04:00
|
|
|
free(tsd->hostname);
|
2010-02-13 13:29:59 -05:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tsd->res)
|
2010-01-25 18:50:13 -05:00
|
|
|
Curl_freeaddrinfo(tsd->res);
|
|
|
|
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-08-10 17:20:23 -04:00
|
|
|
/*
|
|
|
|
* close one end of the socket pair (may be done in resolver thread);
|
|
|
|
* the other end (for reading) is always closed in the parent thread.
|
|
|
|
*/
|
2019-07-26 11:58:41 -04:00
|
|
|
if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
|
|
|
|
sclose(tsd->sock_pair[1]);
|
|
|
|
}
|
|
|
|
#endif
|
2015-03-17 08:41:49 -04:00
|
|
|
memset(tsd, 0, sizeof(*tsd));
|
2005-08-29 10:23:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize resolver thread synchronization data */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2020-05-13 06:56:53 -04:00
|
|
|
int init_thread_sync_data(struct thread_data *td,
|
2016-11-23 01:53:24 -05:00
|
|
|
const char *hostname,
|
2010-02-13 13:29:59 -05:00
|
|
|
int port,
|
|
|
|
const struct addrinfo *hints)
|
2005-08-29 10:23:53 -04:00
|
|
|
{
|
2014-08-20 17:31:53 -04:00
|
|
|
struct thread_sync_data *tsd = &td->tsd;
|
|
|
|
|
2006-10-17 16:34:11 -04:00
|
|
|
memset(tsd, 0, sizeof(*tsd));
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2014-08-20 17:31:53 -04:00
|
|
|
tsd->td = td;
|
2010-01-25 18:50:13 -05:00
|
|
|
tsd->port = port;
|
2017-08-28 18:30:30 -04:00
|
|
|
/* Treat the request as done until the thread actually starts so any early
|
|
|
|
* cleanup gets done properly.
|
|
|
|
*/
|
|
|
|
tsd->done = 1;
|
2014-01-10 02:37:43 -05:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
2010-01-25 18:50:13 -05:00
|
|
|
DEBUGASSERT(hints);
|
|
|
|
tsd->hints = *hints;
|
|
|
|
#else
|
|
|
|
(void) hints;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tsd->mtx = malloc(sizeof(curl_mutex_t));
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tsd->mtx == NULL)
|
|
|
|
goto err_exit;
|
2010-01-25 18:50:13 -05:00
|
|
|
|
|
|
|
Curl_mutex_init(tsd->mtx);
|
|
|
|
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-09-11 17:11:58 -04:00
|
|
|
/* create socket pair, avoid AF_LOCAL since it doesn't build on Solaris */
|
2019-10-05 09:41:09 -04:00
|
|
|
if(Curl_socketpair(AF_UNIX, SOCK_STREAM, 0, &tsd->sock_pair[0]) < 0) {
|
2019-07-26 11:58:41 -04:00
|
|
|
tsd->sock_pair[0] = CURL_SOCKET_BAD;
|
|
|
|
tsd->sock_pair[1] = CURL_SOCKET_BAD;
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-25 18:50:13 -05:00
|
|
|
tsd->sock_error = CURL_ASYNC_SUCCESS;
|
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Copying hostname string because original can be destroyed by parent
|
|
|
|
* thread during gethostbyname execution.
|
|
|
|
*/
|
|
|
|
tsd->hostname = strdup(hostname);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!tsd->hostname)
|
|
|
|
goto err_exit;
|
2005-08-29 10:23:53 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
return 1;
|
2005-08-29 10:23:53 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
err_exit:
|
|
|
|
/* Memory allocation failed */
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
return 0;
|
2005-08-29 10:23:53 -04:00
|
|
|
}
|
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
static int getaddrinfo_complete(struct connectdata *conn)
|
|
|
|
{
|
|
|
|
struct thread_sync_data *tsd = conn_thread_sync_data(conn);
|
|
|
|
int rc;
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2010-02-13 13:29:59 -05:00
|
|
|
rc = Curl_addrinfo_callback(conn, tsd->sock_error, tsd->res);
|
2011-01-29 19:00:52 -05:00
|
|
|
/* The tsd->res structure has been copied to async.dns and perhaps the DNS
|
|
|
|
cache. Set our copy to NULL so destroy_thread_sync_data doesn't free it.
|
|
|
|
*/
|
2010-01-25 18:50:13 -05:00
|
|
|
tsd->res = NULL;
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
return rc;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2010-02-13 13:39:47 -05:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
/*
|
2010-01-25 18:50:13 -05:00
|
|
|
* getaddrinfo_thread() resolves a name and then exits.
|
2004-04-26 03:20:11 -04:00
|
|
|
*
|
|
|
|
* For builds without ARES, but with ENABLE_IPV6, create a resolver thread
|
|
|
|
* and wait on it.
|
|
|
|
*/
|
2016-12-13 17:34:59 -05:00
|
|
|
static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2010-01-25 18:50:13 -05:00
|
|
|
struct thread_sync_data *tsd = (struct thread_sync_data*)arg;
|
2014-08-20 17:31:53 -04:00
|
|
|
struct thread_data *td = tsd->td;
|
2013-09-10 17:18:43 -04:00
|
|
|
char service[12];
|
2010-01-25 18:50:13 -05:00
|
|
|
int rc;
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-07-26 11:58:41 -04:00
|
|
|
char buf[1];
|
|
|
|
#endif
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2018-11-22 03:01:24 -05:00
|
|
|
msnprintf(service, sizeof(service), "%d", tsd->port);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc != 0) {
|
2011-04-27 07:07:49 -04:00
|
|
|
tsd->sock_error = SOCKERRNO?SOCKERRNO:rc;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tsd->sock_error == 0)
|
2011-04-27 07:07:49 -04:00
|
|
|
tsd->sock_error = RESOLVER_ENOMEM;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2016-06-07 06:11:37 -04:00
|
|
|
else {
|
|
|
|
Curl_addrinfo_set_port(tsd->res, tsd->port);
|
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
Curl_mutex_acquire(tsd->mtx);
|
2014-08-20 17:31:53 -04:00
|
|
|
if(tsd->done) {
|
|
|
|
/* too late, gotta clean up the mess */
|
|
|
|
Curl_mutex_release(tsd->mtx);
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
free(td);
|
|
|
|
}
|
|
|
|
else {
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-07-26 11:58:41 -04:00
|
|
|
if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
|
|
|
|
/* DNS has been resolved, signal client task */
|
|
|
|
buf[0] = 1;
|
2019-10-05 09:41:09 -04:00
|
|
|
if(swrite(tsd->sock_pair[1], buf, sizeof(buf)) < 0) {
|
2019-07-26 11:58:41 -04:00
|
|
|
/* update sock_erro to errno */
|
|
|
|
tsd->sock_error = SOCKERRNO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-20 17:31:53 -04:00
|
|
|
tsd->done = 1;
|
|
|
|
Curl_mutex_release(tsd->mtx);
|
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
return 0;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2010-02-13 13:39:47 -05:00
|
|
|
#else /* HAVE_GETADDRINFO */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gethostbyname_thread() resolves a name and then exits.
|
|
|
|
*/
|
2016-12-13 17:34:59 -05:00
|
|
|
static unsigned int CURL_STDCALL gethostbyname_thread(void *arg)
|
2010-02-13 13:39:47 -05:00
|
|
|
{
|
|
|
|
struct thread_sync_data *tsd = (struct thread_sync_data *)arg;
|
2014-08-20 17:31:53 -04:00
|
|
|
struct thread_data *td = tsd->td;
|
2010-02-13 13:39:47 -05:00
|
|
|
|
|
|
|
tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port);
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!tsd->res) {
|
2010-02-13 13:39:47 -05:00
|
|
|
tsd->sock_error = SOCKERRNO;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tsd->sock_error == 0)
|
2011-04-27 07:07:49 -04:00
|
|
|
tsd->sock_error = RESOLVER_ENOMEM;
|
2010-02-13 13:39:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Curl_mutex_acquire(tsd->mtx);
|
2014-08-20 17:31:53 -04:00
|
|
|
if(tsd->done) {
|
|
|
|
/* too late, gotta clean up the mess */
|
|
|
|
Curl_mutex_release(tsd->mtx);
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
free(td);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tsd->done = 1;
|
|
|
|
Curl_mutex_release(tsd->mtx);
|
|
|
|
}
|
2010-02-13 13:39:47 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
#endif /* HAVE_GETADDRINFO */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
/*
|
2011-01-29 14:12:10 -05:00
|
|
|
* destroy_async_data() cleans up async resolver data and thread handle.
|
2004-04-26 03:20:11 -04:00
|
|
|
*/
|
2016-12-13 17:34:59 -05:00
|
|
|
static void destroy_async_data(struct Curl_async *async)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2007-11-05 04:45:09 -05:00
|
|
|
if(async->os_specific) {
|
2004-10-16 08:59:05 -04:00
|
|
|
struct thread_data *td = (struct thread_data*) async->os_specific;
|
2014-08-20 17:31:53 -04:00
|
|
|
int done;
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-08-10 17:20:23 -04:00
|
|
|
curl_socket_t sock_rd = td->tsd.sock_pair[0];
|
|
|
|
struct connectdata *conn = td->tsd.conn;
|
|
|
|
#endif
|
2014-08-20 17:31:53 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if the thread is still blocking in the resolve syscall, detach it and
|
|
|
|
* let the thread do the cleanup...
|
|
|
|
*/
|
|
|
|
Curl_mutex_acquire(td->tsd.mtx);
|
|
|
|
done = td->tsd.done;
|
|
|
|
td->tsd.done = 1;
|
|
|
|
Curl_mutex_release(td->tsd.mtx);
|
|
|
|
|
|
|
|
if(!done) {
|
|
|
|
Curl_thread_destroy(td->thread_hnd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(td->thread_hnd != curl_thread_t_null)
|
|
|
|
Curl_thread_join(&td->thread_hnd);
|
|
|
|
|
|
|
|
destroy_thread_sync_data(&td->tsd);
|
|
|
|
|
|
|
|
free(async->os_specific);
|
|
|
|
}
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-08-10 17:20:23 -04:00
|
|
|
/*
|
|
|
|
* ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE
|
|
|
|
* before the FD is invalidated to avoid EBADF on EPOLL_CTL_DEL
|
|
|
|
*/
|
|
|
|
if(conn)
|
|
|
|
Curl_multi_closed(conn->data, sock_rd);
|
|
|
|
sclose(sock_rd);
|
|
|
|
#endif
|
2014-08-20 17:31:53 -04:00
|
|
|
}
|
|
|
|
async->os_specific = NULL;
|
2005-08-29 10:23:53 -04:00
|
|
|
|
2015-03-11 12:41:01 -04:00
|
|
|
free(async->hostname);
|
2004-04-26 03:20:11 -04:00
|
|
|
async->hostname = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_resolve_thread() starts a new thread that performs the actual
|
|
|
|
* resolve. This function returns before the resolve is done.
|
|
|
|
*
|
|
|
|
* Returns FALSE in case of failure, otherwise TRUE.
|
|
|
|
*/
|
2016-12-13 17:34:59 -05:00
|
|
|
static bool init_resolve_thread(struct connectdata *conn,
|
|
|
|
const char *hostname, int port,
|
|
|
|
const struct addrinfo *hints)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2009-11-18 05:33:54 -05:00
|
|
|
struct thread_data *td = calloc(1, sizeof(struct thread_data));
|
2017-08-28 17:41:04 -04:00
|
|
|
int err = ENOMEM;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2016-11-23 02:30:18 -05:00
|
|
|
conn->async.os_specific = (void *)td;
|
2010-02-13 13:29:59 -05:00
|
|
|
if(!td)
|
2017-08-28 17:43:36 -04:00
|
|
|
goto errno_exit;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
conn->async.port = port;
|
|
|
|
conn->async.done = FALSE;
|
|
|
|
conn->async.status = 0;
|
|
|
|
conn->async.dns = NULL;
|
2010-01-25 18:50:13 -05:00
|
|
|
td->thread_hnd = curl_thread_t_null;
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2017-08-28 17:43:36 -04:00
|
|
|
if(!init_thread_sync_data(td, hostname, port, hints)) {
|
|
|
|
conn->async.os_specific = NULL;
|
|
|
|
free(td);
|
|
|
|
goto errno_exit;
|
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2015-03-16 10:01:15 -04:00
|
|
|
free(conn->async.hostname);
|
2010-01-25 18:50:13 -05:00
|
|
|
conn->async.hostname = strdup(hostname);
|
|
|
|
if(!conn->async.hostname)
|
|
|
|
goto err_exit;
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2017-08-28 18:30:30 -04:00
|
|
|
/* The thread will set this to 1 when complete. */
|
|
|
|
td->tsd.done = 0;
|
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
|
|
|
td->thread_hnd = Curl_thread_create(getaddrinfo_thread, &td->tsd);
|
2004-04-26 03:20:11 -04:00
|
|
|
#else
|
2010-01-25 18:50:13 -05:00
|
|
|
td->thread_hnd = Curl_thread_create(gethostbyname_thread, &td->tsd);
|
2004-04-26 03:20:11 -04:00
|
|
|
#endif
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!td->thread_hnd) {
|
2017-08-28 18:30:30 -04:00
|
|
|
/* The thread never started, so mark it as done here for proper cleanup. */
|
|
|
|
td->tsd.done = 1;
|
2010-01-25 18:50:13 -05:00
|
|
|
err = errno;
|
|
|
|
goto err_exit;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
return TRUE;
|
2010-01-25 18:50:13 -05:00
|
|
|
|
|
|
|
err_exit:
|
2011-01-29 14:12:10 -05:00
|
|
|
destroy_async_data(&conn->async);
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2017-08-28 17:43:36 -04:00
|
|
|
errno_exit:
|
2017-06-19 00:52:38 -04:00
|
|
|
errno = err;
|
2010-01-25 18:50:13 -05:00
|
|
|
return FALSE;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
2011-04-27 07:07:49 -04:00
|
|
|
/*
|
|
|
|
* resolver_error() calls failf() with the appropriate message after a resolve
|
|
|
|
* error
|
|
|
|
*/
|
|
|
|
|
2013-02-18 15:36:34 -05:00
|
|
|
static CURLcode resolver_error(struct connectdata *conn)
|
2011-04-27 07:07:49 -04:00
|
|
|
{
|
2013-02-18 15:36:34 -05:00
|
|
|
const char *host_or_proxy;
|
2014-12-14 07:52:08 -05:00
|
|
|
CURLcode result;
|
|
|
|
|
2020-05-27 05:51:34 -04:00
|
|
|
#ifndef CURL_DISABLE_PROXY
|
2013-02-18 15:36:34 -05:00
|
|
|
if(conn->bits.httpproxy) {
|
|
|
|
host_or_proxy = "proxy";
|
2014-12-14 07:52:08 -05:00
|
|
|
result = CURLE_COULDNT_RESOLVE_PROXY;
|
2013-02-18 15:36:34 -05:00
|
|
|
}
|
2020-05-27 05:51:34 -04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2013-02-18 15:36:34 -05:00
|
|
|
host_or_proxy = "host";
|
2014-12-14 07:52:08 -05:00
|
|
|
result = CURLE_COULDNT_RESOLVE_HOST;
|
2013-02-18 15:36:34 -05:00
|
|
|
}
|
|
|
|
|
2013-02-18 16:52:58 -05:00
|
|
|
failf(conn->data, "Could not resolve %s: %s", host_or_proxy,
|
|
|
|
conn->async.hostname);
|
2014-12-14 07:52:08 -05:00
|
|
|
|
|
|
|
return result;
|
2011-04-27 07:07:49 -04:00
|
|
|
}
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2020-05-02 10:59:38 -04:00
|
|
|
/*
|
|
|
|
* 'entry' may be NULL and then no data is returned
|
|
|
|
*/
|
2019-02-28 14:34:36 -05:00
|
|
|
static CURLcode thread_wait_resolv(struct connectdata *conn,
|
|
|
|
struct Curl_dns_entry **entry,
|
|
|
|
bool report)
|
|
|
|
{
|
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(conn && td);
|
|
|
|
DEBUGASSERT(td->thread_hnd != curl_thread_t_null);
|
|
|
|
|
|
|
|
/* wait for the thread to resolve the name */
|
|
|
|
if(Curl_thread_join(&td->thread_hnd)) {
|
|
|
|
if(entry)
|
|
|
|
result = getaddrinfo_complete(conn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DEBUGASSERT(0);
|
|
|
|
|
|
|
|
conn->async.done = TRUE;
|
|
|
|
|
|
|
|
if(entry)
|
|
|
|
*entry = conn->async.dns;
|
|
|
|
|
|
|
|
if(!conn->async.dns && report)
|
|
|
|
/* a name was not resolved, report error */
|
|
|
|
result = resolver_error(conn);
|
|
|
|
|
|
|
|
destroy_async_data(&conn->async);
|
|
|
|
|
|
|
|
if(!conn->async.dns && report)
|
|
|
|
connclose(conn, "asynch resolve failed");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-14 16:18:22 -05:00
|
|
|
/*
|
|
|
|
* Until we gain a way to signal the resolver threads to stop early, we must
|
|
|
|
* simply wait for them and ignore their results.
|
|
|
|
*/
|
|
|
|
void Curl_resolver_kill(struct connectdata *conn)
|
|
|
|
{
|
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
|
|
|
|
|
|
|
/* If we're still resolving, we must wait for the threads to fully clean up,
|
|
|
|
unfortunately. Otherwise, we can simply cancel to clean up any resolver
|
|
|
|
data. */
|
|
|
|
if(td && td->thread_hnd != curl_thread_t_null)
|
2019-02-28 14:34:36 -05:00
|
|
|
(void)thread_wait_resolv(conn, NULL, FALSE);
|
2018-12-14 16:18:22 -05:00
|
|
|
else
|
|
|
|
Curl_resolver_cancel(conn);
|
|
|
|
}
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
/*
|
2011-01-30 18:10:35 -05:00
|
|
|
* Curl_resolver_wait_resolv()
|
|
|
|
*
|
2018-12-14 16:18:22 -05:00
|
|
|
* Waits for a resolve to finish. This function should be avoided since using
|
2011-01-30 18:10:35 -05:00
|
|
|
* this risk getting the multi interface to "hang".
|
2004-04-26 03:20:11 -04:00
|
|
|
*
|
|
|
|
* If 'entry' is non-NULL, make it point to the resolved dns entry
|
|
|
|
*
|
2018-12-14 16:18:22 -05:00
|
|
|
* Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
|
|
|
|
* CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
|
|
|
|
*
|
2004-04-26 03:20:11 -04:00
|
|
|
* This is the version for resolves-in-a-thread.
|
|
|
|
*/
|
2011-01-30 18:10:35 -05:00
|
|
|
CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
|
|
|
|
struct Curl_dns_entry **entry)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2019-02-28 14:34:36 -05:00
|
|
|
return thread_wait_resolv(conn, entry, TRUE);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-30 18:10:35 -05:00
|
|
|
* Curl_resolver_is_resolved() is called repeatedly to check if a previous
|
|
|
|
* name resolve request has completed. It should also make sure to time-out if
|
|
|
|
* the operation seems to take too long.
|
2004-04-26 03:20:11 -04:00
|
|
|
*/
|
2011-01-30 18:10:35 -05:00
|
|
|
CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
|
|
|
|
struct Curl_dns_entry **entry)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-01-25 18:50:13 -05:00
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
|
|
|
int done = 0;
|
2010-02-13 13:29:59 -05:00
|
|
|
|
2020-05-02 10:59:38 -04:00
|
|
|
DEBUGASSERT(entry);
|
|
|
|
*entry = NULL;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!td) {
|
2010-01-25 18:50:13 -05:00
|
|
|
DEBUGASSERT(td);
|
|
|
|
return CURLE_COULDNT_RESOLVE_HOST;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_mutex_acquire(td->tsd.mtx);
|
|
|
|
done = td->tsd.done;
|
|
|
|
Curl_mutex_release(td->tsd.mtx);
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(done) {
|
2010-01-25 18:50:13 -05:00
|
|
|
getaddrinfo_complete(conn);
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!conn->async.dns) {
|
2014-12-14 07:52:08 -05:00
|
|
|
CURLcode result = resolver_error(conn);
|
2013-02-18 15:36:34 -05:00
|
|
|
destroy_async_data(&conn->async);
|
2014-12-14 07:52:08 -05:00
|
|
|
return result;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2013-02-18 15:36:34 -05:00
|
|
|
destroy_async_data(&conn->async);
|
2020-05-02 10:59:38 -04:00
|
|
|
*entry = conn->async.dns;
|
2011-04-20 09:17:42 -04:00
|
|
|
}
|
|
|
|
else {
|
2010-01-25 18:50:13 -05:00
|
|
|
/* poll for name lookup done with exponential backoff up to 250ms */
|
2019-07-31 09:30:31 -04:00
|
|
|
/* should be fine even if this converts to 32 bit */
|
2020-05-28 18:08:03 -04:00
|
|
|
timediff_t elapsed = Curl_timediff(Curl_now(),
|
|
|
|
data->progress.t_startsingle);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(elapsed < 0)
|
2010-01-25 18:50:13 -05:00
|
|
|
elapsed = 0;
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(td->poll_interval == 0)
|
2010-01-25 18:50:13 -05:00
|
|
|
/* Start at 1ms poll interval */
|
|
|
|
td->poll_interval = 1;
|
2011-04-20 09:17:42 -04:00
|
|
|
else if(elapsed >= td->interval_end)
|
2010-01-25 18:50:13 -05:00
|
|
|
/* Back-off exponentially if last interval expired */
|
|
|
|
td->poll_interval *= 2;
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(td->poll_interval > 250)
|
2010-01-25 18:50:13 -05:00
|
|
|
td->poll_interval = 250;
|
|
|
|
|
|
|
|
td->interval_end = elapsed + td->poll_interval;
|
2017-05-09 06:47:49 -04:00
|
|
|
Curl_expire(conn->data, td->poll_interval, EXPIRE_ASYNC_NAME);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-30 18:10:35 -05:00
|
|
|
int Curl_resolver_getsock(struct connectdata *conn,
|
2019-07-30 05:02:03 -04:00
|
|
|
curl_socket_t *socks)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2019-07-26 11:58:41 -04:00
|
|
|
int ret_val = 0;
|
2020-05-28 18:08:03 -04:00
|
|
|
timediff_t milli;
|
2018-03-22 12:59:58 -04:00
|
|
|
timediff_t ms;
|
|
|
|
struct Curl_easy *data = conn->data;
|
|
|
|
struct resdata *reslv = (struct resdata *)data->state.resolver;
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-07-26 11:58:41 -04:00
|
|
|
struct thread_data *td = (struct thread_data*)conn->async.os_specific;
|
|
|
|
#else
|
2012-01-03 10:22:50 -05:00
|
|
|
(void)socks;
|
2019-07-26 11:58:41 -04:00
|
|
|
#endif
|
|
|
|
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-07-26 11:58:41 -04:00
|
|
|
if(td) {
|
|
|
|
/* return read fd to client for polling the DNS resolution status */
|
|
|
|
socks[0] = td->tsd.sock_pair[0];
|
2019-08-10 17:20:23 -04:00
|
|
|
DEBUGASSERT(td->tsd.conn == conn || !td->tsd.conn);
|
|
|
|
td->tsd.conn = conn;
|
2019-07-26 11:58:41 -04:00
|
|
|
ret_val = GETSOCK_READSOCK(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
ms = Curl_timediff(Curl_now(), reslv->start);
|
|
|
|
if(ms < 3)
|
|
|
|
milli = 0;
|
|
|
|
else if(ms <= 50)
|
2020-05-28 18:08:03 -04:00
|
|
|
milli = ms/3;
|
2019-07-26 11:58:41 -04:00
|
|
|
else if(ms <= 250)
|
|
|
|
milli = 50;
|
|
|
|
else
|
|
|
|
milli = 200;
|
|
|
|
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
|
2019-10-05 09:41:09 -04:00
|
|
|
#ifdef USE_SOCKETPAIR
|
2019-07-26 11:58:41 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return ret_val;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
2010-02-13 13:39:47 -05:00
|
|
|
#ifndef HAVE_GETADDRINFO
|
2004-04-26 03:20:11 -04:00
|
|
|
/*
|
2010-01-25 18:50:13 -05:00
|
|
|
* Curl_getaddrinfo() - for platforms without getaddrinfo
|
2004-04-26 03:20:11 -04:00
|
|
|
*/
|
2020-05-13 18:05:04 -04:00
|
|
|
struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
|
|
|
const char *hostname,
|
|
|
|
int port,
|
|
|
|
int *waitp)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2018-03-22 12:59:58 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
|
|
|
struct resdata *reslv = (struct resdata *)data->state.resolver;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
*waitp = 0; /* default to synchronous response */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2018-03-22 12:59:58 -04:00
|
|
|
reslv->start = Curl_now();
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
/* fire up a new resolver thread! */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(init_resolve_thread(conn, hostname, port, NULL)) {
|
2010-01-25 18:50:13 -05:00
|
|
|
*waitp = 1; /* expect asynchronous response */
|
2004-04-26 03:20:11 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:59:58 -04:00
|
|
|
failf(conn->data, "getaddrinfo() thread failed\n");
|
|
|
|
|
|
|
|
return NULL;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
2010-02-13 13:39:47 -05:00
|
|
|
#else /* !HAVE_GETADDRINFO */
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
/*
|
2011-01-30 18:10:35 -05:00
|
|
|
* Curl_resolver_getaddrinfo() - for getaddrinfo
|
2004-04-26 03:20:11 -04:00
|
|
|
*/
|
2020-05-13 18:05:04 -04:00
|
|
|
struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
|
|
|
const char *hostname,
|
|
|
|
int port,
|
|
|
|
int *waitp)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2008-10-30 09:45:25 -04:00
|
|
|
struct addrinfo hints;
|
2010-01-25 18:50:13 -05:00
|
|
|
int pf = PF_INET;
|
2018-03-22 12:59:58 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
|
|
|
struct resdata *reslv = (struct resdata *)data->state.resolver;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2010-01-25 18:50:13 -05:00
|
|
|
*waitp = 0; /* default to synchronous response */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2016-06-07 19:23:54 -04:00
|
|
|
#ifdef CURLRES_IPV6
|
2008-07-29 14:26:35 -04:00
|
|
|
/*
|
|
|
|
* Check if a limited name resolve has been requested.
|
|
|
|
*/
|
2010-11-11 08:51:39 -05:00
|
|
|
switch(conn->ip_version) {
|
2008-07-29 14:26:35 -04:00
|
|
|
case CURL_IPRESOLVE_V4:
|
2004-04-26 03:20:11 -04:00
|
|
|
pf = PF_INET;
|
2008-07-29 14:26:35 -04:00
|
|
|
break;
|
|
|
|
case CURL_IPRESOLVE_V6:
|
|
|
|
pf = PF_INET6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pf = PF_UNSPEC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-26 11:51:01 -05:00
|
|
|
if((pf != PF_INET) && !Curl_ipv6works(conn))
|
2014-12-27 06:09:01 -05:00
|
|
|
/* The stack seems to be a non-IPv6 one */
|
2011-03-23 06:10:55 -04:00
|
|
|
pf = PF_INET;
|
2011-08-06 09:21:42 -04:00
|
|
|
#endif /* CURLRES_IPV6 */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = pf;
|
2019-07-21 17:48:58 -04:00
|
|
|
hints.ai_socktype = (conn->transport == TRNSPRT_TCP)?
|
|
|
|
SOCK_STREAM : SOCK_DGRAM;
|
2010-04-16 09:03:52 -04:00
|
|
|
|
2018-03-22 12:59:58 -04:00
|
|
|
reslv->start = Curl_now();
|
2004-04-26 03:20:11 -04:00
|
|
|
/* fire up a new resolver thread! */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(init_resolve_thread(conn, hostname, port, &hints)) {
|
2010-01-25 18:50:13 -05:00
|
|
|
*waitp = 1; /* expect asynchronous response */
|
2004-04-26 03:20:11 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:59:58 -04:00
|
|
|
failf(data, "getaddrinfo() thread failed to start\n");
|
|
|
|
return NULL;
|
2016-06-07 06:11:37 -04:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2010-02-13 13:39:47 -05:00
|
|
|
#endif /* !HAVE_GETADDRINFO */
|
2010-01-25 18:50:13 -05:00
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_set_dns_servers(struct Curl_easy *data,
|
2011-04-12 11:34:28 -04:00
|
|
|
char *servers)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)servers;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_set_dns_interface(struct Curl_easy *data,
|
2013-09-17 15:59:43 -04:00
|
|
|
const char *interf)
|
2013-09-07 12:45:50 -04:00
|
|
|
{
|
|
|
|
(void)data;
|
2013-09-17 15:59:43 -04:00
|
|
|
(void)interf;
|
2013-09-07 12:45:50 -04:00
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
|
2013-09-07 12:45:50 -04:00
|
|
|
const char *local_ip4)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)local_ip4;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
|
2013-09-07 12:45:50 -04:00
|
|
|
const char *local_ip6)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)local_ip6;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
#endif /* CURLRES_THREADED */
|