cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH 01/10] parseurlandfillconn: Handle named zone identifiers

From: Till Maas <opensource_at_till.name>
Date: Sat, 15 Mar 2014 19:41:25 +0100

Support URLs like http://[fe80::1%eth0].

---
 lib/url.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/lib/url.c b/lib/url.c
index 2240f11..ee888d2 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3965,8 +3965,36 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
           /* Don't honour a scope given in a Location: header */
           conn->scope = (unsigned int)scope;
       }
-      else
-        infof(data, "Invalid IPv6 address format\n");
+      else {
+#ifdef HAVE_NET_IF_H
+        char ifname[IFNAMSIZ + 2];
+        size_t square_bracket;
+        unsigned int scope = 0;
+        strncpy(ifname, percent + 3, IFNAMSIZ + 2);
+        /* Ensure nullbyte termination */
+        ifname[IFNAMSIZ + 1] = '\0';
+        square_bracket = strcspn(ifname, "]");
+        if (square_bracket > 0) {
+          /* Remove ']' */
+          ifname[square_bracket] = '\0';
+          scope = if_nametoindex(ifname);
+        }
+        if (scope > 0) {
+          /* Remove zone identifier from hostname */
+          memmove(percent,
+                  percent + 3 + strlen(ifname),
+                  3 + strlen(ifname));
+          if(!data->state.this_is_a_follow)
+            /* Don't honour a scope given in a Location: header */
+            conn->scope = scope;
+        }
+        else {
+#endif
+          infof(data, "Invalid IPv6 address format\n");
+#ifdef HAVE_NET_IF_H
+        }
+#endif
+      }
     }
   }
 
-- 
1.8.3.1
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-03-15