X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=uclient-fetch.c;h=065742eeed3378167b234cb664efb19750af26e0;hb=f0754619b9ee216b0cb5fc7484f861e876781984;hp=ebf49ae559ac395fbd069ab53c3d1e29da42f4be;hpb=ea129593d022d6edb9237f1888f1f7899a8c6f61;p=project%2Fuclient.git diff --git a/uclient-fetch.c b/uclient-fetch.c index ebf49ae..065742e 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -18,6 +18,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -103,7 +104,7 @@ static int open_output_file(const char *path, uint64_t resume_offset) if (cur_resume) flags = O_RDWR; else - flags = O_WRONLY; + flags = O_WRONLY | O_TRUNC; if (!cur_resume && !output_file) flags |= O_EXCL; @@ -439,9 +440,11 @@ static int usage(const char *progname) fprintf(stderr, "Usage: %s [options] \n" "Options:\n" - " -q: Turn off status messages\n" - " -O : Redirect output to file (use \"-\" for stdout)\n" - " -P : Set directory for output files\n" + " -4 Use IPv4 only\n" + " -6 Use IPv6 only\n" + " -q Turn off status messages\n" + " -O Redirect output to file (use \"-\" for stdout)\n" + " -P Set directory for output files\n" " --user= HTTP authentication username\n" " --password= HTTP authentication password\n" " --user-agent|-U Set HTTP user agent\n" @@ -451,8 +454,8 @@ static int usage(const char *progname) " --proxy=on|off|-Y on|off Enable/disable env var configured proxy\n" "\n" "HTTPS options:\n" - " --ca-certificate=: Load CA certificates from file \n" - " --no-check-certificate: don't validate the server's certificate\n" + " --ca-certificate= Load CA certificates from file \n" + " --no-check-certificate don't validate the server's certificate\n" "\n", progname); return 1; } @@ -530,11 +533,12 @@ int main(int argc, char **argv) bool has_cert = false; int i, ch; int rc; + int af = -1; signal(SIGPIPE, SIG_IGN); init_ustream_ssl(); - while ((ch = getopt_long(argc, argv, "cO:P:qsT:U:Y:", longopts, &longopt_idx)) != -1) { + while ((ch = getopt_long(argc, argv, "46cO:P:qsT:U:Y:", longopts, &longopt_idx)) != -1) { switch(ch) { case 0: switch (longopt_idx) { @@ -584,6 +588,12 @@ int main(int argc, char **argv) return usage(progname); } break; + case '4': + af = AF_INET; + break; + case '6': + af = AF_INET6; + break; case 'c': resume = true; break; @@ -652,7 +662,8 @@ int main(int argc, char **argv) proxy_url = get_proxy_url(argv[0]); if (proxy_url) { cl = uclient_new(proxy_url, auth_str, &cb); - uclient_set_proxy_url(cl, argv[0], NULL); + if (cl) + uclient_set_proxy_url(cl, argv[0], NULL); } else { cl = uclient_new(argv[0], auth_str, &cb); } @@ -660,6 +671,8 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to allocate uclient context\n"); return 1; } + if (af >= 0) + uclient_http_set_address_family(cl, af); if (ssl_ctx && default_certs) init_ca_cert();