From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH] io: stronger check for support for IPv4/6
Date: Mon, 14 Mar 2016 18:49:05 +0000 [thread overview]
Message-ID: <1457981345-19681-1-git-send-email-berrange@redhat.com> (raw)
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
reply other threads:[~2016-03-14 18:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457981345-19681-1-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).