diff options
author | Eric Wong <e@80x24.org> | 2019-01-10 04:02:59 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-01-10 04:08:35 +0000 |
commit | f9eba5de3cc2f43d3ef5b9ec1379934b4158e5e6 (patch) | |
tree | 8bd3c2b46340d67b92e7cf7b69022188545c3e8b /lib | |
parent | a9cab9c477b74b3b828c26aa64e70d88c9d6744c (diff) | |
download | public-inbox-f9eba5de3cc2f43d3ef5b9ec1379934b4158e5e6.tar.gz |
It looks like Net::Socket::IP comes with Perl 5.20 and later; so we won't have to hassle users with another package to install.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/Daemon.pm | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 6d2ae81b..6aa4a194 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -234,6 +234,21 @@ sub sockname ($) { "$host:$port"; } +sub unpack_ipv6 ($) { + my ($addr) = @_; + + # TODO: support IO::Socket::IP which comes with Perl 5.24 + # (perl-modules-5.24 in Debian) + + # SpamAssassin and Net::Server use Socket6, so it may be installed + # on our system, already: + eval { require Socket6 } or return ('???-Socket6-missing', 0); + + my ($port, $host) = Socket6::unpack_sockaddr_in6($addr); + $host = Socket6::inet_ntop(Socket6::AF_INET6(), $host); + ($host, $port); +} + sub host_with_port ($) { my ($addr) = @_; my ($port, $host); @@ -241,9 +256,7 @@ sub host_with_port ($) { # this eval will die on Unix sockets: eval { if (length($addr) >= 28) { - require Socket6; - ($port, $host) = Socket6::unpack_sockaddr_in6($addr); - $host = Socket6::inet_ntop(Socket6::AF_INET6(), $host); + ($host, $port) = unpack_ipv6($addr); $host = "[$host]"; } else { ($port, $host) = Socket::sockaddr_in($addr); |