mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
https-client: fix connect to ipv6 address with square brackets
getaddrinfo() cannot process addresses like "[::1]", only "::1" Fixes: #1275
This commit is contained in:
parent
5cc2ff8897
commit
41239c9dac
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user