#!/usr/bin/perl 
require 5.002;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket qw(SOCK_STREAM getaddrinfo getnameinfo NI_NUMERICHOST NIx_NOSERV AF_INET6 inet_pton);

use Carp;
use IO::Select;

sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

my $host = shift || inet_pton(AF_INET6, "::"); 
my $port = shift || 2345;
my $proto = getprotobyname('tcp');

use IO::Socket;
use Socket qw(SOCK_STREAM getaddrinfo);

my %hints = (socktype => SOCK_STREAM);
my ($err, @res) = getaddrinfo( $host  , $port , \%hints);
die "Cannot getaddrinfo - $err" if $err;

my $sock;

foreach my $ai (@res) {
      my ($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_NOSERV);
      print "$ipaddr\n";
}

