1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Move curl_dofreeaddrinfo() and curl_dofreeaddrinfo()

implementation from lib/hostip6.c to lib/curl_addrinfo.c
and prototypes from lib/hostip.h to lib/curl_addrinfo.h
This commit is contained in:
Yang Tse 2008-10-30 19:02:23 +00:00
parent 625c107c25
commit c2c800d863
5 changed files with 79 additions and 42 deletions

View File

@ -329,3 +329,57 @@ Curl_he2ai(const struct hostent *he, int port)
return firstai; return firstai;
} }
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
/*
* curl_dofreeaddrinfo()
*
* This is Strictly for memory tracing and are using the same style as the
* family otherwise present in memdebug.c. I put these ones here since they
* require a bunch of structs I didn't wanna include in memdebug.c
*/
void
curl_dofreeaddrinfo(struct addrinfo *freethis,
int line, const char *source)
{
(freeaddrinfo)(freethis);
if(logfile)
fprintf(logfile, "ADDR %s:%d freeaddrinfo(%p)\n",
source, line, (void *)freethis);
}
#endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
/*
* curl_dogetaddrinfo()
*
* This is Strictly for memory tracing and are using the same style as the
* family otherwise present in memdebug.c. I put these ones here since they
* require a bunch of structs I didn't wanna include in memdebug.c
*/
int
curl_dogetaddrinfo(const char *hostname,
const char *service,
const struct addrinfo *hints,
struct addrinfo **result,
int line, const char *source)
{
int res=(getaddrinfo)(hostname, service, hints, result);
if(0 == res) {
/* success */
if(logfile)
fprintf(logfile, "ADDR %s:%d getaddrinfo() = %p\n",
source, line, (void *)*result);
}
else {
if(logfile)
fprintf(logfile, "ADDR %s:%d getaddrinfo() failed\n",
source, line);
}
return res;
}
#endif /* defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) */

View File

@ -78,4 +78,20 @@ Curl_getaddrinfo_ex(const char *nodename,
Curl_addrinfo * Curl_addrinfo *
Curl_he2ai(const struct hostent *he, int port); Curl_he2ai(const struct hostent *he, int port);
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
void
curl_dofreeaddrinfo(struct addrinfo *freethis,
int line, const char *source);
#endif
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
int
curl_dogetaddrinfo(const char *hostname,
const char *service,
const struct addrinfo *hints,
struct addrinfo **result,
int line, const char *source);
#endif
#endif /* HEADER_CURL_ADDRINFO_H */ #endif /* HEADER_CURL_ADDRINFO_H */

View File

@ -197,14 +197,7 @@ void Curl_hostcache_prune(struct SessionHandle *data);
/* Return # of adresses in a Curl_addrinfo struct */ /* Return # of adresses in a Curl_addrinfo struct */
int Curl_num_addresses (const Curl_addrinfo *addr); int Curl_num_addresses (const Curl_addrinfo *addr);
#ifdef CURLDEBUG #if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
void curl_dofreeaddrinfo(struct addrinfo *freethis,
int line, const char *source);
int curl_dogetaddrinfo(const char *hostname, const char *service,
struct addrinfo *hints,
struct addrinfo **result,
int line, const char *source);
#ifdef HAVE_GETNAMEINFO
int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa, int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
GETNAMEINFO_TYPE_ARG2 salen, GETNAMEINFO_TYPE_ARG2 salen,
char *host, GETNAMEINFO_TYPE_ARG46 hostlen, char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
@ -212,7 +205,6 @@ int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
GETNAMEINFO_TYPE_ARG7 flags, GETNAMEINFO_TYPE_ARG7 flags,
int line, const char *source); int line, const char *source);
#endif #endif
#endif
/* This is the callback function that is used when we build with asynch /* This is the callback function that is used when we build with asynch
resolve, ipv4 */ resolve, ipv4 */

View File

@ -93,36 +93,17 @@ Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port)
#endif /* CURLRES_ASYNCH */ #endif /* CURLRES_ASYNCH */
#endif /* CURLRES_ARES */ #endif /* CURLRES_ARES */
#ifdef CURLDEBUG #if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
/* These are strictly for memory tracing and are using the same style as the /* These are strictly for memory tracing and are using the same style as the
* family otherwise present in memdebug.c. I put these ones here since they * family otherwise present in memdebug.c. I put these ones here since they
* require a bunch of structs I didn't wanna include in memdebug.c * require a bunch of structs I didn't wanna include in memdebug.c
*/ */
int curl_dogetaddrinfo(const char *hostname, const char *service,
struct addrinfo *hints,
struct addrinfo **result,
int line, const char *source)
{
int res=(getaddrinfo)(hostname, service, hints, result);
if(0 == res) {
/* success */
if(logfile)
fprintf(logfile, "ADDR %s:%d getaddrinfo() = %p\n",
source, line, (void *)*result);
}
else {
if(logfile)
fprintf(logfile, "ADDR %s:%d getaddrinfo() failed\n",
source, line);
}
return res;
}
/* /*
* For CURLRES_ARS, this should be written using ares_gethostbyaddr() * For CURLRES_ARS, this should be written using ares_gethostbyaddr()
* (ignoring the fact c-ares doesn't return 'serv'). * (ignoring the fact c-ares doesn't return 'serv').
*/ */
#ifdef HAVE_GETNAMEINFO
int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa, int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
GETNAMEINFO_TYPE_ARG2 salen, GETNAMEINFO_TYPE_ARG2 salen,
char *host, GETNAMEINFO_TYPE_ARG46 hostlen, char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
@ -147,17 +128,7 @@ int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
} }
return res; return res;
} }
#endif #endif /* defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO) */
void curl_dofreeaddrinfo(struct addrinfo *freethis,
int line, const char *source)
{
(freeaddrinfo)(freethis);
if(logfile)
fprintf(logfile, "ADDR %s:%d freeaddrinfo(%p)\n",
source, line, (void *)freethis);
}
#endif /* CURLDEBUG */
/* /*
* Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've

View File

@ -89,6 +89,7 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#define accept(sock,addr,len)\ #define accept(sock,addr,len)\
curl_accept(sock,addr,len,__LINE__,__FILE__) curl_accept(sock,addr,len,__LINE__,__FILE__)
#ifdef HAVE_GETADDRINFO
#if defined(getaddrinfo) && defined(__osf__) #if defined(getaddrinfo) && defined(__osf__)
/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define /* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
our macro as for other platforms. Instead, we redefine the new name they our macro as for other platforms. Instead, we redefine the new name they
@ -100,17 +101,20 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#define getaddrinfo(host,serv,hint,res) \ #define getaddrinfo(host,serv,hint,res) \
curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__) curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
#endif #endif
#endif /* HAVE_GETADDRINFO */
#ifdef HAVE_GETNAMEINFO #ifdef HAVE_GETNAMEINFO
#undef getnameinfo #undef getnameinfo
#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \ #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \ curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
__FILE__) __FILE__)
#endif #endif /* HAVE_GETNAMEINFO */
#ifdef HAVE_FREEADDRINFO
#undef freeaddrinfo #undef freeaddrinfo
#define freeaddrinfo(data) \ #define freeaddrinfo(data) \
curl_dofreeaddrinfo(data,__LINE__,__FILE__) curl_dofreeaddrinfo(data,__LINE__,__FILE__)
#endif /* HAVE_FREEADDRINFO */
/* sclose is probably already defined, redefine it! */ /* sclose is probably already defined, redefine it! */
#undef sclose #undef sclose