diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-06-10 11:06:21 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-06-10 11:06:21 +0000 |
commit | 9f341f9ce5ff2cc85a4cbdd38cd4b5c68b02504d (patch) | |
tree | 6e6c97746450dee34253768bfbba72039fd04d4c /lib/hostip.c | |
parent | 20988715093810cde488cabe2b9f52fe5b300450 (diff) | |
download | curl-9f341f9ce5ff2cc85a4cbdd38cd4b5c68b02504d.tar.gz |
Gisle Vanem's improved verbose output and timeout handling when connecting to
a host name that resolves to multiple IP addresses.
Diffstat (limited to 'lib/hostip.c')
-rw-r--r-- | lib/hostip.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index ffc8198ea..2a0367795 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -79,6 +79,7 @@ #include "share.h" #include "strerror.h" #include "url.h" +#include "inet_ntop.h" #define _MPRINTF_REPLACE /* use our functions only */ #include <curl/mprintf.h> @@ -168,6 +169,43 @@ void Curl_global_host_cache_dtor(void) } /* + * Return # of adresses in a Curl_addrinfo struct + */ +int Curl_num_addresses(const Curl_addrinfo *addr) +{ + int i; + +#ifdef ENABLE_IPV6 + for (i = 0; addr; addr = addr->ai_next, i++) +#else + for (i = 0; addr->h_addr_list[i]; i++) +#endif + ; + return (i); +} + +/* + * Curl_printable_address() returns a printable version of the 1st + * address given in the 2nd argument. The result will be stored in + * the buf that is bufsize bytes big. + * + * If the conversion fails, it returns NULL. + */ +const char *Curl_printable_address(const Curl_ipconnect *ip, + char *buf, size_t bufsize) +{ +#ifdef CURLRES_IPV6 + const void *ip4 = &((const struct sockaddr_in*)ip->ai_addr)->sin_addr; + const void *ip6 = &((const struct sockaddr_in6*)ip->ai_addr)->sin6_addr; + int af = ip->ai_family; + + return Curl_inet_ntop(af, af == AF_INET6 ? ip6 : ip4, buf, bufsize); +#else + return Curl_inet_ntop(AF_INET, ip, buf, bufsize); +#endif +} + +/* * Count the number of characters that an integer would use in a string * (base 10). */ |