summaryrefslogtreecommitdiff
path: root/uclient-http.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2016-01-25 00:18:33 +0100
committerFelix Fietkau <nbd@openwrt.org>2016-01-25 00:18:33 +0100
commitf50a654323bbfeb0de53aa2178755b282bcc9d22 (patch)
tree819e5436d6c8c273fa5c45d01b59de016c2583b3 /uclient-http.c
parentcaa8052ac55218a687593f3dcf30229016e48b0d (diff)
downloaduclient-f50a654323bbfeb0de53aa2178755b282bcc9d22.tar.gz
http: add support for specifying ipv4/ipv6 preference
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'uclient-http.c')
-rw-r--r--uclient-http.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/uclient-http.c b/uclient-http.c
index 5e5f996..f080e41 100644
--- a/uclient-http.c
+++ b/uclient-http.c
@@ -15,6 +15,7 @@
* 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>
@@ -90,6 +91,8 @@ struct uclient_http {
long read_chunked;
long content_length;
+ int usock_flags;
+
uint32_t nc;
struct blob_buf headers;
@@ -120,7 +123,7 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port)
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;
@@ -1129,6 +1132,28 @@ int uclient_http_set_ssl_ctx(struct uclient *cl, const struct ustream_ssl_ops *o
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,