|
|
|
@ -39,7 +39,7 @@ |
|
|
|
|
|
|
|
|
|
bool grpc_parse_unix(const grpc_uri* uri, |
|
|
|
|
grpc_resolved_address* resolved_addr) { |
|
|
|
|
if (strcmp("unix", uri->scheme) != 0) { |
|
|
|
|
if (GPR_UNLIKELY(strcmp("unix", uri->scheme) != 0)) { |
|
|
|
|
gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -75,17 +75,18 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, |
|
|
|
|
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in)); |
|
|
|
|
grpc_sockaddr_in* in = reinterpret_cast<grpc_sockaddr_in*>(addr->addr); |
|
|
|
|
in->sin_family = GRPC_AF_INET; |
|
|
|
|
if (grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0) { |
|
|
|
|
if (GPR_UNLIKELY(grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0)) { |
|
|
|
|
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
// Parse port.
|
|
|
|
|
if (port == nullptr) { |
|
|
|
|
if (GPR_UNLIKELY(port == nullptr)) { |
|
|
|
|
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
int port_num; |
|
|
|
|
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) { |
|
|
|
|
if (GPR_UNLIKELY(sscanf(port, "%d", &port_num) != 1 || port_num < 0 || |
|
|
|
|
port_num > 65535)) { |
|
|
|
|
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
@ -99,7 +100,7 @@ done: |
|
|
|
|
|
|
|
|
|
bool grpc_parse_ipv4(const grpc_uri* uri, |
|
|
|
|
grpc_resolved_address* resolved_addr) { |
|
|
|
|
if (strcmp("ipv4", uri->scheme) != 0) { |
|
|
|
|
if (GPR_UNLIKELY(strcmp("ipv4", uri->scheme) != 0)) { |
|
|
|
|
gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -130,32 +131,35 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, |
|
|
|
|
uint32_t sin6_scope_id = 0; |
|
|
|
|
strncpy(host_without_scope, host, host_without_scope_len); |
|
|
|
|
host_without_scope[host_without_scope_len] = '\0'; |
|
|
|
|
if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) == |
|
|
|
|
0) { |
|
|
|
|
if (GPR_UNLIKELY(grpc_inet_pton(GRPC_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, |
|
|
|
|
if (GPR_UNLIKELY( |
|
|
|
|
gpr_parse_bytes_to_uint32(host_end + 1, |
|
|
|
|
strlen(host) - host_without_scope_len - 1, |
|
|
|
|
&sin6_scope_id) == 0) { |
|
|
|
|
&sin6_scope_id) == 0)) { |
|
|
|
|
gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
// Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
|
|
|
|
|
in6->sin6_scope_id = sin6_scope_id; |
|
|
|
|
} else { |
|
|
|
|
if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) { |
|
|
|
|
if (GPR_UNLIKELY(grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == |
|
|
|
|
0)) { |
|
|
|
|
gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Parse port.
|
|
|
|
|
if (port == nullptr) { |
|
|
|
|
if (GPR_UNLIKELY(port == nullptr)) { |
|
|
|
|
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
int port_num; |
|
|
|
|
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) { |
|
|
|
|
if (GPR_UNLIKELY(sscanf(port, "%d", &port_num) != 1 || port_num < 0 || |
|
|
|
|
port_num > 65535)) { |
|
|
|
|
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
@ -169,7 +173,7 @@ done: |
|
|
|
|
|
|
|
|
|
bool grpc_parse_ipv6(const grpc_uri* uri, |
|
|
|
|
grpc_resolved_address* resolved_addr) { |
|
|
|
|
if (strcmp("ipv6", uri->scheme) != 0) { |
|
|
|
|
if (GPR_UNLIKELY(strcmp("ipv6", uri->scheme) != 0)) { |
|
|
|
|
gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|