aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/client_channel/parse_address.c
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2017-02-15 14:00:01 -0800
committerGravatar Yuchen Zeng <zyc@google.com>2017-02-22 16:25:52 -0800
commitaa76d3d3b642304ba05026593fc8b9cf8b49e072 (patch)
tree889025a5798b4007f85198f6c5e66e756dc37db1 /src/core/ext/client_channel/parse_address.c
parentdfa88e95c5584ccce7c339e704ac5c1ad3bfb894 (diff)
Enclose sin6_scope_id in uri
Diffstat (limited to 'src/core/ext/client_channel/parse_address.c')
-rw-r--r--src/core/ext/client_channel/parse_address.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/ext/client_channel/parse_address.c b/src/core/ext/client_channel/parse_address.c
index b1d55ad0f5..eb1df84bc6 100644
--- a/src/core/ext/client_channel/parse_address.c
+++ b/src/core/ext/client_channel/parse_address.c
@@ -44,6 +44,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
+#include "src/core/lib/support/string.h"
#ifdef GRPC_HAVE_UNIX_SOCKET
@@ -119,9 +120,28 @@ int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr) {
memset(in6, 0, sizeof(*in6));
resolved_addr->len = sizeof(*in6);
in6->sin6_family = AF_INET6;
- if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
- gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
- goto done;
+
+ char *host_end = (char *)gpr_memrchr(host, '%', strlen(host));
+ if (host_end != NULL) {
+ size_t host_without_scope_len = (size_t)(host_end - host);
+ char host_without_scope[host_without_scope_len + 1];
+ strncpy(host_without_scope, host, host_without_scope_len);
+ host_without_scope[host_without_scope_len] = '\0';
+ if (inet_pton(AF_INET6, host_without_scope, &in6->sin6_addr) == 0) {
+ gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope);
+ goto done;
+ }
+ if (gpr_parse_bytes_to_uint32(host_end + 1,
+ strlen(host) - host_without_scope_len - 1,
+ &in6->sin6_scope_id) == 0) {
+ gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
+ goto done;
+ }
+ } else {
+ if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
+ gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
+ goto done;
+ }
}
if (port != NULL) {