diff options
-rw-r--r-- | lib/hostares.c | 48 | ||||
-rw-r--r-- | lib/hostip4.c | 14 | ||||
-rw-r--r-- | lib/hostip6.c | 7 | ||||
-rw-r--r-- | lib/setup.h | 12 |
4 files changed, 63 insertions, 18 deletions
diff --git a/lib/hostares.c b/lib/hostares.c index 646af5839..f08ad5859 100644 --- a/lib/hostares.c +++ b/lib/hostares.c @@ -293,4 +293,52 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, return NULL; /* no struct yet */ } +#if !defined(CURLRES_IPV4) +/* + * The rest of this file is copied from hostip4.c. (needed for the + * combination USE_ARES and ENABLE_IPV6). + */ +struct namebuf { + struct hostent hostentry; + char *h_addr_list[2]; + struct in_addr addrentry; + char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */ +}; + +/* + * Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter + * together with a pointer to the string version of the address, and it + * returns a Curl_addrinfo chain filled in correctly with information for this + * address/host. + * + * The input parameters ARE NOT checked for validity but they are expected + * to have been checked already when this is called. + */ +Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) +{ + Curl_addrinfo *ai; + struct hostent *h; + struct in_addr *addrentry; + struct namebuf buffer; + struct namebuf *buf = &buffer; + + h = &buf->hostentry; + h->h_addr_list = &buf->h_addr_list[0]; + addrentry = &buf->addrentry; + addrentry->s_addr = num; + h->h_addr_list[0] = (char*)addrentry; + h->h_addr_list[1] = NULL; + h->h_addrtype = AF_INET; + h->h_length = sizeof(*addrentry); + h->h_name = &buf->h_name[0]; + h->h_aliases = NULL; + + /* Now store the dotted version of the address */ + snprintf((char *)h->h_name, 16, "%s", hostname); + + ai = Curl_he2ai(h, port); + + return ai; +} +#endif /* !CURLRES_IPV4 */ #endif /* CURLRES_ARES */ diff --git a/lib/hostip4.c b/lib/hostip4.c index bba9fb1dc..e55eb38d8 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -365,14 +365,15 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, } #endif /* CURLRES_SYNCH */ +#endif /* CURLRES_IPV4 */ /* * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct. * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6 * stacks, but for all hosts and environments. - * + * * Curl_addrinfo defined in "lib/hostip.h" - * + * * struct Curl_addrinfo { * int ai_flags; * int ai_family; @@ -383,9 +384,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * struct sockaddr *ai_addr; * struct Curl_addrinfo *ai_next; * }; - * + * * hostent defined in <netdb.h> - * + * * struct hostent { * char *h_name; * char **h_aliases; @@ -393,9 +394,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * int h_length; * char **h_addr_list; * }; - * + * * for backward compatibility: - * + * * #define h_addr h_addr_list[0] */ @@ -451,4 +452,3 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) return firstai; } -#endif /* CURLRES_IPV4 */ diff --git a/lib/hostip6.c b/lib/hostip6.c index 55be255e7..b013ee902 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -191,7 +191,7 @@ bool Curl_ipvalid(struct SessionHandle *data) return TRUE; } -#ifndef USE_THREADING_GETADDRINFO +#if !defined(USE_THREADING_GETADDRINFO) && !defined(USE_ARES) #ifdef DEBUG_ADDRINFO static void dump_addrinfo(struct connectdata *conn, const struct addrinfo *ai) @@ -213,7 +213,8 @@ static void dump_addrinfo(struct connectdata *conn, const struct addrinfo *ai) #endif /* - * Curl_getaddrinfo() when built ipv6-enabled (non-threading version). + * 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 @@ -295,6 +296,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, return res; } -#endif /* USE_THREADING_GETADDRINFO */ +#endif /* !USE_THREADING_GETADDRINFO && !USE_ARES */ #endif /* ipv6 */ diff --git a/lib/setup.h b/lib/setup.h index f89c82e5f..6e221a136 100644 --- a/lib/setup.h +++ b/lib/setup.h @@ -216,7 +216,7 @@ typedef unsigned char bool; /* * The definitions for the return type and arguments types - * of functions recv() and send() belong and come from the + * of functions recv() and send() belong and come from the * configuration file. Do not define them in any other place. * * HAVE_RECV is defined if you have a function named recv() @@ -232,7 +232,7 @@ typedef unsigned char bool; * If yours has another name then don't define HAVE_SEND. * * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, - * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and + * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and * SEND_TYPE_RETV must also be defined. */ @@ -251,7 +251,7 @@ typedef unsigned char bool; #else /* HAVE_RECV */ #ifdef DJGPP #define sread(x,y,z) (ssize_t)read_s((int)(x), (char *)(y), (int)(z)) -#endif +#endif #endif /* HAVE_RECV */ #ifdef HAVE_SEND @@ -270,7 +270,7 @@ typedef unsigned char bool; #else /* HAVE_SEND */ #ifdef DJGPP #define swrite(x,y,z) (ssize_t)write_s((int)(x), (char *)(y), (int)(z)) -#endif +#endif #endif /* HAVE_SEND */ @@ -358,10 +358,6 @@ typedef int curl_socket_t; #endif /* curl_socket_typedef */ -#if defined(ENABLE_IPV6) && defined(USE_ARES) -#error "ares does not yet support IPv6. Disable IPv6 or ares and rebuild" -#endif - #if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \ !defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */ #ifdef ENABLE_IPV6 |