diff --git a/CHANGES b/CHANGES index 42317ac85..99f5ee58e 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,9 @@ Changelog Daniel (29 January 2005) +- Adjusted the KNOWN_BUGS #17 fix a bit more since the FTP code also did some + bad assumptions. + - multi interface: when a request is denied due to "Maximum redirects followed" libcurl leaked the last Location: URL. diff --git a/lib/connect.c b/lib/connect.c index 5cd4c0656..104be2d42 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -429,6 +429,25 @@ static bool verifyconnect(curl_socket_t sockfd, int *error) return rc; } +CURLcode Curl_store_ip_addr(struct connectdata *conn) +{ + char addrbuf[256]; + Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf)); + + /* save the string */ + Curl_safefree(conn->ip_addr_str); + conn->ip_addr_str = strdup(addrbuf); + if(!conn->ip_addr_str) + return CURLE_OUT_OF_MEMORY; /* FAIL */ + +#ifdef PF_INET6 + if(conn->ip_addr->ai_family == PF_INET6) + conn->bits.ipv6 = TRUE; +#endif + + return CURLE_OK; +} + /* Used within the multi interface. Try next IP address, return TRUE if no more address exists */ static bool trynextip(struct connectdata *conn, @@ -450,6 +469,8 @@ static bool trynextip(struct connectdata *conn, /* store the new socket descriptor */ conn->sock[sockindex] = sockfd; conn->ip_addr = ai; + + Curl_store_ip_addr(conn); return FALSE; } ai = ai->ai_next; diff --git a/lib/connect.h b/lib/connect.h index d39495cfc..50a9e3464 100644 --- a/lib/connect.h +++ b/lib/connect.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -39,6 +39,8 @@ CURLcode Curl_connecthost(struct connectdata *conn, int Curl_ourerrno(void); +CURLcode Curl_store_ip_addr(struct connectdata *conn); + #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */ #endif diff --git a/lib/ftp.c b/lib/ftp.c index e5ad8bde1..e6d2cdfae 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -1226,12 +1226,10 @@ CURLcode ftp_use_port(struct connectdata *conn) } #ifdef PF_INET6 - if(!conn->bits.ftp_use_eprt && - (conn->ip_addr->ai_family == PF_INET6)) { + if(!conn->bits.ftp_use_eprt && conn->bits.ipv6) /* EPRT is disabled but we are connected to a IPv6 host, so we ignore the - request! */ + request and enable EPRT again! */ conn->bits.ftp_use_eprt = TRUE; - } #endif for (fcmd = EPRT; fcmd != DONE; fcmd++) { @@ -1563,12 +1561,10 @@ CURLcode ftp_use_pasv(struct connectdata *conn, char newhost[NEWHOST_BUFSIZE]; #ifdef PF_INET6 - if(!conn->bits.ftp_use_epsv && - (conn->ip_addr->ai_family == PF_INET6)) { + if(!conn->bits.ftp_use_epsv && conn->bits.ipv6) /* EPSV is disabled but we are connected to a IPv6 host, so we ignore the - request! */ + request and enable EPSV again! */ conn->bits.ftp_use_epsv = TRUE; - } #endif for (modeoff = (conn->bits.ftp_use_epsv?0:1); @@ -1653,7 +1649,7 @@ CURLcode ftp_use_pasv(struct connectdata *conn, newport = num; /* We must use the same IP we are already connected to */ - Curl_printable_address(conn->ip_addr, newhost, NEWHOST_BUFSIZE); + snprintf(newhost, NEWHOST_BUFSIZE, "%s", conn->ip_addr_str); } } else diff --git a/lib/url.c b/lib/url.c index c8c4360be..de6d4c2c9 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1959,6 +1959,8 @@ static CURLcode ConnectPlease(struct connectdata *conn, conn->dns_entry = hostaddr; conn->ip_addr = addr; + Curl_store_ip_addr(conn); + if (conn->data->set.proxytype == CURLPROXY_SOCKS5) { return handleSock5Proxy(conn->proxyuser, conn->proxypasswd, @@ -1982,24 +1984,7 @@ static CURLcode ConnectPlease(struct connectdata *conn, */ static void verboseconnect(struct connectdata *conn) { - struct SessionHandle *data = conn->data; - char addrbuf[256]; - - /* Get a printable version of the network address. */ - if(!conn->bits.reuse) { - Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf)); - - /* save the string */ - if(conn->ip_addr_str) - free(conn->ip_addr_str); - conn->ip_addr_str = strdup(addrbuf); - if(!conn->ip_addr_str) - return; /* FAIL */ - } - /* else, - Re-used, ip_addr is not safe to access. */ - - infof(data, "Connected to %s (%s) port %d\n", + infof(conn->data, "Connected to %s (%s) port %d\n", conn->bits.httpproxy ? conn->proxy.dispname : conn->host.dispname, conn->ip_addr_str, conn->port); } diff --git a/lib/urldata.h b/lib/urldata.h index c51ccf303..2068c9a70 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -293,8 +293,9 @@ struct ConnectBits { bool httpproxy; /* if set, this transfer is done through a http proxy */ bool user_passwd; /* do we use user+password for this connection? */ bool proxy_user_passwd; /* user+password for the proxy? */ - bool ipv6_ip; /* we communicate with a remove site specified with pure IPv6 + bool ipv6_ip; /* we communicate with a remote site specified with pure IPv6 IP address */ + bool ipv6; /* we communicate with a site using an IPv6 address */ bool use_range; bool rangestringalloc; /* the range string is malloc()'ed */ @@ -462,8 +463,8 @@ struct connectdata { /* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string. It remains available as long as the connection does, which is longer than - the ip_addr itself. Currently, this is only set (and used) in - url.c:verboseconnect(). */ + the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been + set. */ char *ip_addr_str; char protostr[16]; /* store the protocol string in this buffer */