]>
Commit | Line | Data |
---|---|---|
6f2c94a3 FG |
1 | From: =?utf-8?q?Petr_P=C3=ADsa=C5=99?= <ppisar@redhat.com> |
2 | Date: Wed, 23 May 2018 17:31:42 +0200 | |
3 | Subject: Resolve specific socket addresses correctly | |
4 | MIME-Version: 1.0 | |
5 | Content-Type: text/plain; charset="utf-8" | |
6 | Content-Transfer-Encoding: 8bit | |
7 | ||
8 | Previous code did not formatted specific (not 0.0.0.0 or ::) | |
9 | correctly: | |
10 | ||
11 | $ perl -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalAddr=>q{127.0.0.2}) or die; print $d->url, qq{\n}' | |
12 | Can't call method "sockhostname" without a package or object reference at /usr/share/perl5/vendor_perl/HTTP/Daemon.pm line 64. | |
13 | ||
14 | This patch also fixes formatting numerical IPv6 addresses. It seems | |
15 | that IO::Socket::IP::sockhostname() formats unresolvable addresses too. | |
16 | ||
17 | Signed-off-by: Petr Písař <ppisar@redhat.com> | |
18 | ||
19 | Bug: 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 | ||
24 | diff --git a/lib/HTTP/Daemon.pm b/lib/HTTP/Daemon.pm | |
25 | index 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; |