summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-09-11 10:32:37 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-09-11 10:32:37 +0000
commitcac5251a98165bf5b6069f5276fd9d1d7331a11a (patch)
tree229a2a8beca08e2d5fffcff08f7a4a9d9827ccf6
parent3b825bcbfbd7553a58a506ecc3d08a941feb8081 (diff)
downloadgnurl-cac5251a98165bf5b6069f5276fd9d1d7331a11a.tar.gz
gnurl-cac5251a98165bf5b6069f5276fd9d1d7331a11a.tar.bz2
gnurl-cac5251a98165bf5b6069f5276fd9d1d7331a11a.zip
Lukasz Czekierda correctly pointed out that curl used a bad Host: header
when talking to a IPv6-server using IPv6 IP address only.
-rw-r--r--lib/connect.c6
-rw-r--r--lib/http.c13
-rw-r--r--lib/url.c2
-rw-r--r--lib/urldata.h3
4 files changed, 20 insertions, 4 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 0272f2e82..203253500 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -463,7 +463,11 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
}
hostname = data->change.proxy?conn->proxyhost:conn->hostname;
- infof(data, "About to connect() to %s:%d\n", hostname, port);
+ infof(data, "About to connect() to %s%s%s:%d\n",
+ conn->bits.ipv6_ip?"[":"",
+ hostname,
+ conn->bits.ipv6_ip?"]":"",
+ port);
#ifdef ENABLE_IPV6
/*
diff --git a/lib/http.c b/lib/http.c
index 788309d76..6a71e47b1 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -581,13 +581,22 @@ CURLcode Curl_http(struct connectdata *conn)
if(conn->allocptr.host)
free(conn->allocptr.host);
+ /* When building Host: headers, we must put the host name within
+ [brackets] if the host name is a plain IPv6-address. RFC2732-style. */
+
if(((conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTPS)) ||
(!(conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTP)) )
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
the port number in the host string */
- conn->allocptr.host = aprintf("Host: %s\r\n", host);
+ conn->allocptr.host = aprintf("Host: %s%s%s\r\n",
+ conn->bits.ipv6_ip?"[":"",
+ host,
+ conn->bits.ipv6_ip?"]":"");
else
- conn->allocptr.host = aprintf("Host: %s:%d\r\n", host,
+ conn->allocptr.host = aprintf("Host: %s%s%s:%d\r\n",
+ conn->bits.ipv6_ip?"[":"",
+ host,
+ conn->bits.ipv6_ip?"]":"",
conn->remote_port);
}
diff --git a/lib/url.c b/lib/url.c
index ee4c7729d..394d3d0c9 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2279,8 +2279,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
if((1 == sscanf(conn->name, "[%*39[0-9a-fA-F:.]%c", &endbracket)) &&
(']' == endbracket)) {
/* this is a RFC2732-style specified IP-address */
+ conn->bits.ipv6_ip = TRUE;
conn->name++; /* pass the starting bracket */
+ conn->hostname++;
tmp = strchr(conn->name, ']');
*tmp = 0; /* zero terminate */
tmp++; /* pass the ending bracket */
diff --git a/lib/urldata.h b/lib/urldata.h
index 233abcef6..6d3f9ce73 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -210,7 +210,8 @@ 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
+ IP address */
bool use_range;
bool rangestringalloc; /* the range string is malloc()'ed */
};