Skip to content

Commit

Permalink
Enabled support for IPv6-style IP-addresses if ENABLE_IPV6 is set. If…
Browse files Browse the repository at this point in the history
… it isn't,

curl will return an error when such an address is used.
  • Loading branch information
bagder committed Jan 23, 2001
1 parent 210aa43 commit 7872cc1
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions lib/url.c
Expand Up @@ -635,6 +635,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
char resumerange[40]="";
struct UrlData *data = curl;
struct connectdata *conn;
char endbracket;
#ifdef HAVE_SIGACTION
struct sigaction sigact;
#endif
Expand Down Expand Up @@ -1146,15 +1147,40 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
}
}

/* No matter if we use a proxy or not, we have to figure out the remote
port number of various reasons.
To be able to detect port number flawlessly, we must not confuse them
IPv6-specified addresses in the [0::1] style.
*/
if((1 == sscanf(conn->name, "[%*39[0-9a-fA-F:]%c", &endbracket)) &&
(']' == endbracket)) {
/* this is a IPv6-style specified IP-address */
#ifndef ENABLE_IPV6
failf(data, "You haven't enabled IPv6 support");
return CURLE_URL_MALFORMAT;
#else
tmp = strchr(conn->name, ']');

tmp++; /* pass the ending bracket */
if(':' != *tmp)
tmp = NULL; /* no port number available */
#endif
}
else {
/* traditional IPv4-style port-extracting */
tmp = strchr(conn->name, ':');
}

if (tmp) {
*tmp++ = '\0'; /* cut off the name there */
data->remote_port = atoi(tmp);
}

if(!data->bits.httpproxy) {
/* If not connecting via a proxy, extract the port from the URL, if it is
* there, thus overriding any defaults that might have been set above. */
tmp = strchr(conn->name, ':');
if (tmp) {
*tmp++ = '\0';
data->port = atoi(tmp);
}
data->remote_port = data->port; /* it is the same port */
data->port = data->remote_port; /* it is the same port */

/* Connect to target host right on */
conn->hp = Curl_gethost(data, conn->name, &conn->hostent_buf);
Expand All @@ -1179,14 +1205,6 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
return CURLE_OUT_OF_MEMORY;
}

/* we use proxy all right, but we wanna know the remote port for SSL
reasons */
tmp = strchr(conn->name, ':');
if (tmp) {
*tmp++ = '\0'; /* cut off the name there */
data->remote_port = atoi(tmp);
}

/* Daniel Dec 10, 1998:
We do the proxy host string parsing here. We want the host name and the
port name. Accept a protocol:// prefix, even though it should just be
Expand Down

0 comments on commit 7872cc1

Please sign in to comment.