]> git.proxmox.com Git - libhttp-daemon-perl.git/blame - debian/patches/0003-Resolve-specific-socket-addresses-correctly.patch
switch to IO::Socket::IP to add IPv6 support
[libhttp-daemon-perl.git] / debian / patches / 0003-Resolve-specific-socket-addresses-correctly.patch
CommitLineData
6f2c94a3
FG
1From: =?utf-8?q?Petr_P=C3=ADsa=C5=99?= <ppisar@redhat.com>
2Date: Wed, 23 May 2018 17:31:42 +0200
3Subject: Resolve specific socket addresses correctly
4MIME-Version: 1.0
5Content-Type: text/plain; charset="utf-8"
6Content-Transfer-Encoding: 8bit
7
8Previous code did not formatted specific (not 0.0.0.0 or ::)
9correctly:
10
11$ perl -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalAddr=>q{127.0.0.2}) or die; print $d->url, qq{\n}'
12Can't call method "sockhostname" without a package or object reference at /usr/share/perl5/vendor_perl/HTTP/Daemon.pm line 64.
13
14This patch also fixes formatting numerical IPv6 addresses. It seems
15that IO::Socket::IP::sockhostname() formats unresolvable addresses too.
16
17Signed-off-by: Petr Písař <ppisar@redhat.com>
18
19Bug: https://rt.cpan.org/Public/Bug/Display.html?id=125242
20---
21 lib/HTTP/Daemon.pm | 15 +++++++++++++--
22 1 file changed, 13 insertions(+), 2 deletions(-)
23
24diff --git a/lib/HTTP/Daemon.pm b/lib/HTTP/Daemon.pm
25index 1e9d48e..216c73f 100644
26--- a/lib/HTTP/Daemon.pm
27+++ b/lib/HTTP/Daemon.pm
28@@ -61,12 +61,23 @@ sub url
29 $url .= '[' . inet_ntop(AF_INET6, $addr) . ']';
30 }
31 else {
32- my $host = $addr->sockhostname;
33+ my $host = $self->sockhostname;
34+ # sockhostname() seems to return a stringified IP address if not
35+ # resolvable, then quote it for a port separator and an IPv6 zone separator.
36+ # But be paranoid for a case when it already contains a bracket.
37+ if (defined $host and $host =~ /:/) {
38+ if ($host =~ /[\[\]]/) {
39+ $host = undef;
40+ } else {
41+ $host =~ s/%/%25/g;
42+ $host = '[' . $host . ']';
43+ }
44+ }
45 if (!defined $host) {
46 if (sockaddr_family($addr) eq AF_INET6) {
47 $host = '[' . inet_ntop(AF_INET6, $addr) . ']';
48 } else {
49- $host = inet_ntop(AF_INET6, $addr);
50+ $host = inet_ntop(AF_INET, $addr);
51 }
52 }
53 $url .= $host;