Use AI_ADDRCONFIG hint with getaddrinfo if available.
authorTomas Mraz <tmraz@fedoraproject.org>
Thu, 21 Mar 2019 12:17:29 +0000 (13:17 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 3 Apr 2019 23:25:08 +0000 (01:25 +0200)
This prevents failure of openssl s_server socket binding to wildcard
address on hosts with disabled IPv6.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8550)

(cherry picked from commit b8472b4e67ec7ad49254821f2da578ce588df4e6)

crypto/bio/b_addr.c

index 4395ab7a0683ec69418aa16d6150a50c4c715121..f295b766fa7346d7ac4c11d4bb1485d9c36b80d4 100644 (file)
@@ -683,6 +683,12 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
         hints.ai_family = family;
         hints.ai_socktype = socktype;
         hints.ai_protocol = protocol;
+#ifdef AI_ADDRCONFIG
+#ifdef AF_UNSPEC
+        if (family == AF_UNSPEC)
+#endif
+            hints.ai_flags |= AI_ADDRCONFIG;
+#endif
 
         if (lookup_type == BIO_LOOKUP_SERVER)
             hints.ai_flags |= AI_PASSIVE;