diff options
author | Daniel Stenberg <daniel@haxx.se> | 2001-10-04 13:25:12 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2001-10-04 13:25:12 +0000 |
commit | 5d9ae88f58349022ee437fdf4dfc9e3a7f755beb (patch) | |
tree | eaa66a90d9abeb791b72a83f719636fb85266941 /lib/hostip.c | |
parent | 9d066935e5e4e0d7477520eeb6fd7b82ce6bebc2 (diff) |
getaddrinfo() cleanups
Diffstat (limited to 'lib/hostip.c')
-rw-r--r-- | lib/hostip.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index 4fb25bd47..5bea046b5 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. @@ -69,6 +69,58 @@ /* --- resolve name or IP-number --- */ #ifdef ENABLE_IPV6 + +#ifdef MALLOCDEBUG +/* These two 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 struct types I didn't wanna include + * in memdebug.c + */ +int curl_getaddrinfo(char *hostname, char *service, + struct addrinfo *hints, + struct addrinfo **result, + int line, const char *source) +{ + int res=(getaddrinfo)(hostname, service, hints, result); + if(0 == res) + /* success */ + fprintf(logfile?logfile:stderr, "ADDR %s:%d getaddrinfo() = %p\n", + source, line, *result); + else + fprintf(logfile?logfile:stderr, "ADDR %s:%d getaddrinfo() failed\n", + source, line); + return res; +} +void curl_freeaddrinfo(struct addrinfo *freethis, + int line, const char *source) +{ + (freeaddrinfo)(freethis); + fprintf(logfile?logfile:stderr, "ADDR %s:%d freeaddrinfo(%p)\n", + source, line, freethis); +} + +#endif + +/* + * This is a wrapper function for freeing name information in a protocol + * independent way. This takes care of using the appropriate underlaying + * proper function. + */ +void Curl_freeaddrinfo(void *freethis) +{ +#ifdef ENABLE_IPV6 + freeaddrinfo(freethis); +#else + free(freethis); +#endif +} + +/* + * Return 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 meory *MUST* be freed with + * Curl_freeaddrinfo(), nothing else. + */ Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data, char *hostname, int port, @@ -78,8 +130,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data, int error; char sbuf[NI_MAXSERV]; - *bufp=NULL; /* pointer unused with IPv6 */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -87,9 +137,11 @@ Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data, snprintf(sbuf, sizeof(sbuf), "%d", port); error = getaddrinfo(hostname, sbuf, &hints, &res); if (error) { - infof(data, "getaddrinfo(3) failed for %s\n", hostname); + infof(data, "getaddrinfo(3) failed for %s\n", hostname); return NULL; } + *bufp=(char *)res; /* make it point to the result struct */ + return res; } #else /* following code is IPv4-only */ |