From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7D2AA211B4 for ; Thu, 10 Jan 2019 06:59:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] daemon: make Socket6 optional, note about Net::Socket::IP Date: Thu, 10 Jan 2019 06:59:55 +0000 Message-Id: <20190110065957.28265-2-e@80x24.org> In-Reply-To: <20190110065957.28265-1-e@80x24.org> References: <20190110065957.28265-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/Daemon.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 6d2ae81..6aa4a19 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); -- EW