From f57b23c4059c67c4c2c7ab1b06c02c000bcf7250 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 1 Feb 2015 17:04:09 +0100 Subject: [PATCH] frontend, client: Properly support IPv6 when handling address strings. --- src/client/sock.c | 2 +- src/frontend/sock.c | 3 ++- src/utils/os.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/sock.c b/src/client/sock.c index 838dd95..b1efe58 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -187,7 +187,7 @@ connect_tcp(sdb_client_t *client, const char *address) } strncpy(host, address, sizeof(host)); - if ((tmp = strchr(host, (int)':'))) + if ((tmp = strrchr(host, (int)':'))) *tmp = '\0'; if (! host[0]) strncpy(host, "localhost", sizeof(host)); diff --git a/src/frontend/sock.c b/src/frontend/sock.c index c2a805a..cf187fc 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -434,7 +434,8 @@ get_type(const char *address) return impl->type; } } - return -1; + /* don't report an error, this could be an IPv6 address */ + return listener_impls[0].type; } /* get_type */ static void diff --git a/src/utils/os.c b/src/utils/os.c index c94e271..2b6a514 100644 --- a/src/utils/os.c +++ b/src/utils/os.c @@ -319,7 +319,7 @@ sdb_resolve(int network, const char *address, struct addrinfo **res) if (address) { host = address; - port = strchr(host, ':'); + port = strrchr(host, ':'); if (port) { *port = '\0'; ++port; -- 2.30.2