From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
berrange@redhat.com, "Alex Bennée" <alex.bennee@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/5] tests: specify the address family when checking bind
Date: Tue, 9 Jul 2019 23:43:28 +0400 [thread overview]
Message-ID: <20190709194330.837-4-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com>
getaddrinfo() may succeed with PF_UNSPEC, but fail when more specific.
(this allows to skip some tests that would fail under podman)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
tests/socket-helpers.c | 17 +++++++++++++----
tests/socket-helpers.h | 11 -----------
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/tests/socket-helpers.c b/tests/socket-helpers.c
index 8112763f5b..19a51e887e 100644
--- a/tests/socket-helpers.c
+++ b/tests/socket-helpers.c
@@ -30,7 +30,16 @@
# define EAI_ADDRFAMILY 0
#endif
-int socket_can_bind_connect(const char *hostname)
+/*
+ * @hostname: a DNS name or numeric IP address
+ *
+ * Check whether it is possible to bind & connect to ports
+ * on the DNS name or IP address @hostname. If an IP address
+ * is used, it must not be a wildcard address.
+ *
+ * Returns 0 on success, -1 on error with errno set
+ */
+static int socket_can_bind_connect(const char *hostname, int family)
{
int lfd = -1, cfd = -1, afd = -1;
struct addrinfo ai, *res = NULL;
@@ -44,7 +53,7 @@ int socket_can_bind_connect(const char *hostname)
memset(&ai, 0, sizeof(ai));
ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
- ai.ai_family = AF_UNSPEC;
+ ai.ai_family = family;
ai.ai_socktype = SOCK_STREAM;
/* lookup */
@@ -129,7 +138,7 @@ int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6)
{
*has_ipv4 = *has_ipv6 = false;
- if (socket_can_bind_connect("127.0.0.1") < 0) {
+ if (socket_can_bind_connect("127.0.0.1", PF_INET) < 0) {
if (errno != EADDRNOTAVAIL) {
return -1;
}
@@ -137,7 +146,7 @@ int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6)
*has_ipv4 = true;
}
- if (socket_can_bind_connect("::1") < 0) {
+ if (socket_can_bind_connect("::1", PF_INET6) < 0) {
if (errno != EADDRNOTAVAIL) {
return -1;
}
diff --git a/tests/socket-helpers.h b/tests/socket-helpers.h
index 9de0e6b151..512a004811 100644
--- a/tests/socket-helpers.h
+++ b/tests/socket-helpers.h
@@ -20,17 +20,6 @@
#ifndef TESTS_SOCKET_HELPERS_H
#define TESTS_SOCKET_HELPERS_H
-/*
- * @hostname: a DNS name or numeric IP address
- *
- * Check whether it is possible to bind & connect to ports
- * on the DNS name or IP address @hostname. If an IP address
- * is used, it must not be a wildcard address.
- *
- * Returns 0 on success, -1 on error with errno set
- */
-int socket_can_bind_connect(const char *hostname);
-
/*
* @has_ipv4: set to true on return if IPv4 is available
* @has_ipv6: set to true on return if IPv6 is available
--
2.22.0.214.g8dca754b1e
next prev parent reply other threads:[~2019-07-09 19:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-09 19:43 [Qemu-devel] [PATCH v2 0/5] tests/docker: add podman support Marc-André Lureau
2019-07-09 19:43 ` [Qemu-devel] [PATCH v2 1/5] docker.py: " Marc-André Lureau
2019-07-11 15:52 ` Alex Bennée
2019-07-09 19:43 ` [Qemu-devel] [PATCH v2 2/5] tests/docker: " Marc-André Lureau
2019-07-10 8:27 ` Paolo Bonzini
2019-07-10 8:39 ` Marc-André Lureau
2019-07-10 9:44 ` Paolo Bonzini
2019-07-11 15:55 ` Alex Bennée
2019-07-17 15:44 ` Debarshi Ray
2019-07-17 15:17 ` Debarshi Ray
2019-07-09 19:43 ` Marc-André Lureau [this message]
2019-07-10 10:12 ` [Qemu-devel] [PATCH v2 3/5] tests: specify the address family when checking bind Philippe Mathieu-Daudé
2019-07-09 19:43 ` [Qemu-devel] [PATCH v2 4/5] test-char: skip tcp tests if ipv4 check failed Marc-André Lureau
2019-07-09 19:43 ` [Qemu-devel] [PATCH v2 5/5] test: skip tests if socket_check_protocol_support() failed Marc-André Lureau
2019-07-09 23:39 ` [Qemu-devel] [PATCH v2 0/5] tests/docker: add podman support no-reply
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=20190709194330.837-4-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=fam@euphon.net \
--cc=kraxel@redhat.com \
--cc=philmd@redhat.com \
--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).