[PATCH 1/3] virNetSocketCheckProtocols: Separate out checking family via getaddrinfo()

Ján Tomko jtomko at redhat.com
Wed Jul 15 21:43:21 UTC 2020


On a Wednesday in 2020, Michal Privoznik wrote:
>The virNetSocketCheckProtocols() function is supposed to tell
>caller whether IPv4 and/or IPv6 is supported on the system. In
>the initial round, it uses getifaddrs() to see if an interface
>has IPv4/IPv6 address assigned and then to double check IPv6 it
>uses getaddrinfo() to lookup IPv6 loopback address. Separate out
>this latter code because it is going to be reused.
>
>Since the original code lived under an #ifdef and the new
>function doesn't it is marked as unused - because on some systems
>it may be so.
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/rpc/virnetsocket.c | 63 ++++++++++++++++++++++++++----------------
> 1 file changed, 39 insertions(+), 24 deletions(-)
>
>diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
>index d1f4c531aa..b6bc3edc3b 100644
>--- a/src/rpc/virnetsocket.c
>+++ b/src/rpc/virnetsocket.c
>@@ -141,16 +141,48 @@ static int virNetSocketForkDaemon(const char *binary)
> }
> #endif
>
>+
>+static int G_GNUC_UNUSED
>+virNetSocketCheckProtocolByLookup(const char *address,
>+                                  int family,
>+                                  bool *hasFamily)
>+{
>+    struct addrinfo hints;
>+    struct addrinfo *ai = NULL;
>+    int gaierr;
>+
>+    memset(&hints, 0, sizeof(hints));
>+    hints.ai_family = family;
>+    hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
>+    hints.ai_socktype = SOCK_STREAM;
>+
>+    if ((gaierr = getaddrinfo(address, NULL, &hints, &ai)) != 0) {
>+        *hasFamily = false;
>+
>+        if (gaierr == EAI_FAMILY ||
>+#ifdef EAI_ADDRFAMILY
>+            gaierr == EAI_ADDRFAMILY ||
>+#endif
>+            gaierr == EAI_NONAME) {
>+        } else {
>+            virReportError(VIR_ERR_INTERNAL_ERROR,
>+                           _("Cannot resolve ::1 address: %s"),

s/::1/'%s'/

>+                           gai_strerror(gaierr));
>+            return -1;
>+        }
>+    } else {
>+        *hasFamily = true;
>+    }

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200715/3593ae2d/attachment-0001.sig>


More information about the libvir-list mailing list