Skip to content

Commit 81bd91d

Browse files
ppisargenio
authored andcommitted
Format unresolvable specific socket addresses correctly
It seems that IO::Socket::IP::sockhostname() formats unresolvable addresses. However, IPv6 numerical addresses must be properly delimited by brackets: $ perl -Ilib -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalAddr=>q{::2}) or die; print $d->url, qq{\n}' http://::2:52153/ And a zone seperator must be URI-quoted: $ perl -Ilib -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalAddr=>q{fe80::250:54ff:fe00:f15%ens3}) or die; print $d->url, qq{\n}' http://fe80::250:54ff:fe00:f15%ens3:57797/ This patch fixes these two formatting issues. Signed-off-by: Petr Písař <ppisar@redhat.com>
1 parent e9142a9 commit 81bd91d

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Revision history for HTTP-Daemon
22

33
{{$NEXT}}
4+
- Delimit IPv6 numeric address with brackets and URI-quote an IPv6 zone
5+
separator in url() method output
46
- Handle undef and empty LocalAddr value in new() constructor as an
57
unspecified address (GH#24, RT#123069)
68

lib/HTTP/Daemon.pm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ sub url {
6262
}
6363
else {
6464
my $host = $self->sockhostname;
65+
66+
# sockhostname() seems to return a stringified IP address if not
67+
# resolvable. Then quote it for a port separator and an IPv6 zone
68+
# separator. But be paranoid for a case when it already contains
69+
# a bracket.
70+
if (defined $host and $host =~ /:/) {
71+
if ($host =~ /[\[\]]/) {
72+
$host = undef;
73+
}
74+
else {
75+
$host =~ s/%/%25/g;
76+
$host = '[' . $host . ']';
77+
}
78+
}
6579
if (!defined $host) {
6680
my $family = sockaddr_family($self->sockname);
6781
if ($family && $family == AF_INET6) {

0 commit comments

Comments
 (0)