#define _GNU_SOURCE
#include <sys/stat.h>
+#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>
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();
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/socket.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
long read_chunked;
long content_length;
+ int usock_flags;
+
uint32_t nc;
struct blob_buf headers;
memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
- fd = usock_inet(USOCK_TCP, uh->uc.url->host, port, &uh->uc.remote_addr);
+ fd = usock_inet(USOCK_TCP | uh->usock_flags, uh->uc.url->host, port, &uh->uc.remote_addr);
if (fd < 0)
return -1;
return 0;
}
+int uclient_http_set_address_family(struct uclient *cl, int af)
+{
+ struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
+
+ if (cl->backend != &uclient_backend_http)
+ return -1;
+
+ switch (af) {
+ case AF_INET:
+ uh->usock_flags = USOCK_IPV4ONLY;
+ break;
+ case AF_INET6:
+ uh->usock_flags = USOCK_IPV6ONLY;
+ break;
+ default:
+ uh->usock_flags = 0;
+ break;
+ }
+
+ return 0;
+}
+
const struct uclient_backend uclient_backend_http = {
.prefix = uclient_http_prefix,
int uclient_http_set_ssl_ctx(struct uclient *cl, const struct ustream_ssl_ops *ops,
struct ustream_ssl_ctx *ctx, bool require_validation);
+int uclient_http_set_address_family(struct uclient *cl, int af);
#endif