add ipv6 literal support to wget
authorGlenn L McGrath <bug1@ihug.co.nz>
Wed, 10 Sep 2003 23:52:15 +0000 (23:52 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Wed, 10 Sep 2003 23:52:15 +0000 (23:52 -0000)
networking/Config.in
networking/wget.c

index 2705980bbcffe95ead38f18b5769034b5c0c0448..534f672055aa54da415b3eebb5e168d49e91984c 100644 (file)
@@ -589,6 +589,13 @@ config CONFIG_FEATURE_WGET_AUTHENTICATION
        help
          Support authenticated HTTP transfers.
 
+config CONFIG_FEATURE_WGET_IP6_LITERAL
+       bool "  Enable IPv6 literal addresses"
+       default y
+       depends on CONFIG_WGET
+       help
+         Support IPv6 address literal notation in URLs.
+
 source networking/udhcp/Config.in
 
 endmenu
index 5ea559b8930fef1417f12063819c6ca8231df879..5f2a39917c414f6d91e0540fb353fc1659ffecce 100644 (file)
@@ -310,7 +310,12 @@ int wget_main(int argc, char **argv)
                         * Send HTTP request.
                         */
                        if (proxy) {
-                               fprintf(sfp, "GET %stp://%s:%d/%s HTTP/1.1\r\n",
+                               const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
+#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
+                               if (strchr (target.host, ':'))
+                                       format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
+#endif
+                               fprintf(sfp, format,
                                        target.is_ftp ? "f" : "ht", target.host,
                                        target.port, target.path);
                        } else {
@@ -525,7 +530,7 @@ read_response:
 
 void parse_url(char *url, struct host_info *h)
 {
-       char *cp, *sp, *up;
+       char *cp, *sp, *up, *pp;
 
        if (strncmp(url, "http://", 7) == 0) {
                h->port = 80;
@@ -553,7 +558,24 @@ void parse_url(char *url, struct host_info *h)
        } else
                h->user = NULL;
 
-       cp = strchr(h->host, ':');
+       pp = h->host;
+
+#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
+       if (h->host[0] == '[') {
+               char *ep;
+
+               ep = h->host + 1;
+               while (*ep == ':' || isdigit (*ep))
+                       ep++;
+               if (*ep == ']') {
+                       h->host++;
+                       *ep = '\0';
+                       pp = ep + 1;
+               }
+       }
+#endif
+
+       cp = strchr(pp, ':');
        if (cp != NULL) {
                *cp++ = '\0';
                h->port = atoi(cp);
@@ -819,7 +841,7 @@ progressmeter(int flag)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: wget.c,v 1.57 2003/08/29 06:25:04 bug1 Exp $
+ *     $Id: wget.c,v 1.58 2003/09/10 23:52:15 bug1 Exp $
  */