7580c9a
From 957a39309fa2f8a85a6b8a0a2c5b1751a151cb8b Mon Sep 17 00:00:00 2001
7580c9a
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
7580c9a
Date: Tue, 16 Feb 2021 15:29:58 +0100
7580c9a
Subject: [PATCH] Do not default IO::Socket::IP to AI_ADDRCONFIG flag
7580c9a
MIME-Version: 1.0
7580c9a
Content-Type: text/plain; charset=UTF-8
7580c9a
Content-Transfer-Encoding: 8bit
7580c9a
7580c9a
t/40connect.t fails if the only available network interface is
7580c9a
loopback and IO::Socket::IP is installed:
7580c9a
7580c9a
    # perl -Ilib -I. t/40connect.t
7580c9a
    1..3
7580c9a
    ok 1 - client with IPv4/IPv6 auto-selection, bound to ::1
7580c9a
    ldap://localhost:9009/ Name or service not known at t/common.pl line 157.
7580c9a
    # Looks like your test exited with 22 just after 1.
7580c9a
7580c9a
The reason is that IO::Socket::IP by default resolves host names with
7580c9a
AI_ADDRCONFIG flag and in the particular case (no interfaces other
7580c9a
than loopback) a system resolver (glibc in my case) hides both IPv4
7580c9a
and IPv6 addreses of the hostname (e.g. localhost).
7580c9a
7580c9a
See <https://rt.cpan.org/Ticket/Display.html?id=104793> for more
7580c9a
details.
7580c9a
7580c9a
I applied a workaround similar to one found in IO-Socket-SSL.
7580c9a
I believe that other Socket implementations perl-ldap can use do not
7580c9a
suffer from this problem.
7580c9a
7580c9a
Signed-off-by: Petr Písař <ppisar@redhat.com>
7580c9a
---
7580c9a
 lib/Net/LDAP.pm | 3 +++
7580c9a
 1 file changed, 3 insertions(+)
7580c9a
7580c9a
diff --git a/lib/Net/LDAP.pm b/lib/Net/LDAP.pm
7580c9a
index 5dfe3e3..be11d12 100644
7580c9a
--- a/lib/Net/LDAP.pm
7580c9a
+++ b/lib/Net/LDAP.pm
7580c9a
@@ -167,6 +167,9 @@ sub connect_ldap {
7580c9a
     LocalAddr  => $arg->{localaddr} || undef,
7580c9a
     Proto      => 'tcp',
7580c9a
     ($class eq 'IO::Socket::IP' ? 'Family' : 'Domain')     => $domain,
7580c9a
+    # Work around IO::Socket::IP defaulting to AI_ADDRCONFIG which breaks
7580c9a
+    # resolution if only a loopback interface is available. CPAN RT#104793.
7580c9a
+    ($class eq 'IO::Socket::IP' and $domain ne AF_UNSPEC ? ('GetAddrInfoFlags' => 0) : ()),
7580c9a
     MultiHomed => $arg->{multihomed},
7580c9a
     Timeout    => defined $arg->{timeout}
7580c9a
 		 ? $arg->{timeout}
7580c9a
-- 
7580c9a
2.26.2
7580c9a