|
|
|
@ -89,6 +89,12 @@ static grpc_error_handle get_unused_port(int* port) { |
|
|
|
|
return *port <= 0 ? GRPC_ERROR_CREATE("Bad port") : absl::OkStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool grpc_is_ipv4_availabile() { |
|
|
|
|
const int fd = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
|
|
if (fd >= 0) close(fd); |
|
|
|
|
return fd >= 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, |
|
|
|
|
unsigned port_index, |
|
|
|
|
int requested_port, |
|
|
|
@ -110,6 +116,9 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, |
|
|
|
|
} |
|
|
|
|
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool v4_available = grpc_is_ipv4_availabile(); |
|
|
|
|
|
|
|
|
|
if (getifaddrs(&ifa) != 0 || ifa == nullptr) { |
|
|
|
|
return GRPC_OS_ERROR(errno, "getifaddrs"); |
|
|
|
|
} |
|
|
|
@ -121,6 +130,9 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, |
|
|
|
|
if (ifa_it->ifa_addr == nullptr) { |
|
|
|
|
continue; |
|
|
|
|
} else if (ifa_it->ifa_addr->sa_family == AF_INET) { |
|
|
|
|
if (!v4_available) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
addr.len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in)); |
|
|
|
|
} else if (ifa_it->ifa_addr->sa_family == AF_INET6) { |
|
|
|
|
addr.len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in6)); |
|
|
|
|