From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afXYM-0003Z2-Ae for qemu-devel@nongnu.org; Mon, 14 Mar 2016 14:49:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afXYH-000571-7S for qemu-devel@nongnu.org; Mon, 14 Mar 2016 14:49:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afXYH-00056x-1m for qemu-devel@nongnu.org; Mon, 14 Mar 2016 14:49:13 -0400 From: "Daniel P. Berrange" Date: Mon, 14 Mar 2016 18:49:05 +0000 Message-Id: <1457981345-19681-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH] io: stronger check for support for IPv4/6 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell 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 --- 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