diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-30 20:36:27 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-30 20:36:27 +0200 |
commit | 7d5ddf14a3ce2b9c3e8251e40d67333b13287a15 (patch) | |
tree | 08790d7c9c27ae3fe538eed58d4c08455a79a36b /networking/wget.c | |
parent | 8bca3e20b9c057e9144af27870ca3905f1e5d316 (diff) | |
download | busybox-w32-7d5ddf14a3ce2b9c3e8251e40d67333b13287a15.tar.gz busybox-w32-7d5ddf14a3ce2b9c3e8251e40d67333b13287a15.tar.bz2 busybox-w32-7d5ddf14a3ce2b9c3e8251e40d67333b13287a15.zip |
wget: remove IPv6 scope id in Host: field (apache compat)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/networking/wget.c b/networking/wget.c index d518286a4..26b62cc58 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -193,6 +193,42 @@ static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { } | |||
193 | #endif | 193 | #endif |
194 | 194 | ||
195 | 195 | ||
196 | /* IPv6 knows scoped address types i.e. link and site local addresses. Link | ||
197 | * local addresses can have a scope identifier to specify the | ||
198 | * interface/link an address is valid on (e.g. fe80::1%eth0). This scope | ||
199 | * identifier is only valid on a single node. | ||
200 | * | ||
201 | * RFC 4007 says that the scope identifier MUST NOT be sent across the wire, | ||
202 | * unless all nodes agree on the semantic. Apache e.g. regards zone identifiers | ||
203 | * in the Host header as invalid requests, see | ||
204 | * https://issues.apache.org/bugzilla/show_bug.cgi?id=35122 | ||
205 | */ | ||
206 | static void strip_ipv6_scope_id(char *host) | ||
207 | { | ||
208 | char *scope, *cp; | ||
209 | |||
210 | /* bbox wget actually handles IPv6 addresses without [], like | ||
211 | * wget "http://::1/xxx", but this is not standard. | ||
212 | * To save code, _here_ we do not support it. */ | ||
213 | |||
214 | if (host[0] != '[') | ||
215 | return; /* not IPv6 */ | ||
216 | |||
217 | scope = strchr(host, '%'); | ||
218 | if (!scope) | ||
219 | return; | ||
220 | |||
221 | /* Remove the IPv6 zone identifier from the host address */ | ||
222 | cp = strchr(host, ']'); | ||
223 | if (!cp || (cp[1] != ':' && cp[1] != '\0')) { | ||
224 | /* malformed address (not "[xx]:nn" or "[xx]") */ | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | /* cp points to "]...", scope points to "%eth0]..." */ | ||
229 | overlapping_strcpy(scope, cp); | ||
230 | } | ||
231 | |||
196 | /* Read NMEMB bytes into PTR from STREAM. Returns the number of bytes read, | 232 | /* Read NMEMB bytes into PTR from STREAM. Returns the number of bytes read, |
197 | * and a short count if an eof or non-interrupt error is encountered. */ | 233 | * and a short count if an eof or non-interrupt error is encountered. */ |
198 | static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream) | 234 | static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream) |
@@ -655,20 +691,30 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
655 | #endif | 691 | #endif |
656 | 692 | ||
657 | /* TODO: compat issue: should handle "wget URL1 URL2..." */ | 693 | /* TODO: compat issue: should handle "wget URL1 URL2..." */ |
694 | |||
658 | parse_url(argv[optind], &target); | 695 | parse_url(argv[optind], &target); |
659 | server.host = target.host; | ||
660 | server.port = target.port; | ||
661 | 696 | ||
662 | /* Use the proxy if necessary */ | 697 | /* Use the proxy if necessary */ |
663 | use_proxy = (strcmp(proxy_flag, "off") != 0); | 698 | use_proxy = (strcmp(proxy_flag, "off") != 0); |
664 | if (use_proxy) { | 699 | if (use_proxy) { |
665 | proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); | 700 | proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); |
666 | if (proxy && *proxy) { | 701 | if (proxy && proxy[0]) { |
667 | parse_url(proxy, &server); | 702 | parse_url(proxy, &server); |
668 | } else { | 703 | } else { |
669 | use_proxy = 0; | 704 | use_proxy = 0; |
670 | } | 705 | } |
671 | } | 706 | } |
707 | if (!use_proxy) { | ||
708 | server.port = target.port; | ||
709 | if (ENABLE_FEATURE_IPV6) { | ||
710 | server.host = xstrdup(target.host); | ||
711 | } else { | ||
712 | server.host = target.host; | ||
713 | } | ||
714 | } | ||
715 | |||
716 | if (ENABLE_FEATURE_IPV6) | ||
717 | strip_ipv6_scope_id(target.host); | ||
672 | 718 | ||
673 | /* Guess an output filename, if there was no -O FILE */ | 719 | /* Guess an output filename, if there was no -O FILE */ |
674 | if (!(opt & WGET_OPT_OUTNAME)) { | 720 | if (!(opt & WGET_OPT_OUTNAME)) { |
@@ -862,6 +908,8 @@ However, in real world it was observed that some web servers | |||
862 | parse_url(str, &target); | 908 | parse_url(str, &target); |
863 | if (!use_proxy) { | 909 | if (!use_proxy) { |
864 | server.host = target.host; | 910 | server.host = target.host; |
911 | /* strip_ipv6_scope_id(target.host); - no! */ | ||
912 | /* we assume remote never gives us IPv6 addr with scope id */ | ||
865 | server.port = target.port; | 913 | server.port = target.port; |
866 | free(lsa); | 914 | free(lsa); |
867 | goto resolve_lsa; | 915 | goto resolve_lsa; |