Instead of just checking for bind(), use socket_listen() so that we check getaddrinfo() can resolve IPv6 addrs too. This should avoids test failures on QEMU travis build systems which can't resolve IPv6 addrs.
Signed-off-by: Daniel P. Berrange <berra...@redhat.com> --- tests/test-io-channel-socket.c | 62 ++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index ae665f5..060c109 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -23,48 +23,40 @@ #include "io/channel-util.h" #include "io-channel-helpers.h" -static int check_bind(struct sockaddr *sa, socklen_t salen, bool *has_proto) +static bool check_listen(InetSocketAddress *saddr) { - int fd; - - fd = socket(sa->sa_family, SOCK_STREAM, 0); + SocketAddress addr = { + .type = SOCKET_ADDRESS_KIND_INET, + .u.inet = saddr, + }; + int fd = socket_listen(&addr, NULL); if (fd < 0) { - return -1; - } - - if (bind(fd, sa, salen) < 0) { - close(fd); - if (errno == EADDRNOTAVAIL) { - *has_proto = false; - return 0; - } - return -1; + return false; } - close(fd); - *has_proto = true; - return 0; + return true; } -static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) +static void check_protocol_support(bool *has_ipv4, bool *has_ipv6) { - struct sockaddr_in sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) }, + InetSocketAddress saddr4 = { + .host = (char *)"127.0.0.1", + .port = NULL, + .has_ipv4 = true, + .ipv4 = true, + .has_ipv6 = true, + .ipv6 = false, }; - struct sockaddr_in6 sin6 = { - .sin6_family = AF_INET6, - .sin6_addr = IN6ADDR_LOOPBACK_INIT, + InetSocketAddress saddr6 = { + .host = (char *)"::1", + .port = NULL, + .has_ipv4 = true, + .ipv4 = false, + .has_ipv6 = true, + .ipv6 = true, }; - - if (check_bind((struct sockaddr *)&sin, sizeof(sin), has_ipv4) < 0) { - return -1; - } - if (check_bind((struct sockaddr *)&sin6, sizeof(sin6), has_ipv6) < 0) { - return -1; - } - - return 0; + *has_ipv4 = check_listen(&saddr4); + *has_ipv6 = check_listen(&saddr6); } @@ -510,9 +502,7 @@ int main(int argc, char **argv) * each protocol to avoid breaking tests on machines * with either IPv4 or IPv6 disabled. */ - if (check_protocol_support(&has_ipv4, &has_ipv6) < 0) { - return 1; - } + check_protocol_support(&has_ipv4, &has_ipv6); if (has_ipv4) { g_test_add_func("/io/channel/socket/ipv4-sync", -- 2.5.0