Skip to content

Commit

Permalink
Move curl_dofreeaddrinfo() and curl_dofreeaddrinfo()
Browse files Browse the repository at this point in the history
implementation from lib/hostip6.c to lib/curl_addrinfo.c
and prototypes from lib/hostip.h to lib/curl_addrinfo.h
  • Loading branch information
yangtse committed Oct 30, 2008
1 parent 625c107 commit c2c800d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 42 deletions.
54 changes: 54 additions & 0 deletions lib/curl_addrinfo.c
Expand Up @@ -329,3 +329,57 @@ Curl_he2ai(const struct hostent *he, int port)
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) */

16 changes: 16 additions & 0 deletions lib/curl_addrinfo.h
Expand Up @@ -78,4 +78,20 @@ Curl_getaddrinfo_ex(const char *nodename,
Curl_addrinfo *
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 */
10 changes: 1 addition & 9 deletions lib/hostip.h
Expand Up @@ -197,22 +197,14 @@ void Curl_hostcache_prune(struct SessionHandle *data);
/* Return # of adresses in a Curl_addrinfo struct */
int Curl_num_addresses (const Curl_addrinfo *addr);

#ifdef CURLDEBUG
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
#if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
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);
#endif
#endif

/* This is the callback function that is used when we build with asynch
resolve, ipv4 */
Expand Down
35 changes: 3 additions & 32 deletions lib/hostip6.c
Expand Up @@ -93,36 +93,17 @@ Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port)
#endif /* CURLRES_ASYNCH */
#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
* 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,
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()
* (ignoring the fact c-ares doesn't return 'serv').
*/
#ifdef HAVE_GETNAMEINFO

int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
GETNAMEINFO_TYPE_ARG2 salen,
char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
Expand All @@ -147,17 +128,7 @@ int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
}
return res;
}
#endif

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 */
#endif /* defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO) */

/*
* Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
Expand Down
6 changes: 5 additions & 1 deletion lib/memdebug.h
Expand Up @@ -89,6 +89,7 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#define accept(sock,addr,len)\
curl_accept(sock,addr,len,__LINE__,__FILE__)

#ifdef HAVE_GETADDRINFO
#if defined(getaddrinfo) && defined(__osf__)
/* 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
Expand All @@ -100,17 +101,20 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#define getaddrinfo(host,serv,hint,res) \
curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
#endif
#endif /* HAVE_GETADDRINFO */

#ifdef HAVE_GETNAMEINFO
#undef getnameinfo
#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
__FILE__)
#endif
#endif /* HAVE_GETNAMEINFO */

#ifdef HAVE_FREEADDRINFO
#undef freeaddrinfo
#define freeaddrinfo(data) \
curl_dofreeaddrinfo(data,__LINE__,__FILE__)
#endif /* HAVE_FREEADDRINFO */

/* sclose is probably already defined, redefine it! */
#undef sclose
Expand Down

0 comments on commit c2c800d

Please sign in to comment.