* [Qemu-devel] [PATCH] io: stronger check for support for IPv4/6
@ 2016-03-14 18:49 Daniel P. Berrange
0 siblings, 0 replies; only message in thread
From: Daniel P. Berrange @ 2016-03-14 18:49 UTC (permalink / raw)
To: qemu-devel; +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 <berrange@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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-03-14 18:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-14 18:49 [Qemu-devel] [PATCH] io: stronger check for support for IPv4/6 Daniel P. Berrange
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).