cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_SCOPE

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 30 Jul 2008 19:18:12 -0700

On Thu, Jul 10, 2008 at 09:30:45AM +0100, Phil Blundell wrote:
> By way of rationale, consider the following case:
>
> Client requests http://[fe80::1234%251]/index.htm
>
> Server wants to redirect this to another host on the same link:
>
> Location: http://[fe80::4321]/index.htm
>
> But, the server doesn't have any way of knowing what interface index the
> client needs to use to access this link-local scope. (It could perhaps
> infer it from the Host header if the scope were included there, but the
> MS scope-stripping behaviour that Yang Tse mentions would make this
> impossible.) So, the only useful behaviour would seem to be for the
> client to figure out the intended scope for itself based on its
> knowledge of where the original server is located.

The patch that just went in implements almost the right behaviour in this
case. When the server responds with a Location header including a scope,
such as:

Location: http://[fe80::1234%25111]/

the host address used by curl is actually the literal "fe80::1234%25111".
This is because the line:

  if (conn->host.name[0] == '[' && !data->state.this_is_a_follow) {

refuses to set the scope (as it should for a redirect), but doesn't
remove the scope from the URL.

Also, the removal of the scope from the host name also removed any port
number that may have also been in the URL.

I've checked in this fix which solves both problems:

retrieving revision 1.721
diff -u -r1.721 url.c
--- lib/url.c 30 Jul 2008 21:55:27 -0000 1.721
+++ lib/url.c 31 Jul 2008 02:13:29 -0000
@@ -3089,16 +3089,19 @@
     path[0] = '/';
   }
 
- if (conn->host.name[0] == '[' && !data->state.this_is_a_follow) {
+ if (conn->host.name[0] == '[') {
     /* This looks like an IPv6 address literal. See if there is an address
        scope. */
     char *percent = strstr (conn->host.name, "%25");
     if (percent) {
       char *endp;
- conn->scope = strtoul (percent + 3, &endp, 10);
+ unsigned int scope = strtoul (percent + 3, &endp, 10);
       if (*endp == ']') {
         /* The address scope was well formed. Knock it out of the hostname. */
- strcpy (percent, "]");
+ memmove(percent, endp, strlen(endp)+1);
+ if (!data->state.this_is_a_follow)
+ /* Don't honour a scope given in a Location: header */
+ conn->scope = scope;
       }
     }
   }

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2008-07-31