summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorAzat Khuzhin <azat@libevent.org>2022-05-12 07:37:19 +0300
committerAzat Khuzhin <azat@libevent.org>2022-05-12 07:37:19 +0300
commit41239c9dac70ed90187fb287f214e1b106f52c83 (patch)
tree4b5bb08be3db011b26f597ec53c779eb65ef8100 /sample
parent5cc2ff8897dade8eb4d5426884490fae0e2f160b (diff)
downloadlibevent-41239c9dac70ed90187fb287f214e1b106f52c83.tar.gz
https-client: fix connect to ipv6 address with square brackets
getaddrinfo() cannot process addresses like "[::1]", only "::1" Fixes: #1275
Diffstat (limited to 'sample')
-rw-r--r--sample/https-client.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sample/https-client.c b/sample/https-client.c
index 733655fb..85433850 100644
--- a/sample/https-client.c
+++ b/sample/https-client.c
@@ -541,8 +541,18 @@ main(int argc, char **argv)
// For simplicity, we let DNS resolution block. Everything else should be
// asynchronous though.
- evcon = evhttp_connection_base_bufferevent_new(base, NULL, bev,
- host, port);
+ {
+ if (host[0] == '[' && strlen(host) > 2 && ipv6) {
+ // trim '[' and ']'
+ char *host_ipv6 = strndup(&host[1], strlen(&host[1]) - 1);
+ evcon = evhttp_connection_base_bufferevent_new(base, NULL, bev,
+ host_ipv6, port);
+ free(host_ipv6);
+ } else {
+ evcon = evhttp_connection_base_bufferevent_new(base, NULL, bev,
+ host, port);
+ }
+ }
if (evcon == NULL) {
fprintf(stderr, "evhttp_connection_base_bufferevent_new() failed\n");
goto error;