about summary refs log tree commit homepage
path: root/lib/PublicInbox/Daemon.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/Daemon.pm')
-rw-r--r--lib/PublicInbox/Daemon.pm25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 77ab2a71..c101ecb7 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -157,20 +157,23 @@ sub reopen_logs {
 
 sub sockname ($) {
         my ($s) = @_;
-        my $n = getsockname($s) or return;
-        my ($port, $addr);
-        if (length($n) >= 28) {
+        my $addr = getsockname($s) or return;
+        my ($host, $port) = host_with_port($addr);
+        "$host:$port";
+}
+
+sub host_with_port ($) {
+        my ($addr) = @_;
+        my ($port, $host);
+        if (length($addr) >= 28) {
                 require Socket6;
-                ($port, $addr) = Socket6::unpack_sockaddr_in6($n);
-        } else {
-                ($port, $addr) = Socket::sockaddr_in($n);
-        }
-        if (length($addr) == 4) {
-                $n = Socket::inet_ntoa($addr)
+                ($port, $host) = Socket6::unpack_sockaddr_in6($addr);
+                $host = '['.Socket6::inet_ntop(Socket6::AF_INET6(), $host).']';
         } else {
-                $n = '['.Socket6::inet_ntop(Socket6::AF_INET6(), $addr).']';
+                ($port, $host) = Socket::sockaddr_in($addr);
+                $host = Socket::inet_ntoa($host);
         }
-        $n .= ":$port";
+        ($host, $port);
 }
 
 sub inherit () {