From: Remi Collet Date: Tue, 26 Jan 2021 10:35:46 +0000 (+0100) Subject: drop [] from address, commonly used for IPv6 X-Git-Tag: 1.1.0-beta3~10 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=46bddd219732926aae6734a1962c3899b9946ffb;p=awesomized%2Flibmemcached drop [] from address, commonly used for IPv6 --- diff --git a/src/libmemcached/connect.cc b/src/libmemcached/connect.cc index 90f1b217..e6db6fd6 100644 --- a/src/libmemcached/connect.cc +++ b/src/libmemcached/connect.cc @@ -46,8 +46,22 @@ static memcached_return_t set_hostinfo(memcached_instance_st *server) { assert(server->address_info == NULL); assert(server->address_info_next == NULL); int errcode; + char hostname[MEMCACHED_NI_MAXHOST]; + const char *addr; + char *p; + assert(server->hostname()); - switch (errcode = getaddrinfo(server->hostname(), str_port, &hints, &server->address_info)) { + // drop [] from address, commonly used for IPv6 + addr = server->hostname(); + if (*addr == '[') { + strcpy(hostname, addr +1); + p = strchr(hostname, ']'); + if (p) { + *p = 0; + addr = hostname; + } + } + switch (errcode = getaddrinfo(addr, str_port, &hints, &server->address_info)) { case 0: server->address_info_next = server->address_info; server->state = MEMCACHED_SERVER_STATE_ADDRINFO;