1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00

Fix for mg_inet_pton on Linux

While getaddrinfo on Windows will work with [::1],
getaddrinfo on Linux only works with ::1 (without []).
This commit is contained in:
bel
2015-08-16 22:32:33 +02:00
parent a440a482e8
commit b1e93e70e5

View File

@@ -4993,8 +4993,23 @@ static int connect_socket(struct mg_context *ctx /* may be null */,
} else if (mg_inet_pton(AF_INET6, host, &sa->sin6, sizeof(sa->sin6))) {
sa->sin6.sin6_port = htons((uint16_t)port);
ip_ver = 6;
} else if (host[0] == '[') {
/* While getaddrinfo on Windows will work with [::1],
* getaddrinfo on Linux only works with ::1 (without []). */
size_t l = strlen(host + 1);
char *h = l > 1 ? mg_strdup(host + 1) : NULL;
if (h) {
h[l - 1] = 0;
if (mg_inet_pton(AF_INET6, h, &sa->sin6, sizeof(sa->sin6))) {
sa->sin6.sin6_port = htons((uint16_t)port);
ip_ver = 6;
}
mg_free(h);
}
#endif
} else {
}
if (ip_ver == 0) {
mg_snprintf(NULL,
NULL, /* No truncation check for ebuf */
ebuf,