mirror of https://github.com/sipwise/ngcpcfg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
763 B
32 lines
763 B
[%
|
|
# vi: ft=tt2
|
|
|
|
# Return an array of IPs from a given hostname.
|
|
#
|
|
# @param argv.name The hostname to lookup.
|
|
# @param argv.type The address family to lookup, one of:
|
|
# "AF_INET" for IPv4
|
|
# "AF_INET6" for IPv6
|
|
# "" for both
|
|
# @return out The array of IPs.
|
|
-%]
|
|
[% PERL -%]
|
|
use Socket qw(:all);
|
|
|
|
my $err;
|
|
my $ipaddr;
|
|
my @res;
|
|
my @ips;
|
|
|
|
($err, @res) = getaddrinfo("[% argv.name %]", "", {
|
|
socktype => SOCK_RAW, family => [% argv.type %]
|
|
});
|
|
while (my $ai = shift @res) {
|
|
($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_NOSERV);
|
|
push @ips, $ipaddr;
|
|
}
|
|
@ips = sort @ips;
|
|
|
|
$stash->set(out => \@ips);
|
|
[% END -%]
|