Newer
Older
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* 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.
***************************************************************************/
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
#else
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h> /* required for free() prototypes */
#endif
#include <inet.h>
#include <stdlib.h>
#endif
Daniel Stenberg
committed
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
#endif
#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
#undef in_addr_t
#define in_addr_t unsigned long
#endif
#include "hash.h"
Daniel Stenberg
committed
#include "url.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
/* The last #include file should be: */
#ifdef CURLDEBUG
Daniel Stenberg
committed
#ifndef ARES_SUCCESS
#define ARES_SUCCESS CURLE_OK
#endif
#define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
many seconds for a name resolve */
/* These two symbols are for the global DNS cache */
static curl_hash hostname_cache;
static int host_cache_initialized;
static void freednsentry(void *freethis);
/*
* my_getaddrinfo() is the generic low-level name resolve API within this
* source file. There exist three versions of this function - for different
* name resolve layers (selected at build-time). They all take this same set
* of arguments
*/
Daniel Stenberg
committed
static Curl_addrinfo *my_getaddrinfo(struct connectdata *conn,
char *hostname,
int port,
int *waitp);
Daniel Stenberg
committed
#ifndef ENABLE_IPV6
Daniel Stenberg
committed
#if !defined(HAVE_GETHOSTBYNAME_R) || defined(USE_ARES) || \
defined(USE_THREADING_GETHOSTBYNAME)
Daniel Stenberg
committed
static struct hostent* pack_hostent(char** buf, struct hostent* orig);
#endif
Daniel Stenberg
committed
#endif
Daniel Stenberg
committed
#ifdef USE_THREADING_GETHOSTBYNAME
#ifdef DEBUG_THREADING_GETHOSTBYNAME
/* If this is defined, provide tracing */
Daniel Stenberg
committed
#define TRACE(args) \
do { trace_it("%u: ", __LINE__); trace_it args; } while (0)
static void trace_it (const char *fmt, ...);
#else
#define TRACE(x)
#endif
Daniel Stenberg
committed
static struct hostent* pack_hostent (char** buf, struct hostent* orig);
static bool init_gethostbyname_thread (struct connectdata *conn,
const char *hostname, int port);
struct thread_data {
HANDLE thread_hnd;
DWORD thread_id;
DWORD thread_status;
};
#endif
/*
* Curl_global_host_cache_init() initializes and sets up a global DNS cache.
* Global DNS cache is general badness. Do not use. This will be removed in
* a future version. Use the share interface instead!
*/
void Curl_global_host_cache_init(void)
if (!host_cache_initialized) {
Curl_hash_init(&hostname_cache, 7, freednsentry);
host_cache_initialized = 1;
}
/*
* Return a pointer to the global cache
*/
curl_hash *Curl_global_host_cache_get(void)
return &hostname_cache;
/*
* Destroy and cleanup the global DNS cache
*/
void Curl_global_host_cache_dtor(void)
{
if (host_cache_initialized) {
Daniel Stenberg
committed
Curl_hash_clean(&hostname_cache);
host_cache_initialized = 0;
}
}
/*
* Minor utility-function:
* Count the number of characters that an integer takes up.
*/
static int _num_chars(int i)
{
int chars = 0;
/* While the number divided by 10 is greater than one,
* re-divide the number by 10, and increment the number of
* characters by 1.
*
* this relies on the fact that for every multiple of 10,
* a new digit is added onto every number
*/
do {
chars++;
i = (int) i / 10;
} while (i >= 1);
return chars;
}
/*
* Minor utility-function:
* Create a hostcache id string for the DNS caching.
*/
Daniel Stenberg
committed
create_hostcache_id(char *server, int port, size_t *entry_len)
Loading
Loading full blame…