#define _GNU_SOURCE
#include <sys/stat.h>
+#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>
if (cur_resume)
flags = O_RDWR;
else
- flags = O_WRONLY;
+ flags = O_WRONLY | O_TRUNC;
if (!cur_resume && !output_file)
flags |= O_EXCL;
fprintf(stderr,
"Usage: %s [options] <URL>\n"
"Options:\n"
+ " -4: Use IPv4 only\n"
+ " -6: Use IPv6 only\n"
" -q: Turn off status messages\n"
" -O <file>: Redirect output to file (use \"-\" for stdout)\n"
" -P <dir>: Set directory for output files\n"
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) {
return usage(progname);
}
break;
+ case '4':
+ af = AF_INET;
+ break;
+ case '6':
+ af = AF_INET6;
+ break;
case 'c':
resume = true;
break;
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);
}
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();