Blame SOURCES/HTTP-Daemon-6.01-Resolve-specific-socket-addresses-correctly.patch

776a43
From e49f553aa8be21e5df72452e50af2e9f0b82ecad Mon Sep 17 00:00:00 2001
776a43
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
776a43
Date: Wed, 23 May 2018 17:31:42 +0200
776a43
Subject: [PATCH] Resolve specific socket addresses correctly
776a43
MIME-Version: 1.0
776a43
Content-Type: text/plain; charset=UTF-8
776a43
Content-Transfer-Encoding: 8bit
776a43
776a43
Previous code did not formatted specific (not 0.0.0.0 or ::)
776a43
correctly:
776a43
776a43
$ perl -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalAddr=>q{127.0.0.2}) or die; print $d->url, qq{\n}'
776a43
Can't call method "sockhostname" without a package or object reference at /usr/share/perl5/vendor_perl/HTTP/Daemon.pm line 64.
776a43
776a43
This patch also fixes formatting numerical IPv6 addresses. It seems
776a43
that IO::Socket::IP::sockhostname() formats unresolvable addresses too.
776a43
776a43
Signed-off-by: Petr Písař <ppisar@redhat.com>
776a43
---
776a43
 lib/HTTP/Daemon.pm | 15 +++++++++++++--
776a43
 1 file changed, 13 insertions(+), 2 deletions(-)
776a43
776a43
diff --git a/lib/HTTP/Daemon.pm b/lib/HTTP/Daemon.pm
776a43
index 1e9d48e..216c73f 100644
776a43
--- a/lib/HTTP/Daemon.pm
776a43
+++ b/lib/HTTP/Daemon.pm
776a43
@@ -61,12 +61,23 @@ sub url
776a43
 	$url .= '[' . inet_ntop(AF_INET6, $addr) . ']';
776a43
     }
776a43
     else {
776a43
-	my $host = $addr->sockhostname;
776a43
+	my $host = $self->sockhostname;
776a43
+	# sockhostname() seems to return a stringified IP address if not
776a43
+	# resolvable, then quote it for a port separator and an IPv6 zone separator.
776a43
+	# But be paranoid for a case when it already contains a bracket.
776a43
+	if (defined $host and $host =~ /:/) {
776a43
+	    if ($host =~ /[\[\]]/) {
776a43
+		$host = undef;
776a43
+	    } else {
776a43
+		$host =~ s/%/%25/g;
776a43
+		$host  = '[' . $host . ']';
776a43
+	    }
776a43
+	}
776a43
         if (!defined $host) {
776a43
 	    if (sockaddr_family($addr) eq AF_INET6) {
776a43
 		$host = '[' . inet_ntop(AF_INET6, $addr) . ']';
776a43
 	    } else {
776a43
-		$host = inet_ntop(AF_INET6, $addr);
776a43
+		$host = inet_ntop(AF_INET, $addr);
776a43
 	    }
776a43
 	}
776a43
 	$url .= $host;
776a43
-- 
776a43
2.14.3
776a43