mirror of
https://github.com/moparisthebest/curl
synced 2024-11-10 11:35:07 -05:00
5b6e7927c6
93 lib/*.c source files renamed to use our standard naming scheme. This commit only does the file renaming. ---------------------------------------- renamed: lib/amigaos.c -> lib/curl_amigaos.c renamed: lib/asyn-ares.c -> lib/curl_asyn_ares.c renamed: lib/asyn-thread.c -> lib/curl_asyn_thread.c renamed: lib/axtls.c -> lib/curl_axtls.c renamed: lib/base64.c -> lib/curl_base64.c renamed: lib/bundles.c -> lib/curl_bundles.c renamed: lib/conncache.c -> lib/curl_conncache.c renamed: lib/connect.c -> lib/curl_connect.c renamed: lib/content_encoding.c -> lib/curl_content_encoding.c renamed: lib/cookie.c -> lib/curl_cookie.c renamed: lib/cyassl.c -> lib/curl_cyassl.c renamed: lib/dict.c -> lib/curl_dict.c renamed: lib/easy.c -> lib/curl_easy.c renamed: lib/escape.c -> lib/curl_escape.c renamed: lib/file.c -> lib/curl_file.c renamed: lib/fileinfo.c -> lib/curl_fileinfo.c renamed: lib/formdata.c -> lib/curl_formdata.c renamed: lib/ftp.c -> lib/curl_ftp.c renamed: lib/ftplistparser.c -> lib/curl_ftplistparser.c renamed: lib/getenv.c -> lib/curl_getenv.c renamed: lib/getinfo.c -> lib/curl_getinfo.c renamed: lib/gopher.c -> lib/curl_gopher.c renamed: lib/gtls.c -> lib/curl_gtls.c renamed: lib/hash.c -> lib/curl_hash.c renamed: lib/hmac.c -> lib/curl_hmac.c renamed: lib/hostasyn.c -> lib/curl_hostasyn.c renamed: lib/hostcheck.c -> lib/curl_hostcheck.c renamed: lib/hostip.c -> lib/curl_hostip.c renamed: lib/hostip4.c -> lib/curl_hostip4.c renamed: lib/hostip6.c -> lib/curl_hostip6.c renamed: lib/hostsyn.c -> lib/curl_hostsyn.c renamed: lib/http.c -> lib/curl_http.c renamed: lib/http_chunks.c -> lib/curl_http_chunks.c renamed: lib/http_digest.c -> lib/curl_http_digest.c renamed: lib/http_negotiate.c -> lib/curl_http_negotiate.c renamed: lib/http_negotiate_sspi.c -> lib/curl_http_negotiate_sspi.c renamed: lib/http_proxy.c -> lib/curl_http_proxy.c renamed: lib/idn_win32.c -> lib/curl_idn_win32.c renamed: lib/if2ip.c -> lib/curl_if2ip.c renamed: lib/imap.c -> lib/curl_imap.c renamed: lib/inet_ntop.c -> lib/curl_inet_ntop.c renamed: lib/inet_pton.c -> lib/curl_inet_pton.c renamed: lib/krb4.c -> lib/curl_krb4.c renamed: lib/krb5.c -> lib/curl_krb5.c renamed: lib/ldap.c -> lib/curl_ldap.c renamed: lib/llist.c -> lib/curl_llist.c renamed: lib/md4.c -> lib/curl_md4.c renamed: lib/md5.c -> lib/curl_md5.c renamed: lib/memdebug.c -> lib/curl_memdebug.c renamed: lib/mprintf.c -> lib/curl_mprintf.c renamed: lib/multi.c -> lib/curl_multi.c renamed: lib/netrc.c -> lib/curl_netrc.c renamed: lib/non-ascii.c -> lib/curl_non_ascii.c renamed: lib/curl_non-ascii.h -> lib/curl_non_ascii.h renamed: lib/nonblock.c -> lib/curl_nonblock.c renamed: lib/nss.c -> lib/curl_nss.c renamed: lib/nwlib.c -> lib/curl_nwlib.c renamed: lib/nwos.c -> lib/curl_nwos.c renamed: lib/openldap.c -> lib/curl_openldap.c renamed: lib/parsedate.c -> lib/curl_parsedate.c renamed: lib/pingpong.c -> lib/curl_pingpong.c renamed: lib/polarssl.c -> lib/curl_polarssl.c renamed: lib/pop3.c -> lib/curl_pop3.c renamed: lib/progress.c -> lib/curl_progress.c renamed: lib/qssl.c -> lib/curl_qssl.c renamed: lib/rawstr.c -> lib/curl_rawstr.c renamed: lib/rtsp.c -> lib/curl_rtsp.c renamed: lib/security.c -> lib/curl_security.c renamed: lib/select.c -> lib/curl_select.c renamed: lib/sendf.c -> lib/curl_sendf.c renamed: lib/share.c -> lib/curl_share.c renamed: lib/slist.c -> lib/curl_slist.c renamed: lib/smtp.c -> lib/curl_smtp.c renamed: lib/socks.c -> lib/curl_socks.c renamed: lib/socks_gssapi.c -> lib/curl_socks_gssapi.c renamed: lib/socks_sspi.c -> lib/curl_socks_sspi.c renamed: lib/speedcheck.c -> lib/curl_speedcheck.c renamed: lib/splay.c -> lib/curl_splay.c renamed: lib/ssh.c -> lib/curl_ssh.c renamed: lib/sslgen.c -> lib/curl_sslgen.c renamed: lib/ssluse.c -> lib/curl_ssluse.c renamed: lib/strdup.c -> lib/curl_strdup.c renamed: lib/strequal.c -> lib/curl_strequal.c renamed: lib/strerror.c -> lib/curl_strerror.c renamed: lib/strtok.c -> lib/curl_strtok.c renamed: lib/strtoofft.c -> lib/curl_strtoofft.c renamed: lib/telnet.c -> lib/curl_telnet.c renamed: lib/tftp.c -> lib/curl_tftp.c renamed: lib/timeval.c -> lib/curl_timeval.c renamed: lib/transfer.c -> lib/curl_transfer.c renamed: lib/url.c -> lib/curl_url.c renamed: lib/version.c -> lib/curl_version.c renamed: lib/warnless.c -> lib/curl_warnless.c renamed: lib/wildcard.c -> lib/curl_wildcard.c ----------------------------------------
225 lines
6.3 KiB
C
225 lines
6.3 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) 1998 - 2013, 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.
|
|
*
|
|
***************************************************************************/
|
|
|
|
#include "curl_setup.h"
|
|
|
|
#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
|
|
#ifdef __VMS
|
|
#include <in.h>
|
|
#include <inet.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_PROCESS_H
|
|
#include <process.h>
|
|
#endif
|
|
|
|
#include "curl_urldata.h"
|
|
#include "curl_sendf.h"
|
|
#include "curl_hostip.h"
|
|
#include "curl_hash.h"
|
|
#include "curl_share.h"
|
|
#include "curl_strerror.h"
|
|
#include "curl_url.h"
|
|
#include "curl_inet_pton.h"
|
|
#include "curl_connect.h"
|
|
|
|
#define _MPRINTF_REPLACE /* use our functions only */
|
|
#include <curl/mprintf.h>
|
|
|
|
#include "curl_memory.h"
|
|
/* The last #include file should be: */
|
|
#include "curl_memdebug.h"
|
|
|
|
/***********************************************************************
|
|
* Only for ipv6-enabled builds
|
|
**********************************************************************/
|
|
#ifdef CURLRES_IPV6
|
|
|
|
|
|
#if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
|
|
/* These are strictly for memory tracing and are using the same style as the
|
|
* family otherwise present in curl_memdebug.c. I put these ones here since
|
|
* they require a bunch of structs I didn't want to include there.
|
|
*/
|
|
|
|
/*
|
|
* For CURLRES_ARS, this should be written using ares_gethostbyaddr()
|
|
* (ignoring the fact c-ares doesn't return 'serv').
|
|
*/
|
|
|
|
int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
|
|
GETNAMEINFO_TYPE_ARG2 salen,
|
|
char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
|
|
char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
|
|
GETNAMEINFO_TYPE_ARG7 flags,
|
|
int line, const char *source)
|
|
{
|
|
int res = (getnameinfo)(sa, salen,
|
|
host, hostlen,
|
|
serv, servlen,
|
|
flags);
|
|
if(0 == res)
|
|
/* success */
|
|
curl_memlog("GETNAME %s:%d getnameinfo()\n",
|
|
source, line);
|
|
else
|
|
curl_memlog("GETNAME %s:%d getnameinfo() failed = %d\n",
|
|
source, line, res);
|
|
return res;
|
|
}
|
|
#endif /* defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO) */
|
|
|
|
/*
|
|
* Curl_ipv6works() returns TRUE if ipv6 seems to work.
|
|
*/
|
|
bool Curl_ipv6works(void)
|
|
{
|
|
/* the nature of most system is that IPv6 status doesn't come and go
|
|
during a program's lifetime so we only probe the first time and then we
|
|
have the info kept for fast re-use */
|
|
static int ipv6_works = -1;
|
|
if(-1 == ipv6_works) {
|
|
/* probe to see if we have a working IPv6 stack */
|
|
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
|
|
if(s == CURL_SOCKET_BAD)
|
|
/* an ipv6 address was requested but we can't get/use one */
|
|
ipv6_works = 0;
|
|
else {
|
|
ipv6_works = 1;
|
|
Curl_closesocket(NULL, s);
|
|
}
|
|
}
|
|
return (ipv6_works>0)?TRUE:FALSE;
|
|
}
|
|
|
|
/*
|
|
* Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
|
|
* been set and returns TRUE if they are OK.
|
|
*/
|
|
bool Curl_ipvalid(struct connectdata *conn)
|
|
{
|
|
if(conn->ip_version == CURL_IPRESOLVE_V6)
|
|
return Curl_ipv6works();
|
|
return TRUE;
|
|
}
|
|
|
|
#if defined(CURLRES_SYNCH)
|
|
|
|
#ifdef DEBUG_ADDRINFO
|
|
static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
|
|
{
|
|
printf("dump_addrinfo:\n");
|
|
for(; ai; ai = ai->ai_next) {
|
|
char buf[INET6_ADDRSTRLEN];
|
|
|
|
printf(" fam %2d, CNAME %s, ",
|
|
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
|
|
if(Curl_printable_address(ai, buf, sizeof(buf)))
|
|
printf("%s\n", buf);
|
|
else
|
|
printf("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
|
|
}
|
|
}
|
|
#else
|
|
#define dump_addrinfo(x,y) Curl_nop_stmt
|
|
#endif
|
|
|
|
/*
|
|
* Curl_getaddrinfo() when built ipv6-enabled (non-threading and
|
|
* non-ares version).
|
|
*
|
|
* Returns name information about the given hostname and port number. If
|
|
* successful, the 'addrinfo' is returned and the forth argument will point to
|
|
* memory we need to free after use. That memory *MUST* be freed with
|
|
* Curl_freeaddrinfo(), nothing else.
|
|
*/
|
|
Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
|
const char *hostname,
|
|
int port,
|
|
int *waitp)
|
|
{
|
|
struct addrinfo hints;
|
|
Curl_addrinfo *res;
|
|
int error;
|
|
char sbuf[NI_MAXSERV];
|
|
char *sbufptr = NULL;
|
|
char addrbuf[128];
|
|
int pf;
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
*waitp = 0; /* synchronous response only */
|
|
|
|
/*
|
|
* Check if a limited name resolve has been requested.
|
|
*/
|
|
switch(conn->ip_version) {
|
|
case CURL_IPRESOLVE_V4:
|
|
pf = PF_INET;
|
|
break;
|
|
case CURL_IPRESOLVE_V6:
|
|
pf = PF_INET6;
|
|
break;
|
|
default:
|
|
pf = PF_UNSPEC;
|
|
break;
|
|
}
|
|
|
|
if((pf != PF_INET) && !Curl_ipv6works())
|
|
/* the stack seems to be a non-ipv6 one */
|
|
pf = PF_INET;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
hints.ai_family = pf;
|
|
hints.ai_socktype = conn->socktype;
|
|
|
|
if((1 == Curl_inet_pton(AF_INET, hostname, addrbuf)) ||
|
|
(1 == Curl_inet_pton(AF_INET6, hostname, addrbuf))) {
|
|
/* the given address is numerical only, prevent a reverse lookup */
|
|
hints.ai_flags = AI_NUMERICHOST;
|
|
}
|
|
|
|
if(port) {
|
|
snprintf(sbuf, sizeof(sbuf), "%d", port);
|
|
sbufptr=sbuf;
|
|
}
|
|
error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &res);
|
|
if(error) {
|
|
infof(data, "getaddrinfo(3) failed for %s:%d\n", hostname, port);
|
|
return NULL;
|
|
}
|
|
|
|
dump_addrinfo(conn, res);
|
|
|
|
return res;
|
|
}
|
|
#endif /* CURLRES_SYNCH */
|
|
#endif /* CURLRES_IPV6 */
|
|
|