From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20190110065957.28265-2-e@80x24.org> (raw)
In-Reply-To: <20190110065957.28265-1-e@80x24.org>
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
next prev parent reply other threads:[~2019-01-10 6:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-10 6:59 [PATCH 0/3] some dependency cleanups Eric Wong
2019-01-10 6:59 ` Eric Wong [this message]
2019-01-10 6:59 ` [PATCH 2/3] INSTALL: Net::Server is not needed for systemd use Eric Wong
2019-01-10 6:59 ` [PATCH 3/3] check git version requirements Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190110065957.28265-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).