|
|
@ -127,8 +127,8 @@ static bool is_port_available(int *port, bool is_tcp) { |
|
|
|
on each supported family. */ |
|
|
|
on each supported family. */ |
|
|
|
bool got_socket = false; |
|
|
|
bool got_socket = false; |
|
|
|
for (int is_ipv6 = 1; is_ipv6 >= 0; is_ipv6--) { |
|
|
|
for (int is_ipv6 = 1; is_ipv6 >= 0; is_ipv6--) { |
|
|
|
const int fd = socket(is_ipv6 ? AF_INET6 : AF_INET, |
|
|
|
const int fd = |
|
|
|
is_tcp ? SOCK_STREAM : SOCK_DGRAM, |
|
|
|
socket(is_ipv6 ? AF_INET6 : AF_INET, is_tcp ? SOCK_STREAM : SOCK_DGRAM, |
|
|
|
is_tcp ? IPPROTO_TCP : 0); |
|
|
|
is_tcp ? IPPROTO_TCP : 0); |
|
|
|
if (fd >= 0) { |
|
|
|
if (fd >= 0) { |
|
|
|
got_socket = true; |
|
|
|
got_socket = true; |
|
|
@ -158,8 +158,8 @@ static bool is_port_available(int *port, bool is_tcp) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Get the bound port number */ |
|
|
|
/* Get the bound port number */ |
|
|
|
if (getsockname(fd, (struct sockaddr *)addr.addr, |
|
|
|
if (getsockname(fd, (struct sockaddr *)addr.addr, (socklen_t *)&addr.len) < |
|
|
|
(socklen_t *)&addr.len) < 0) { |
|
|
|
0) { |
|
|
|
gpr_log(GPR_ERROR, "getsockname() failed: %s", strerror(errno)); |
|
|
|
gpr_log(GPR_ERROR, "getsockname() failed: %s", strerror(errno)); |
|
|
|
close(fd); |
|
|
|
close(fd); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|