diff options
author | Yuchen Zeng <y-zeng@users.noreply.github.com> | 2017-02-27 15:25:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-27 15:25:38 -0800 |
commit | 2aa5a1d90864dd8ebad60e218a7059bbebdc5085 (patch) | |
tree | b7693265416eb00be7bcdddc6982b997db79464d /src/core/lib | |
parent | 38c8bb4a7fc8b0e9d36836d03d9af47f35447011 (diff) | |
parent | c40d1d84f9d492561cb71ea3f5304ef780d7e574 (diff) |
Merge pull request #9839 from y-zeng/1_1_x_address_arg_fix
Preserve ipv6 scope id in grpc_channel_args
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/iomgr/sockaddr_utils.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/core/lib/iomgr/sockaddr_utils.c b/src/core/lib/iomgr/sockaddr_utils.c index 44bc2f968b..f23f9888d5 100644 --- a/src/core/lib/iomgr/sockaddr_utils.c +++ b/src/core/lib/iomgr/sockaddr_utils.c @@ -162,6 +162,7 @@ int grpc_sockaddr_to_string(char **out, char ntop_buf[INET6_ADDRSTRLEN]; const void *ip = NULL; int port; + uint32_t sin6_scope_id = 0; int ret; *out = NULL; @@ -177,10 +178,19 @@ int grpc_sockaddr_to_string(char **out, const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr; ip = &addr6->sin6_addr; port = ntohs(addr6->sin6_port); + sin6_scope_id = addr6->sin6_scope_id; } if (ip != NULL && grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) != NULL) { - ret = gpr_join_host_port(out, ntop_buf, port); + if (sin6_scope_id != 0) { + char *host_with_scope; + /* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */ + gpr_asprintf(&host_with_scope, "%s%%25%" PRIu32, ntop_buf, sin6_scope_id); + ret = gpr_join_host_port(out, host_with_scope, port); + gpr_free(host_with_scope); + } else { + ret = gpr_join_host_port(out, ntop_buf, port); + } } else { ret = gpr_asprintf(out, "(sockaddr family=%d)", addr->sa_family); } |